program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,l,q,t(100000)
    
    integer(8),allocatable :: a(:),b(:),c(:)
  
    read(*,*) n
    allocate(a(n))
    read(*,*)a
    read(*,*)q
    allocate(b(q))
    allocate(c(q))
    do i=1,q
        read(*,*)b(i),c(i)
    end do
    do i=1,10000
        t(i)=0
    end do
    do i=1,n
        m=a(i)
        t(m)=t(m)+1
    end do
    m=sum(a)


    do i=1,q
        k=b(i)
        l=c(i)
        m=m+(l-k)*t(k)
        t(l)=t(l)+t(k)
        t(k)=0
        
        write(*,*)m
    end do
    
    
    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"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEt = internal unnamed_addr global [100000 x i64] undef
@_QQcl.aa7a5478b42c031d6419d4d6c2030a92 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1135/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 i64, align 8
  %3 = alloca i64, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.aa7a5478b42c031d6419d4d6c2030a92, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i64, ptr %2, align 8, !tbaa !3
  %8 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 3
  %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 ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.aa7a5478b42c031d6419d4d6c2030a92, i32 10)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack374.unpack.unpack376 = load i64, ptr @_QFEa.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 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 %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 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 %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 %.unpack374.unpack.unpack376, 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 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %12 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %14 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.aa7a5478b42c031d6419d4d6c2030a92, i32 11)
  %15 = call i1 @_FortranAioInputInteger(ptr %14, ptr nonnull %3, i32 8)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %14)
  %17 = load i64, ptr %3, align 8, !tbaa !3
  %18 = call i64 @llvm.smax.i64(i64 %17, i64 0)
  %19 = shl i64 %18, 3
  %20 = call ptr @malloc(i64 %19)
  store ptr %20, ptr @_QFEb.0, align 8, !tbaa !7
  %21 = call ptr @malloc(i64 %19)
  store ptr %21, ptr @_QFEc.0, align 8, !tbaa !7
  %22 = icmp sgt i64 %17, 0
  br i1 %22, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %0
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(80000) @_QFEt, i8 0, i64 80000, i1 false), !tbaa !3
  %23 = load i64, ptr %2, align 8, !tbaa !3
  %24 = icmp sgt i64 %23, 0
  %.unpack433 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br i1 %24, label %.lr.ph469.preheader, label %._crit_edge

.lr.ph469.preheader:                              ; preds = %.preheader
  %xtraiter = and i64 %23, 1
  %25 = icmp eq i64 %23, 1
  br i1 %25, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph469.preheader.new

.lr.ph469.preheader.new:                          ; preds = %.lr.ph469.preheader
  %unroll_iter = and i64 %23, -2
  br label %.lr.ph469

.lr.ph:                                           ; preds = %0, %.lr.ph
  %26 = phi i64 [ %35, %.lr.ph ], [ 1, %0 ]
  %27 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.aa7a5478b42c031d6419d4d6c2030a92, i32 15)
  %.unpack445 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %28 = add i64 %26, -1
  %29 = getelementptr i64, ptr %.unpack445, i64 %28
  %30 = call i1 @_FortranAioInputInteger(ptr %27, ptr %29, i32 8)
  %.unpack457 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %31 = add i64 %26, -1
  %32 = getelementptr i64, ptr %.unpack457, i64 %31
  %33 = call i1 @_FortranAioInputInteger(ptr %27, ptr %32, i32 8)
  %34 = call i32 @_FortranAioEndIoStatement(ptr %27)
  %35 = add nuw i64 %26, 1
  %exitcond.not = icmp eq i64 %26, %17
  br i1 %exitcond.not, label %.preheader, label %.lr.ph

