program main
implicit none
integer :: i, g
integer :: n, m
integer , allocatable :: x(:)

read(*,*) n, m
allocate( x(n) )
read(*,*) x(1:n)
x = abs(x -m)
if( n == 1 ) then
   write(*,'(i0)') x(1)
else
   do i = 1, n-1
      call gcdlcm(x(i), x(i+1), g)
      x(i+1) = g
   end do
   write(*,'(i0)') g
end if

stop
contains
  subroutine gcdlcm( a, b, g )
    integer , intent(in)  :: a, b
    integer , intent(out) :: g

    integer :: i, j, k,l

    i = a
    j = b
    do while( j /= 0 )
       k = mod(i,j)
       i = j
       j = k
    end do
    g = i
    l = a*b/g
  end subroutine gcdlcm

end program main


; 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"

@_QFEx.0 = internal unnamed_addr global ptr null
@_QFEx.8 = internal unnamed_addr global i64 0
@_QQcl.e2ee8ed23486170f62ebc89dfd0d98b1 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5553/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #2 {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e2ee8ed23486170f62ebc89dfd0d98b1, i32 7)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %3, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEx.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEx.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e2ee8ed23486170f62ebc89dfd0d98b1, i32 9)
  %.unpack = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %14 = load i32, ptr %3, align 4, !tbaa !3
  %15 = call i32 @llvm.smax.i32(i32 %14, i32 0)
  %16 = zext i32 %15 to i64
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %16, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %17 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %1)
  %18 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %.unpack235 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack235306 = ptrtoint ptr %.unpack235 to i64
  %.unpack242.unpack.unpack244 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  %19 = load i32, ptr %2, align 4, !tbaa !3
  %.not = icmp eq ptr %.unpack235, null
  %20 = shl i64 %.unpack242.unpack.unpack244, 2
  %21 = call ptr @malloc(i64 %20)
  %22 = ptrtoint ptr %21 to i64
  %23 = icmp slt i64 %.unpack242.unpack.unpack244, 1
  br i1 %.not, label %._crit_edge, label %24

24:                                               ; preds = %0
  br i1 %23, label %.thread, label %.lr.ph294.preheader

.lr.ph294.preheader:                              ; preds = %24
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %21, ptr nonnull align 4 %.unpack235, i64 %20, i1 false), !tbaa !3
  %min.iters.check = icmp ult i64 %.unpack242.unpack.unpack244, 8
  %25 = sub i64 %22, %.unpack235306
  %diff.check = icmp ult i64 %25, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %.lr.ph294.preheader310, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph294.preheader
  %n.vec = and i64 %.unpack242.unpack.unpack244, -8
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %19, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert308 = insertelement <4 x i32> poison, i32 %19, i64 0
  %broadcast.splat309 = shufflevector <4 x i32> %broadcast.splatinsert308, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = getelementptr i32, ptr %.unpack235, i64 %index
  %wide.load = load <4 x i32>, ptr %26, align 4, !tbaa !3
  %27 = getelementptr i32, ptr %26, i64 4
  %wide.load307 = load <4 x i32>, ptr %27, align 4, !tbaa !3
  %28 = sub <4 x i32> %wide.load, %broadcast.splat
  %29 = sub <4 x i32> %wide.load307, %broadcast.splat309
  %30 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %28, i1 false)
  %31 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %29, i1 false)
  %32 = getelementptr i32, ptr %21, i64 %index
  store <4 x i32> %30, ptr %32, align 4, !tbaa !3
  %33 = getelementptr i32, ptr %32, i64 4
  store <4 x i32> %31, ptr %33, align 4, !tbaa !3
  %index.next = add nuw i64 %index, 8
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %.unpack242.unpack.unpack244, %n.vec
  br i1 %cmp.n, label %.preheader, label %.lr.ph294.preheader310

.lr.ph294.preheader310:                           ; preds = %.lr.ph294.preheader, %middle.block
  %.ph = phi i64 [ 0, %.lr.ph294.preheader ], [ %n.vec, %middle.block ]
  %.neg = or i64 %.ph, 1
  %xtraiter = and i64 %.unpack242.unpack.unpack244, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph294.prol.loopexit, label %.lr.ph294.prol

.lr.ph294.prol:                                   ; preds = %.lr.ph294.preheader310
  %35 = getelementptr i32, ptr %.unpack235, i64 %.ph
  %36 = load i32, ptr %35, align 4, !tbaa !3
  %37 = sub i32 %36, %19
  %38 = call i32 @llvm.abs.i32(i32 %37, i1 false)
  %39 = or i64 %.ph, 1
  %40 = getelementptr i32, ptr %21, i64 %.ph
  store i32 %38, ptr %40, align 4, !tbaa !3
  br label %.lr.ph294.prol.loopexit

.lr.ph294.prol.loopexit:                          ; preds = %.lr.ph294.prol, %.lr.ph294.preheader310
  %.unr = phi i64 [ %.ph, %.lr.ph294.preheader310 ], [ %39, %.lr.ph294.prol ]
  %41 = icmp eq i64 %.unpack242.unpack.unpack244, %.neg
  br i1 %41, label %.preheader, label %.lr.ph294

.preheader:                                       ; preds = %.lr.ph294.prol.loopexit, %.lr.ph294, %middle.block
  br i1 %23, label %.thread, label %.lr.ph295.preheader

.lr.ph295.preheader:                              ; preds = %.preheader
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %.unpack235, ptr nonnull align 4 %21, i64 %20, i1 false), !tbaa !3
  br label %.thread

