program sample
    implicit none
  
    integer(8) :: i,j,m,n,s,t,xi,yi,a,b,c
   
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) a,b,m
    allocate(x(a),y(b))
    read(*,*)x
    read(*,*)y
    s=minval(x)+minval(y)
    do i=1,m
        read(*,*)xi,yi,c
        if (x(xi)+y(yi)-c<s)then
            s=x(xi)+y(yi)-c
        end if
    end do


  
    write(*,*) s
  
    stop
end program sample
  


; 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
@_QFEy.0 = internal unnamed_addr global ptr null
@_QFEy.8 = internal unnamed_addr global i64 0
@_QQcl.833d0ba40ede98589b233fd000ea618e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2133/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

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %4 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.833d0ba40ede98589b233fd000ea618e, i32 8)
  %12 = call i1 @_FortranAioInputInteger(ptr %11, ptr nonnull %5, i32 8)
  %13 = call i1 @_FortranAioInputInteger(ptr %11, ptr nonnull %6, i32 8)
  %14 = call i1 @_FortranAioInputInteger(ptr %11, ptr nonnull %8, i32 8)
  %15 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %16 = load i64, ptr %5, align 8, !tbaa !3
  %17 = call i64 @llvm.smax.i64(i64 %16, i64 0)
  %18 = shl i64 %17, 3
  %19 = call ptr @malloc(i64 %18)
  store ptr %19, ptr @_QFEx.0, align 8, !tbaa !7
  store i64 %17, ptr @_QFEx.8, align 8, !tbaa !7
  %20 = load i64, ptr %6, align 8, !tbaa !3
  %21 = call i64 @llvm.smax.i64(i64 %20, i64 0)
  %22 = shl i64 %21, 3
  %23 = call ptr @malloc(i64 %22)
  store ptr %23, ptr @_QFEy.0, align 8, !tbaa !7
  store i64 %21, ptr @_QFEy.8, align 8, !tbaa !7
  %24 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.833d0ba40ede98589b233fd000ea618e, i32 10)
  %.unpack = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack376.unpack.unpack378 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %4, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %4, i64 0, i32 1
  store i64 8, 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 %4, 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 %4, 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 %4, i64 0, i32 4
  store i8 10, 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 %4, 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 %4, 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 %4, 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 %4, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack376.unpack.unpack378, 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 %4, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %25 = call i1 @_FortranAioInputDescriptor(ptr %24, ptr nonnull %4)
  %26 = call i32 @_FortranAioEndIoStatement(ptr %24)
  %27 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.833d0ba40ede98589b233fd000ea618e, i32 11)
  %.unpack381 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %.unpack388.unpack.unpack390 = load i64, ptr @_QFEy.8, align 8, !tbaa !7
  store ptr %.unpack381, ptr %3, align 8, !tbaa !7
  %.fca.1.gep113 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep113, align 8, !tbaa !7
  %.fca.2.gep115 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep115, align 8, !tbaa !7
  %.fca.3.gep117 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep117, align 4, !tbaa !7
  %.fca.4.gep119 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep119, align 1, !tbaa !7
  %.fca.5.gep121 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep121, align 2, !tbaa !7
  %.fca.6.gep123 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep123, align 1, !tbaa !7
  %.fca.7.0.0.gep125 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep125, align 8, !tbaa !7
  %.fca.7.0.1.gep127 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack388.unpack.unpack390, ptr %.fca.7.0.1.gep127, align 8, !tbaa !7
  %.fca.7.0.2.gep129 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep129, align 8, !tbaa !7
  %28 = call i1 @_FortranAioInputDescriptor(ptr %27, ptr nonnull %3)
  %29 = call i32 @_FortranAioEndIoStatement(ptr %27)
  %.unpack393 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack400.unpack.unpack402 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  store ptr %.unpack393, ptr %2, align 8, !tbaa !7
  %.fca.1.gep163 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep163, align 8, !tbaa !7
  %.fca.2.gep165 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep165, align 8, !tbaa !7
  %.fca.3.gep167 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep167, align 4, !tbaa !7
  %.fca.4.gep169 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep169, align 1, !tbaa !7
  %.fca.5.gep171 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep171, align 2, !tbaa !7
  %.fca.6.gep173 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep173, align 1, !tbaa !7
  %.fca.7.0.0.gep175 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep175, align 8, !tbaa !7
  %.fca.7.0.1.gep177 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack400.unpack.unpack402, ptr %.fca.7.0.1.gep177, align 8, !tbaa !7
  %.fca.7.0.2.gep179 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep179, align 8, !tbaa !7
  %30 = call i64 @_FortranAMinvalInteger8(ptr nonnull %2, ptr nonnull @_QQcl.833d0ba40ede98589b233fd000ea618e, i32 12, i32 0, ptr null)
  %.unpack405 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %.unpack412.unpack.unpack414 = load i64, ptr @_QFEy.8, align 8, !tbaa !7
  store ptr %.unpack405, ptr %1, align 8, !tbaa !7
  %.fca.1.gep213 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep213, align 8, !tbaa !7
  %.fca.2.gep215 = 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.gep215, align 8, !tbaa !7
  %.fca.3.gep217 = 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.gep217, align 4, !tbaa !7
  %.fca.4.gep219 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep219, align 1, !tbaa !7
  %.fca.5.gep221 = 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.gep221, align 2, !tbaa !7
  %.fca.6.gep223 = 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.gep223, align 1, !tbaa !7
  %.fca.7.0.0.gep225 = 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.gep225, align 8, !tbaa !7
  %.fca.7.0.1.gep227 = 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 %.unpack412.unpack.unpack414, ptr %.fca.7.0.1.gep227, align 8, !tbaa !7
  %.fca.7.0.2.gep229 = 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 8, ptr %.fca.7.0.2.gep229, align 8, !tbaa !7
  %31 = call i64 @_FortranAMinvalInteger8(ptr nonnull %1, ptr nonnull @_QQcl.833d0ba40ede98589b233fd000ea618e, i32 12, i32 0, ptr null)
  %32 = add i64 %31, %30
  %33 = load i64, ptr %8, align 8, !tbaa !3
  %34 = icmp sgt i64 %33, 0
  br i1 %34, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %35 = phi i64 [ %52, %.lr.ph ], [ %33, %0 ]
  %.0441 = phi i64 [ %spec.select, %.lr.ph ], [ %32, %0 ]
  %36 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.833d0ba40ede98589b233fd000ea618e, i32 14)
  %37 = call i1 @_FortranAioInputInteger(ptr %36, ptr nonnull %9, i32 8)
  %38 = call i1 @_FortranAioInputInteger(ptr %36, ptr nonnull %10, i32 8)
  %39 = call i1 @_FortranAioInputInteger(ptr %36, ptr nonnull %7, i32 8)
  %40 = call i32 @_FortranAioEndIoStatement(ptr %36)
  %.unpack417 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %41 = load i64, ptr %9, align 8, !tbaa !3
  %42 = add i64 %41, -1
  %43 = getelementptr i64, ptr %.unpack417, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !3
  %.unpack429 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %45 = load i64, ptr %10, align 8, !tbaa !3
  %46 = add i64 %45, -1
  %47 = getelementptr i64, ptr %.unpack429, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !3
  %49 = add i64 %48, %44
  %50 = load i64, ptr %7, align 8, !tbaa !3
  %51 = sub i64 %49, %50
  %spec.select = call i64 @llvm.smin.i64(i64 %51, i64 %.0441)
  %52 = add nsw i64 %35, -1
  %53 = icmp ugt i64 %35, 1
  br i1 %53, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.0.lcssa = phi i64 [ %32, %0 ], [ %spec.select, %.lr.ph ]
  %54 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.833d0ba40ede98589b233fd000ea618e, i32 22)
  %55 = call i1 @_FortranAioOutputInteger64(ptr %54, i64 %.0.lcssa)
  %56 = call i32 @_FortranAioEndIoStatement(ptr %54)
  %57 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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

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

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) 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.smin.i64(i64, i64) #2

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