program main
implicit none
integer :: i, j, k
integer :: n, m
integer , allocatable :: x(:), t(:), p(:)

read(*,*) n
allocate( x(n) )
read(*,*) x
read(*,*) m
allocate( t(m), p(m) )
j = sum( x )
do i = 1, m
   read(*,*) t(i), p(i)
   k = t(i)
   write(*,'(i0)') j - x(k) + p(i)
end do


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"

@_QFEp.0 = internal unnamed_addr global ptr null
@_QFEt.0 = internal unnamed_addr global ptr null
@_QFEx.0 = internal unnamed_addr global ptr null
@_QFEx.8 = internal unnamed_addr global i64 0
@_QQcl.e212277eb882691b0cb3a89b5d006809 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7636/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

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 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e212277eb882691b0cb3a89b5d006809, i32 7)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i32, ptr %3, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEx.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEx.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e212277eb882691b0cb3a89b5d006809, i32 9)
  %.unpack = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack359.unpack.unpack361 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  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 %.unpack359.unpack.unpack361, 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
  %13 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %15 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e212277eb882691b0cb3a89b5d006809, i32 10)
  %16 = call i1 @_FortranAioInputInteger(ptr %15, ptr nonnull %2, i32 4)
  %17 = call i32 @_FortranAioEndIoStatement(ptr %15)
  %18 = load i32, ptr %2, align 4, !tbaa !3
  %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 @_QFEt.0, align 8, !tbaa !7
  %23 = call ptr @malloc(i64 %21)
  store ptr %23, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack382 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack389.unpack.unpack391 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  %24 = icmp sgt i64 %.unpack389.unpack.unpack391, 0
  br i1 %24, label %.lr.ph.i.preheader, label %_FortranASumInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %0
  %min.iters.check = icmp ult i64 %.unpack389.unpack.unpack391, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader457, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack389.unpack.unpack391, -8
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %28, %vector.body ]
  %vec.phi455 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %29, %vector.body ]
  %25 = shl i64 %index, 2
  %26 = getelementptr i8, ptr %.unpack382, i64 %25
  %wide.load = load <4 x i32>, ptr %26, align 4, !tbaa !3
  %27 = getelementptr i32, ptr %26, i64 4
  %wide.load456 = load <4 x i32>, ptr %27, align 4, !tbaa !3
  %28 = add <4 x i32> %wide.load, %vec.phi
  %29 = add <4 x i32> %wide.load456, %vec.phi455
  %index.next = add nuw i64 %index, 8
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %29, %28
  %31 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %.unpack389.unpack.unpack391, %n.vec
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader457

.lr.ph.i.preheader457:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i32 [ 0, %.lr.ph.i.preheader ], [ %31, %middle.block ]
  %.ph458 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader457, %.lr.ph.i
  %32 = phi i32 [ %37, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader457 ]
  %33 = phi i64 [ %38, %.lr.ph.i ], [ %.ph458, %.lr.ph.i.preheader457 ]
  %34 = shl i64 %33, 2
  %35 = getelementptr i8, ptr %.unpack382, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !3
  %37 = add i32 %36, %32
  %38 = add nuw nsw i64 %33, 1
  %exitcond.not.i = icmp eq i64 %38, %.unpack389.unpack.unpack391
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %0
  %.lcssa.i = phi i32 [ 0, %0 ], [ %31, %middle.block ], [ %37, %.lr.ph.i ]
  %39 = icmp sgt i32 %18, 0
  br i1 %39, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %_FortranASumInteger4x1_contract_simplified.exit
  %40 = zext i32 %18 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %41 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e212277eb882691b0cb3a89b5d006809, i32 14)
  %.unpack394 = load ptr, ptr @_QFEt.0, align 8, !tbaa !7
  %42 = add nsw i64 %indvars.iv, -1
  %43 = getelementptr i32, ptr %.unpack394, i64 %42
  %44 = call i1 @_FortranAioInputInteger(ptr %41, ptr %43, i32 4)
  %.unpack406 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %45 = add nsw i64 %indvars.iv, -1
  %46 = getelementptr i32, ptr %.unpack406, i64 %45
  %47 = call i1 @_FortranAioInputInteger(ptr %41, ptr %46, i32 4)
  %48 = call i32 @_FortranAioEndIoStatement(ptr %41)
  %.unpack418 = load ptr, ptr @_QFEt.0, align 8, !tbaa !7
  %49 = add nsw i64 %indvars.iv, -1
  %50 = getelementptr i32, ptr %.unpack418, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !3
  %52 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.e212277eb882691b0cb3a89b5d006809, i32 16)
  %.unpack430 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %53 = sext i32 %51 to i64
  %54 = add nsw i64 %53, -1
  %55 = getelementptr i32, ptr %.unpack430, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !3
  %57 = sub i32 %.lcssa.i, %56
  %.unpack442 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %58 = add nsw i64 %indvars.iv, -1
  %59 = getelementptr i32, ptr %.unpack442, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !3
  %61 = add i32 %57, %60
  %62 = call i1 @_FortranAioOutputInteger32(ptr %52, i32 %61)
  %63 = call i32 @_FortranAioEndIoStatement(ptr %52)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %40
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %_FortranASumInteger4x1_contract_simplified.exit
  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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

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) }
attributes #2 = { nocallback nofree nosync nounwind 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}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
