program replacing
  implicit none
  integer :: n, a(100000) = 0, q, b, c, i
  integer(8) :: s = 0, x(100000) = 0
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    s = s + a(i)
    x(a(i)) = x(a(i)) + 1
  end do
  read(*,*) q
  do i = 1, q
    read(*,*) b, c
    s = s + x(b) * (c - b)
    x(c) = x(c) + x(b)
    x(b) = 0
    write(*,'(i0)') s
  end do
end program replacing
; 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 = internal global [100000 x i32] zeroinitializer
@_QFEs = internal unnamed_addr global i64 0
@_QFEx = internal unnamed_addr global [100000 x i64] zeroinitializer
@_QQcl.122f994877c24f4fca3db5cba852792e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1132/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

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 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.122f994877c24f4fca3db5cba852792e, i32 5)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %4, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %9 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.122f994877c24f4fca3db5cba852792e, i32 6)
  %10 = load i32, ptr %4, align 4, !tbaa !3
  %11 = call i32 @llvm.smax.i32(i32 %10, i32 0)
  %12 = zext i32 %11 to i64
  store ptr @_QFEa, 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 %12, 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 %9, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %9)
  %15 = load i32, ptr %4, align 4, !tbaa !3
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph.preheader, label %46

.lr.ph.preheader:                                 ; preds = %0
  %_QFEs.promoted = load i64, ptr @_QFEs, align 8, !tbaa !3
  %17 = zext i32 %15 to i64
  %xtraiter = and i64 %17, 1
  %18 = icmp eq i32 %15, 1
  br i1 %18, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %17, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %19 = phi i64 [ %_QFEs.promoted, %.lr.ph.preheader.new ], [ %32, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %20 = add nsw i64 %indvars.iv, -1
  %21 = getelementptr [100000 x i32], ptr @_QFEa, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !3
  %23 = sext i32 %22 to i64
  %24 = add i64 %19, %23
  %25 = add nsw i64 %23, -1
  %26 = getelementptr [100000 x i64], ptr @_QFEx, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !3
  %28 = add i64 %27, 1
  store i64 %28, ptr %26, align 8, !tbaa !3
  %29 = getelementptr [100000 x i32], ptr @_QFEa, i64 0, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !3
  %31 = sext i32 %30 to i64
  %32 = add i64 %24, %31
  %33 = add nsw i64 %31, -1
  %34 = getelementptr [100000 x i64], ptr @_QFEx, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !3
  %36 = add i64 %35, 1
  store i64 %36, ptr %34, align 8, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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.unr-lcssa.loopexit, label %.lr.ph

._crit_edge.unr-lcssa.loopexit:                   ; preds = %.lr.ph
  %37 = add nuw nsw i64 %indvars.iv, 1
  br label %._crit_edge.unr-lcssa

._crit_edge.unr-lcssa:                            ; preds = %._crit_edge.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ undef, %.lr.ph.preheader ], [ %32, %._crit_edge.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %37, %._crit_edge.unr-lcssa.loopexit ]
  %.unr = phi i64 [ %_QFEs.promoted, %.lr.ph.preheader ], [ %32, %._crit_edge.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %38 = getelementptr [100000 x i32], ptr @_QFEa, i64 0, i64 %indvars.iv.unr
  %39 = load i32, ptr %38, align 4, !tbaa !3
  %40 = sext i32 %39 to i64
  %41 = add i64 %.unr, %40
  %42 = add nsw i64 %40, -1
  %43 = getelementptr [100000 x i64], ptr @_QFEx, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !3
  %45 = add i64 %44, 1
  store i64 %45, ptr %43, align 8, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %41, %.lr.ph.epil ]
  store i64 %.lcssa, ptr @_QFEs, align 8, !tbaa !3
  br label %46

46:                                               ; preds = %._crit_edge, %0
  %47 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.122f994877c24f4fca3db5cba852792e, i32 11)
  %48 = call i1 @_FortranAioInputInteger(ptr %47, ptr nonnull %5, i32 4)
  %49 = call i32 @_FortranAioEndIoStatement(ptr %47)
  %50 = load i32, ptr %5, align 4, !tbaa !3
  %51 = icmp sgt i32 %50, 0
  br i1 %51, label %.lr.ph6.preheader, label %._crit_edge7

.lr.ph6.preheader:                                ; preds = %46
  %52 = zext i32 %50 to i64
  br label %.lr.ph6

.lr.ph6:                                          ; preds = %.lr.ph6.preheader, %.lr.ph6
  %53 = phi i64 [ %78, %.lr.ph6 ], [ %52, %.lr.ph6.preheader ]
  %54 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.122f994877c24f4fca3db5cba852792e, i32 13)
  %55 = call i1 @_FortranAioInputInteger(ptr %54, ptr nonnull %2, i32 4)
  %56 = call i1 @_FortranAioInputInteger(ptr %54, ptr nonnull %3, i32 4)
  %57 = call i32 @_FortranAioEndIoStatement(ptr %54)
  %58 = load i64, ptr @_QFEs, align 8, !tbaa !3
  %59 = load i32, ptr %2, align 4, !tbaa !3
  %60 = sext i32 %59 to i64
  %61 = add nsw i64 %60, -1
  %62 = getelementptr [100000 x i64], ptr @_QFEx, i64 0, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !3
  %64 = load i32, ptr %3, align 4, !tbaa !3
  %65 = sub i32 %64, %59
  %66 = sext i32 %65 to i64
  %67 = mul i64 %63, %66
  %68 = add i64 %67, %58
  store i64 %68, ptr @_QFEs, align 8, !tbaa !3
  %69 = sext i32 %64 to i64
  %70 = add nsw i64 %69, -1
  %71 = getelementptr [100000 x i64], ptr @_QFEx, i64 0, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !3
  %73 = add i64 %72, %63
  store i64 %73, ptr %71, align 8, !tbaa !3
  store i64 0, ptr %62, align 8, !tbaa !3
  %74 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.122f994877c24f4fca3db5cba852792e, i32 17)
  %75 = load i64, ptr @_QFEs, align 8, !tbaa !3
  %76 = call i1 @_FortranAioOutputInteger64(ptr %74, i64 %75)
  %77 = call i32 @_FortranAioEndIoStatement(ptr %74)
  %78 = add nsw i64 %53, -1
  %79 = icmp ugt i64 %53, 1
  br i1 %79, label %.lr.ph6, label %._crit_edge7

._crit_edge7:                                     ; preds = %.lr.ph6, %46
  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 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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

attributes #0 = { 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}
