program test
integer(8)::n, x, ans, i, t, k, p, a
allocatable::a(:)
read(*,*)n, x
allocate(a(n))
read(*,*)(a(i), i=1,n)
 
if(n==1)then
t=a(1)-x
ans=abs(t)
 
else
t=x-a(1)
ans=abs(t)
 
do i=1,n
t=x-a(i)
k=abs(t)
call subr4(ans,k,p)
ans=p
end do
end if
write(*,*)ans
 
end program test
 
subroutine subr4(a,b,q)
  implicit none
  integer(8) :: a, b, q
  integer(8) :: m, n, k
  ! step 1
  m = a
  n = b
  do
     ! step 2
     k = mod(m, n)
     ! step 3
     if (k == 0) then
        q=n
        exit
     end if
     ! step 4
     m = n
     n = k
  end do
 end subroutine subr4
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QQcl.0fde13f654eb4c9fb8dc09379913b6bc = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5552/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0fde13f654eb4c9fb8dc09379913b6bc, i32 4)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i64, ptr %1, align 8, !tbaa !3
  %8 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 3
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0fde13f654eb4c9fb8dc09379913b6bc, i32 6)
  %12 = load i64, ptr %1, align 8, !tbaa !3
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %14 = phi i64 [ %18, %.lr.ph ], [ 1, %0 ]
  %.unpack138 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %15 = add i64 %14, -1
  %16 = getelementptr i64, ptr %.unpack138, i64 %15
  %17 = call i1 @_FortranAioInputInteger(ptr %11, ptr %16, i32 8)
  %18 = add nuw i64 %14, 1
  %exitcond.not = icmp eq i64 %14, %12
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %19 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %20 = load i64, ptr %1, align 8, !tbaa !3
  %21 = icmp eq i64 %20, 1
  br i1 %21, label %22, label %27

22:                                               ; preds = %._crit_edge
  %.unpack126 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %23 = load i64, ptr %.unpack126, align 8, !tbaa !3
  %24 = load i64, ptr %2, align 8, !tbaa !3
  %25 = sub i64 %23, %24
  %26 = call i64 @llvm.abs.i64(i64 %25, i1 false)
  br label %.loopexit

27:                                               ; preds = %._crit_edge
  %28 = load i64, ptr %2, align 8, !tbaa !3
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %29 = load i64, ptr %.unpack, align 8, !tbaa !3
  %30 = sub i64 %28, %29
  %31 = call i64 @llvm.abs.i64(i64 %30, i1 false)
  %32 = icmp sgt i64 %20, 0
  br i1 %32, label %.lr.ph155, label %.loopexit

.lr.ph155:                                        ; preds = %27, %subr4_.exit
  %33 = phi i64 [ %42, %subr4_.exit ], [ 1, %27 ]
  %.0153 = phi i64 [ %.0.i, %subr4_.exit ], [ %31, %27 ]
  %34 = add i64 %33, -1
  %35 = getelementptr i64, ptr %.unpack, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !3
  %37 = sub i64 %28, %36
  %38 = call i64 @llvm.abs.i64(i64 %37, i1 false)
  br label %39

39:                                               ; preds = %39, %.lr.ph155
  %.06.i = phi i64 [ %.0153, %.lr.ph155 ], [ %.0.i, %39 ]
  %.0.i = phi i64 [ %38, %.lr.ph155 ], [ %40, %39 ]
  %40 = srem i64 %.06.i, %.0.i
  %41 = icmp eq i64 %40, 0
  br i1 %41, label %subr4_.exit, label %39

subr4_.exit:                                      ; preds = %39
  %42 = add nuw i64 %33, 1
  %exitcond156.not = icmp eq i64 %33, %20
  br i1 %exitcond156.not, label %.loopexit, label %.lr.ph155

.loopexit:                                        ; preds = %subr4_.exit, %27, %22
  %.1 = phi i64 [ %26, %22 ], [ %31, %27 ], [ %.0.i, %subr4_.exit ]
  %43 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.0fde13f654eb4c9fb8dc09379913b6bc, i32 23)
  %44 = call i1 @_FortranAioOutputInteger64(ptr %43, i64 %.1)
  %45 = call i32 @_FortranAioEndIoStatement(ptr %43)
  ret void
}

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite)
define void @subr4_(ptr nocapture readonly %0, ptr nocapture readonly %1, ptr nocapture writeonly %2) local_unnamed_addr #1 {
  %4 = load i64, ptr %0, align 8, !tbaa !3
  %5 = load i64, ptr %1, align 8, !tbaa !3
  br label %6

6:                                                ; preds = %6, %3
  %.06 = phi i64 [ %4, %3 ], [ %.0, %6 ]
  %.0 = phi i64 [ %5, %3 ], [ %7, %6 ]
  %7 = srem i64 %.06, %.0
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %6

9:                                                ; preds = %6
  store i64 %.0, ptr %2, align 8, !tbaa !3
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
