program name
    implicit none
    integer(4):: n,i,maxgcd
    integer(4),allocatable:: a(:),l(:),r(:)

    read*, n
    allocate(a(n),l(0:n),r(n+1))
    read*, a(:)

    l(0) = 0
    l(1) = a(1)
    r(n) = a(n)
    r(n+1) = 0
    do i=2,n
        l(i) = gcd(l(i-1),a(i))
    end do

    do i=n-1,1,-1
        r(i) = gcd(r(i+1),a(i))
    end do

    maxgcd = r(2)



    do i=2,n-1
        maxgcd = max(maxgcd, gcd(l(i-1),r(i+1)))
    end do

    maxgcd = max(maxgcd,l(n-1))
    print*, maxgcd



contains
    recursive function gcd(x,y) result(ret)
        integer(4),intent(in):: x,y
        integer(4):: ret

        if (mod(x,y) == 0) then
            ret = y
            return
        end if

        ret = gcd(y,mod(x,y))
    end function
end program name
; 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
@_QFEa.8 = internal unnamed_addr global i64 0
@_QFEl.0 = internal unnamed_addr global ptr null
@_QFEl.7 = internal unnamed_addr global i64 1
@_QFEr.0 = internal unnamed_addr global ptr null
@_QQcl.30f39f96a409083f2d4021e4392a8fa5 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4387/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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.30f39f96a409083f2d4021e4392a8fa5, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = call i32 @llvm.smax.i32(i32 %6, i32 -1)
  %12 = sext i32 %11 to i64
  %13 = add nsw i64 %12, 1
  %14 = shl nuw nsw i64 %13, 2
  %15 = call ptr @malloc(i64 %14)
  %16 = icmp eq i64 %13, 0
  %17 = zext i1 %16 to i64
  store ptr %15, ptr @_QFEl.0, align 8, !tbaa !7
  store i64 %17, ptr @_QFEl.7, align 8, !tbaa !7
  %18 = add i32 %6, 1
  %19 = call i32 @llvm.smax.i32(i32 %18, i32 0)
  %20 = zext i32 %19 to i64
  %21 = shl nuw nsw i64 %20, 2
  %22 = call ptr @malloc(i64 %21)
  store ptr %22, ptr @_QFEr.0, align 8, !tbaa !7
  %23 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.30f39f96a409083f2d4021e4392a8fa5, i32 8)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack644.unpack.unpack646 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %24 = call i64 @llvm.smax.i64(i64 %.unpack644.unpack.unpack646, i64 0)
  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 %24, 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
  %25 = call i1 @_FortranAioInputDescriptor(ptr %23, ptr nonnull %1)
  %26 = call i32 @_FortranAioEndIoStatement(ptr %23)
  %.unpack649 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %.unpack656.unpack.unpack = load i64, ptr @_QFEl.7, align 8, !tbaa !7
  %27 = sub i64 0, %.unpack656.unpack.unpack
  %28 = getelementptr i32, ptr %.unpack649, i64 %27
  store i32 0, ptr %28, align 4, !tbaa !3
  %.unpack661 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %29 = load i32, ptr %.unpack661, align 4, !tbaa !3
  %30 = sub i64 1, %.unpack656.unpack.unpack
  %31 = getelementptr i32, ptr %.unpack649, i64 %30
  store i32 %29, ptr %31, align 4, !tbaa !3
  %32 = load i32, ptr %2, align 4, !tbaa !3
  %33 = sext i32 %32 to i64
  %34 = add nsw i64 %33, -1
  %35 = getelementptr i32, ptr %.unpack661, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !3
  %.unpack697 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %37 = add nsw i64 %33, -1
  %38 = getelementptr i32, ptr %.unpack697, i64 %37
  store i32 %36, ptr %38, align 4, !tbaa !3
  %39 = load i32, ptr %2, align 4, !tbaa !3
  %40 = add i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %41, -1
  %43 = getelementptr i32, ptr %.unpack697, i64 %42
  store i32 0, ptr %43, align 4, !tbaa !3
  %44 = load i32, ptr %2, align 4, !tbaa !3
  %45 = icmp sgt i32 %44, 1
  br i1 %45, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %46 = zext i32 %44 to i64
  %47 = xor i64 %.unpack656.unpack.unpack, -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %48 = add i64 %indvars.iv, %47
  %49 = getelementptr i32, ptr %.unpack649, i64 %48
  %50 = add nsw i64 %indvars.iv, -1
  %51 = getelementptr i32, ptr %.unpack661, i64 %50
  %52 = call i32 @_QFPgcd(ptr %49, ptr %51)
  %53 = sub i64 %indvars.iv, %.unpack656.unpack.unpack
  %54 = getelementptr i32, ptr %.unpack649, i64 %53
  store i32 %52, ptr %54, align 4, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %46
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %2, align 4, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %55 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %44, %0 ]
  %56 = add i32 %55, -1
  %57 = sext i32 %56 to i64
  %58 = icmp sgt i32 %56, 0
  br i1 %58, label %.lr.ph843, label %._crit_edge844.thread