.lr.ph469:                                        ; preds = %.lr.ph469, %.lr.ph469.preheader.new
  %36 = phi i64 [ 1, %.lr.ph469.preheader.new ], [ %50, %.lr.ph469 ]
  %niter = phi i64 [ 0, %.lr.ph469.preheader.new ], [ %niter.next.1, %.lr.ph469 ]
  %37 = add nsw i64 %36, -1
  %38 = getelementptr i64, ptr %.unpack433, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !3
  %40 = add i64 %39, -1
  %41 = getelementptr [100000 x i64], ptr @_QFEt, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !3
  %43 = add i64 %42, 1
  store i64 %43, ptr %41, align 8, !tbaa !3
  %44 = getelementptr i64, ptr %.unpack433, i64 %36
  %45 = load i64, ptr %44, align 8, !tbaa !3
  %46 = add i64 %45, -1
  %47 = getelementptr [100000 x i64], ptr @_QFEt, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !3
  %49 = add i64 %48, 1
  store i64 %49, ptr %47, align 8, !tbaa !3
  %50 = add nuw i64 %36, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph469

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %.lr.ph469
  %51 = add i64 %36, 1
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph469.preheader
  %.unr = phi i64 [ 0, %.lr.ph469.preheader ], [ %51, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph469.epil

.lr.ph469.epil:                                   ; preds = %._crit_edge.loopexit.unr-lcssa
  %52 = getelementptr i64, ptr %.unpack433, i64 %.unr
  %53 = load i64, ptr %52, align 8, !tbaa !3
  %54 = add i64 %53, -1
  %55 = getelementptr [100000 x i64], ptr @_QFEt, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !3
  %57 = add i64 %56, 1
  store i64 %57, ptr %55, align 8, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph469.epil, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %.unpack404.unpack.unpack406 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %58 = icmp sgt i64 %.unpack404.unpack.unpack406, 0
  br i1 %58, label %.lr.ph.i.preheader, label %_FortranASumInteger8x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %min.iters.check = icmp ult i64 %.unpack404.unpack.unpack406, 4
  br i1 %min.iters.check, label %.lr.ph.i.preheader478, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack404.unpack.unpack406, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %62, %vector.body ]
  %vec.phi476 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %63, %vector.body ]
  %59 = shl i64 %index, 3
  %60 = getelementptr i8, ptr %.unpack433, i64 %59
  %wide.load = load <2 x i64>, ptr %60, align 8, !tbaa !3
  %61 = getelementptr i64, ptr %60, i64 2
  %wide.load477 = load <2 x i64>, ptr %61, align 8, !tbaa !3
  %62 = add <2 x i64> %wide.load, %vec.phi
  %63 = add <2 x i64> %wide.load477, %vec.phi476
  %index.next = add nuw i64 %index, 4
  %64 = icmp eq i64 %index.next, %n.vec
  br i1 %64, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %63, %62
  %65 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %.unpack404.unpack.unpack406, %n.vec
  br i1 %cmp.n, label %_FortranASumInteger8x1_contract_simplified.exit, label %.lr.ph.i.preheader478

.lr.ph.i.preheader478:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i64 [ 0, %.lr.ph.i.preheader ], [ %65, %middle.block ]
  %.ph479 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader478, %.lr.ph.i
  %66 = phi i64 [ %71, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader478 ]
  %67 = phi i64 [ %72, %.lr.ph.i ], [ %.ph479, %.lr.ph.i.preheader478 ]
  %68 = shl i64 %67, 3
  %69 = getelementptr i8, ptr %.unpack433, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !3
  %71 = add i64 %70, %66
  %72 = add nuw nsw i64 %67, 1
  %exitcond.not.i = icmp eq i64 %72, %.unpack404.unpack.unpack406
  br i1 %exitcond.not.i, label %_FortranASumInteger8x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger8x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %._crit_edge
  %.lcssa.i = phi i64 [ 0, %._crit_edge ], [ %65, %middle.block ], [ %71, %.lr.ph.i ]
  %73 = load i64, ptr %3, align 8, !tbaa !3
  %74 = icmp sgt i64 %73, 0
  br i1 %74, label %.lr.ph471, label %._crit_edge472

.lr.ph471:                                        ; preds = %_FortranASumInteger8x1_contract_simplified.exit, %.lr.ph471
  %75 = phi i64 [ %95, %.lr.ph471 ], [ 1, %_FortranASumInteger8x1_contract_simplified.exit ]
  %.0470 = phi i64 [ %87, %.lr.ph471 ], [ %.lcssa.i, %_FortranASumInteger8x1_contract_simplified.exit ]
  %.unpack409 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %76 = add i64 %75, -1
  %77 = getelementptr i64, ptr %.unpack409, i64 %76
  %78 = load i64, ptr %77, align 8, !tbaa !3
  %.unpack421 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %79 = add i64 %75, -1
  %80 = getelementptr i64, ptr %.unpack421, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !3
  %82 = sub i64 %81, %78
  %83 = add i64 %78, -1
  %84 = getelementptr [100000 x i64], ptr @_QFEt, i64 0, i64 %83
  %85 = load i64, ptr %84, align 8, !tbaa !3
  %86 = mul i64 %82, %85
  %87 = add i64 %86, %.0470
  %88 = add i64 %81, -1
  %89 = getelementptr [100000 x i64], ptr @_QFEt, i64 0, i64 %88
  %90 = load i64, ptr %89, align 8, !tbaa !3
  %91 = add i64 %90, %85
  store i64 %91, ptr %89, align 8, !tbaa !3
  store i64 0, ptr %84, align 8, !tbaa !3
  %92 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.aa7a5478b42c031d6419d4d6c2030a92, i32 34)
  %93 = call i1 @_FortranAioOutputInteger64(ptr %92, i64 %87)
  %94 = call i32 @_FortranAioEndIoStatement(ptr %92)
  %95 = add nuw i64 %75, 1
  %exitcond474.not = icmp eq i64 %75, %73
  br i1 %exitcond474.not, label %._crit_edge472, label %.lr.ph471

._crit_edge472:                                   ; preds = %.lr.ph471, %_FortranASumInteger8x1_contract_simplified.exit
  %96 = 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 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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}
