program test
implicit none
integer::k,l,m,i,s
integer::ans=1000000
integer,allocatable::a(:),b(:),c(:),x(:),y(:)
read(5,*),k,l,m
allocate(a(k))
allocate(b(l))
allocate(c(m))
allocate(x(m))
allocate(y(m))
 
	read(5,*)(a(i),i=1,k)
	read(5,*)(b(i),i=1,l)
 	read(5,*)(x(i),y(i),c(i),i=1,m)
    
do i=1,m 
    s=a(x(i))+b(y(i))-c(i)
    ans=min(s,ans)
end do 
 
ans=min(minval(a)+minval(b),ans)
print*,ans
end program test
; 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
@_QFEans = internal unnamed_addr global i32 1000000
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEb.8 = internal unnamed_addr global i64 0
@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEx.0 = internal unnamed_addr global ptr null
@_QFEy.0 = internal unnamed_addr global ptr null
@_QQcl.56c3b9abf0763ae59daff5a3823634e8 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2134/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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.56c3b9abf0763ae59daff5a3823634e8, i32 6)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %3, i32 4)
  %8 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %4, i32 4)
  %9 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %5, i32 4)
  %10 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %11 = load i32, ptr %3, align 4, !tbaa !3
  %12 = call i32 @llvm.smax.i32(i32 %11, i32 0)
  %13 = zext i32 %12 to i64
  %14 = shl nuw nsw i64 %13, 2
  %15 = call ptr @malloc(i64 %14)
  store ptr %15, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %13, ptr @_QFEa.8, align 8, !tbaa !7
  %16 = load i32, ptr %4, align 4, !tbaa !3
  %17 = call i32 @llvm.smax.i32(i32 %16, i32 0)
  %18 = zext i32 %17 to i64
  %19 = shl nuw nsw i64 %18, 2
  %20 = call ptr @malloc(i64 %19)
  store ptr %20, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 %18, ptr @_QFEb.8, align 8, !tbaa !7
  %21 = load i32, ptr %5, align 4, !tbaa !3
  %22 = call i32 @llvm.smax.i32(i32 %21, i32 0)
  %23 = zext i32 %22 to i64
  %24 = shl nuw nsw i64 %23, 2
  %25 = call ptr @malloc(i64 %24)
  store ptr %25, ptr @_QFEc.0, align 8, !tbaa !7
  %26 = call ptr @malloc(i64 %24)
  store ptr %26, ptr @_QFEx.0, align 8, !tbaa !7
  %27 = call ptr @malloc(i64 %24)
  store ptr %27, ptr @_QFEy.0, align 8, !tbaa !7
  %28 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.56c3b9abf0763ae59daff5a3823634e8, i32 13)
  %29 = load i32, ptr %3, align 4, !tbaa !3
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %31 = zext i32 %29 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %32 = phi i64 [ %37, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.unpack735 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %sext747 = shl i64 %32, 32
  %33 = ashr exact i64 %sext747, 32
  %34 = add nsw i64 %33, -1
  %35 = getelementptr i32, ptr %.unpack735, i64 %34
  %36 = call i1 @_FortranAioInputInteger(ptr %28, ptr %35, i32 4)
  %37 = add nuw nsw i64 %32, 1
  %exitcond.not = icmp eq i64 %32, %31
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %38 = call i32 @_FortranAioEndIoStatement(ptr %28)
  %39 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.56c3b9abf0763ae59daff5a3823634e8, i32 14)
  %40 = load i32, ptr %4, align 4, !tbaa !3
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %.lr.ph749.preheader, label %._crit_edge750

.lr.ph749.preheader:                              ; preds = %._crit_edge
  %42 = zext i32 %40 to i64
  br label %.lr.ph749

.lr.ph749:                                        ; preds = %.lr.ph749.preheader, %.lr.ph749
  %43 = phi i64 [ %48, %.lr.ph749 ], [ 1, %.lr.ph749.preheader ]
  %.unpack722 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %sext734 = shl i64 %43, 32
  %44 = ashr exact i64 %sext734, 32
  %45 = add nsw i64 %44, -1
  %46 = getelementptr i32, ptr %.unpack722, i64 %45
  %47 = call i1 @_FortranAioInputInteger(ptr %39, ptr %46, i32 4)
  %48 = add nuw nsw i64 %43, 1
  %exitcond757.not = icmp eq i64 %43, %42
  br i1 %exitcond757.not, label %._crit_edge750, label %.lr.ph749

._crit_edge750:                                   ; preds = %.lr.ph749, %._crit_edge
  %49 = call i32 @_FortranAioEndIoStatement(ptr %39)
  %50 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.56c3b9abf0763ae59daff5a3823634e8, i32 15)
  %51 = load i32, ptr %5, align 4, !tbaa !3
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %.lr.ph752.preheader, label %._crit_edge753

.lr.ph752.preheader:                              ; preds = %._crit_edge750
  %53 = zext i32 %51 to i64
  br label %.lr.ph752