._crit_edge844.thread:                            ; preds = %._crit_edge
  %59 = getelementptr i32, ptr %.unpack697, i64 1
  %60 = load i32, ptr %59, align 4, !tbaa !3
  br label %._crit_edge848

.lr.ph843:                                        ; preds = %._crit_edge, %.lr.ph843
  %61 = phi i64 [ %72, %.lr.ph843 ], [ %57, %._crit_edge ]
  %62 = shl i64 %61, 32
  %sext859 = add i64 %62, 4294967296
  %63 = ashr exact i64 %sext859, 32
  %64 = add nsw i64 %63, -1
  %65 = getelementptr i32, ptr %.unpack697, i64 %64
  %sext860 = shl i64 %61, 32
  %66 = ashr exact i64 %sext860, 32
  %67 = add nsw i64 %66, -1
  %68 = getelementptr i32, ptr %.unpack661, i64 %67
  %69 = call i32 @_QFPgcd(ptr %65, ptr %68)
  %70 = add nsw i64 %66, -1
  %71 = getelementptr i32, ptr %.unpack697, i64 %70
  store i32 %69, ptr %71, align 4, !tbaa !3
  %72 = add nsw i64 %61, -1
  %73 = icmp sgt i64 %61, 1
  br i1 %73, label %.lr.ph843, label %._crit_edge844

._crit_edge844:                                   ; preds = %.lr.ph843
  %.pre855 = load i32, ptr %2, align 4, !tbaa !3
  %.pre856 = add i32 %.pre855, -1
  %.pre857 = sext i32 %.pre856 to i64
  %74 = getelementptr i32, ptr %.unpack697, i64 1
  %75 = load i32, ptr %74, align 4, !tbaa !3
  %76 = icmp sgt i32 %.pre856, 1
  br i1 %76, label %.lr.ph847.preheader, label %._crit_edge848

.lr.ph847.preheader:                              ; preds = %._crit_edge844
  %77 = xor i64 %.unpack656.unpack.unpack, -1
  br label %.lr.ph847

.lr.ph847:                                        ; preds = %.lr.ph847.preheader, %.lr.ph847
  %indvars.iv851 = phi i64 [ 2, %.lr.ph847.preheader ], [ %indvars.iv.next852, %.lr.ph847 ]
  %.0845 = phi i32 [ %75, %.lr.ph847.preheader ], [ %84, %.lr.ph847 ]
  %78 = add i64 %indvars.iv851, %77
  %79 = getelementptr i32, ptr %.unpack649, i64 %78
  %indvars.iv.next852 = add nuw nsw i64 %indvars.iv851, 1
  %sext = shl i64 %indvars.iv.next852, 32
  %80 = ashr exact i64 %sext, 32
  %81 = add nsw i64 %80, -1
  %82 = getelementptr i32, ptr %.unpack697, i64 %81
  %83 = call i32 @_QFPgcd(ptr %79, ptr %82)
  %84 = call i32 @llvm.smax.i32(i32 %.0845, i32 %83)
  %exitcond854.not = icmp eq i64 %indvars.iv851, %.pre857
  br i1 %exitcond854.not, label %._crit_edge848, label %.lr.ph847

._crit_edge848:                                   ; preds = %.lr.ph847, %._crit_edge844.thread, %._crit_edge844
  %.pre-phi858863 = phi i64 [ %.pre857, %._crit_edge844 ], [ %57, %._crit_edge844.thread ], [ %.pre857, %.lr.ph847 ]
  %.0.lcssa = phi i32 [ %75, %._crit_edge844 ], [ %60, %._crit_edge844.thread ], [ %84, %.lr.ph847 ]
  %85 = sub i64 %.pre-phi858863, %.unpack656.unpack.unpack
  %86 = getelementptr i32, ptr %.unpack649, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !3
  %88 = call i32 @llvm.smax.i32(i32 %.0.lcssa, i32 %87)
  %89 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.30f39f96a409083f2d4021e4392a8fa5, i32 31)
  %90 = call i1 @_FortranAioOutputInteger32(ptr %89, i32 %88)
  %91 = call i32 @_FortranAioEndIoStatement(ptr %89)
  ret void
}

; Function Attrs: nofree nosync nounwind memory(argmem: read)
define i32 @_QFPgcd(ptr nocapture readonly %0, ptr nocapture readonly %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = load i32, ptr %0, align 4, !tbaa !3
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %6 = srem i32 %4, %5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %10, label %8

8:                                                ; preds = %2
  store i32 %6, ptr %3, align 4, !tbaa !3
  %9 = call i32 @_QFPgcd(ptr nonnull %1, ptr nonnull %3)
  br label %10

10:                                               ; preds = %2, %8
  %.0 = phi i32 [ %9, %8 ], [ %5, %2 ]
  ret i32 %.0
}

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 @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) 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 i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nofree nosync nounwind memory(argmem: read) }
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}