.lr.ph294:                                        ; preds = %.lr.ph294.prol.loopexit, %.lr.ph294
  %42 = phi i64 [ %53, %.lr.ph294 ], [ %.unr, %.lr.ph294.prol.loopexit ]
  %43 = getelementptr i32, ptr %.unpack235, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !3
  %45 = sub i32 %44, %19
  %46 = call i32 @llvm.abs.i32(i32 %45, i1 false)
  %47 = add nuw nsw i64 %42, 1
  %48 = getelementptr i32, ptr %21, i64 %42
  store i32 %46, ptr %48, align 4, !tbaa !3
  %49 = getelementptr i32, ptr %.unpack235, i64 %47
  %50 = load i32, ptr %49, align 4, !tbaa !3
  %51 = sub i32 %50, %19
  %52 = call i32 @llvm.abs.i32(i32 %51, i1 false)
  %53 = add nuw nsw i64 %42, 2
  %54 = getelementptr i32, ptr %21, i64 %47
  store i32 %52, ptr %54, align 4, !tbaa !3
  %exitcond.not.1 = icmp eq i64 %53, %.unpack242.unpack.unpack244
  br i1 %exitcond.not.1, label %.preheader, label %.lr.ph294, !llvm.loop !12

.thread:                                          ; preds = %24, %.lr.ph295.preheader, %.preheader
  call void @free(ptr %21)
  br label %55

._crit_edge:                                      ; preds = %0
  call void @llvm.assume(i1 %23)
  store ptr %21, ptr @_QFEx.0, align 8, !tbaa !7
  br label %55

55:                                               ; preds = %.thread, %._crit_edge
  %.unpack247 = phi ptr [ %.unpack235, %.thread ], [ %21, %._crit_edge ]
  %56 = load i32, ptr %3, align 4, !tbaa !3
  %57 = icmp eq i32 %56, 1
  br i1 %57, label %58, label %61

58:                                               ; preds = %55
  %59 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.e2ee8ed23486170f62ebc89dfd0d98b1, i32 12)
  %.unpack271 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %60 = load i32, ptr %.unpack271, align 4, !tbaa !3
  br label %75

61:                                               ; preds = %55
  %62 = add i32 %56, -1
  %63 = icmp sgt i32 %62, 0
  br i1 %63, label %.lr.ph298, label %._crit_edge299

.lr.ph298:                                        ; preds = %61
  %64 = zext i32 %62 to i64
  br label %65

65:                                               ; preds = %.lr.ph298, %_QFPgcdlcm.exit
  %indvars.iv = phi i64 [ 1, %.lr.ph298 ], [ %indvars.iv.next, %_QFPgcdlcm.exit ]
  %66 = add nsw i64 %indvars.iv, -1
  %67 = getelementptr i32, ptr %.unpack247, i64 %66
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext = shl i64 %indvars.iv.next, 32
  %68 = ashr exact i64 %sext, 32
  %69 = add nsw i64 %68, -1
  %70 = getelementptr i32, ptr %.unpack247, i64 %69
  %71 = load i32, ptr %67, align 4, !tbaa !3
  %72 = load i32, ptr %70, align 4, !tbaa !3
  %.not7.i = icmp eq i32 %72, 0
  br i1 %.not7.i, label %_QFPgcdlcm.exit, label %.lr.ph.i

.lr.ph.i:                                         ; preds = %65, %.lr.ph.i
  %.09.i = phi i32 [ %.068.i, %.lr.ph.i ], [ %71, %65 ]
  %.068.i = phi i32 [ %73, %.lr.ph.i ], [ %72, %65 ]
  %73 = srem i32 %.09.i, %.068.i
  %.not.i = icmp eq i32 %73, 0
  br i1 %.not.i, label %_QFPgcdlcm.exit, label %.lr.ph.i

_QFPgcdlcm.exit:                                  ; preds = %.lr.ph.i, %65
  %.0.lcssa.i = phi i32 [ %71, %65 ], [ %.068.i, %.lr.ph.i ]
  store i32 %.0.lcssa.i, ptr %70, align 4, !tbaa !3
  %exitcond302.not = icmp eq i64 %indvars.iv, %64
  br i1 %exitcond302.not, label %._crit_edge299, label %65

._crit_edge299:                                   ; preds = %_QFPgcdlcm.exit, %61
  %.0.lcssa = phi i32 [ undef, %61 ], [ %.0.lcssa.i, %_QFPgcdlcm.exit ]
  %74 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.e2ee8ed23486170f62ebc89dfd0d98b1, i32 18)
  br label %75

75:                                               ; preds = %58, %._crit_edge299
  %.sink305 = phi i32 [ %60, %58 ], [ %.0.lcssa, %._crit_edge299 ]
  %.sink304 = phi ptr [ %59, %58 ], [ %74, %._crit_edge299 ]
  %76 = call i1 @_FortranAioOutputInteger32(ptr %.sink304, i32 %.sink305)
  %77 = call i32 @_FortranAioEndIoStatement(ptr %.sink304)
  %78 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite)
define void @_QFPgcdlcm(ptr nocapture readonly %0, ptr nocapture readonly %1, ptr nocapture writeonly %2) local_unnamed_addr #3 {
  %4 = load i32, ptr %0, align 4, !tbaa !3
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %.not7 = icmp eq i32 %5, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.09 = phi i32 [ %.068, %.lr.ph ], [ %4, %3 ]
  %.068 = phi i32 [ %6, %.lr.ph ], [ %5, %3 ]
  %6 = srem i32 %.09, %.068
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.0.lcssa = phi i32 [ %4, %3 ], [ %.068, %.lr.ph ]
  store i32 %.0.lcssa, ptr %2, align 4, !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 i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
declare void @llvm.assume(i1 noundef) #6

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.abs.v4i32(<4 x i32>, i1 immarg) #4

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

!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}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !10}