.lr.ph752:                                        ; preds = %.lr.ph752.preheader, %.lr.ph752
  %54 = phi i64 [ %65, %.lr.ph752 ], [ 1, %.lr.ph752.preheader ]
  %.unpack686 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %sext = shl i64 %54, 32
  %55 = ashr exact i64 %sext, 32
  %56 = add nsw i64 %55, -1
  %57 = getelementptr i32, ptr %.unpack686, i64 %56
  %58 = call i1 @_FortranAioInputInteger(ptr %50, ptr %57, i32 4)
  %.unpack698 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %59 = add nsw i64 %55, -1
  %60 = getelementptr i32, ptr %.unpack698, i64 %59
  %61 = call i1 @_FortranAioInputInteger(ptr %50, ptr %60, i32 4)
  %.unpack710 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %62 = add nsw i64 %55, -1
  %63 = getelementptr i32, ptr %.unpack710, i64 %62
  %64 = call i1 @_FortranAioInputInteger(ptr %50, ptr %63, i32 4)
  %65 = add nuw nsw i64 %54, 1
  %exitcond758.not = icmp eq i64 %54, %53
  br i1 %exitcond758.not, label %._crit_edge753, label %.lr.ph752

._crit_edge753:                                   ; preds = %.lr.ph752, %._crit_edge750
  %66 = call i32 @_FortranAioEndIoStatement(ptr %50)
  %67 = load i32, ptr %5, align 4, !tbaa !3
  %68 = icmp sgt i32 %67, 0
  br i1 %68, label %.lr.ph755, label %._crit_edge753._crit_edge

._crit_edge753._crit_edge:                        ; preds = %._crit_edge753
  %.unpack.pre = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br label %92

.lr.ph755:                                        ; preds = %._crit_edge753
  %69 = zext i32 %67 to i64
  %_QFEans.promoted = load i32, ptr @_QFEans, align 4, !tbaa !3
  %.unpack626 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack638 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack650 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack662 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %.unpack674 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  br label %70

70:                                               ; preds = %.lr.ph755, %70
  %indvars.iv = phi i64 [ 1, %.lr.ph755 ], [ %indvars.iv.next, %70 ]
  %71 = phi i32 [ %_QFEans.promoted, %.lr.ph755 ], [ %91, %70 ]
  %72 = add nsw i64 %indvars.iv, -1
  %73 = getelementptr i32, ptr %.unpack638, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !3
  %75 = sext i32 %74 to i64
  %76 = add nsw i64 %75, -1
  %77 = getelementptr i32, ptr %.unpack626, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !3
  %79 = add nsw i64 %indvars.iv, -1
  %80 = getelementptr i32, ptr %.unpack662, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !3
  %82 = sext i32 %81 to i64
  %83 = add nsw i64 %82, -1
  %84 = getelementptr i32, ptr %.unpack650, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !3
  %86 = add i32 %85, %78
  %87 = add nsw i64 %indvars.iv, -1
  %88 = getelementptr i32, ptr %.unpack674, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !3
  %90 = sub i32 %86, %89
  %91 = call i32 @llvm.smin.i32(i32 %90, i32 %71)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond760.not = icmp eq i64 %indvars.iv, %69
  br i1 %exitcond760.not, label %._crit_edge756, label %70

._crit_edge756:                                   ; preds = %70
  store i32 %91, ptr @_QFEans, align 4, !tbaa !3
  br label %92

92:                                               ; preds = %._crit_edge753._crit_edge, %._crit_edge756
  %.unpack = phi ptr [ %.unpack.pre, %._crit_edge753._crit_edge ], [ %.unpack626, %._crit_edge756 ]
  %.unpack609.unpack.unpack611 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %2, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack609.unpack.unpack611, 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 %2, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %93 = call i32 @_FortranAMinvalInteger4(ptr nonnull %2, ptr nonnull @_QQcl.56c3b9abf0763ae59daff5a3823634e8, i32 22, i32 0, ptr null)
  %.unpack614 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack621.unpack.unpack623 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  store ptr %.unpack614, ptr %1, align 8, !tbaa !7
  %.fca.1.gep238 = 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.gep238, align 8, !tbaa !7
  %.fca.2.gep240 = 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.gep240, align 8, !tbaa !7
  %.fca.3.gep242 = 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.gep242, align 4, !tbaa !7
  %.fca.4.gep244 = 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.gep244, align 1, !tbaa !7
  %.fca.5.gep246 = 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.gep246, align 2, !tbaa !7
  %.fca.6.gep248 = 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.gep248, align 1, !tbaa !7
  %.fca.7.0.0.gep250 = 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.gep250, align 8, !tbaa !7
  %.fca.7.0.1.gep252 = 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 %.unpack621.unpack.unpack623, ptr %.fca.7.0.1.gep252, align 8, !tbaa !7
  %.fca.7.0.2.gep254 = 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.gep254, align 8, !tbaa !7
  %94 = call i32 @_FortranAMinvalInteger4(ptr nonnull %1, ptr nonnull @_QQcl.56c3b9abf0763ae59daff5a3823634e8, i32 22, i32 0, ptr null)
  %95 = add i32 %94, %93
  %96 = load i32, ptr @_QFEans, align 4, !tbaa !3
  %97 = call i32 @llvm.smin.i32(i32 %95, i32 %96)
  store i32 %97, ptr @_QFEans, align 4, !tbaa !3
  %98 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.56c3b9abf0763ae59daff5a3823634e8, i32 23)
  %99 = load i32, ptr @_QFEans, align 4, !tbaa !3
  %100 = call i1 @_FortranAioOutputInteger32(ptr %98, i32 %99)
  %101 = call i32 @_FortranAioEndIoStatement(ptr %98)
  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 i32 @_FortranAMinvalInteger4(ptr, ptr, i32, i32, 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 i32 @llvm.smax.i32(i32, i32) #1

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

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