      PROGRAM replacing
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 16
      integer(p) :: n,q,S
      integer(p),allocatable :: a(:),b(:),c(:)
      
      integer(p) :: i, table(10**5)=0
      
      
      read*,n
      allocate( a(n) )
      read*,a
      read*,q
      allocate( b(q),c(q) )
      do i = 1,q
        read*,b(i),c(i)
      end do
      
      S = sum( a )
      do i = 1,n
        table(a(i)) = table(a(i)) + 1
      end do
      
      do i = 1,q
        S = S - table(b(i))*b(i) + c(i)*table(b(i))
        table(c(i)) = table(c(i)) + table(b(i))
        table(b(i)) = 0
        print*,S
      end do
      
      
      
      
      stop
      !debugg
      
      print'(*(x,i0))',table(1:maxval(a))
      
      
      END PROGRAM
; 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
@_QFEtable = internal unnamed_addr global [100000 x i128] zeroinitializer
@_QQcl.8fa25026084b66412eea62f19622e341 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1137/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 i128, align 8
  %3 = alloca i128, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8fa25026084b66412eea62f19622e341, i32 10)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 16)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i128, ptr %2, align 8, !tbaa !3
  %8 = trunc i128 %7 to i64
  %9 = call i64 @llvm.smax.i64(i64 %8, i64 0)
  %10 = shl i64 %9, 4
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEa.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8fa25026084b66412eea62f19622e341, i32 12)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack456.unpack.unpack458 = 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 16, 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 11, 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 %.unpack456.unpack.unpack458, 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 16, 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.8fa25026084b66412eea62f19622e341, i32 13)
  %16 = call i1 @_FortranAioInputInteger(ptr %15, ptr nonnull %3, i32 16)
  %17 = call i32 @_FortranAioEndIoStatement(ptr %15)
  %18 = load i128, ptr %3, align 8, !tbaa !3
  %19 = trunc i128 %18 to i64
  %20 = call i64 @llvm.smax.i64(i64 %19, i64 0)
  %21 = shl i64 %20, 4
  %22 = call ptr @malloc(i64 %21)
  store ptr %22, ptr @_QFEb.0, align 8, !tbaa !7
  %23 = call ptr @malloc(i64 %21)
  store ptr %23, ptr @_QFEc.0, align 8, !tbaa !7
  %24 = icmp sgt i64 %19, 0
  br i1 %24, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %25 = phi i64 [ %34, %.lr.ph ], [ 1, %0 ]
  %26 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8fa25026084b66412eea62f19622e341, i32 16)
  %.unpack539 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %27 = add i64 %25, -1
  %28 = getelementptr i128, ptr %.unpack539, i64 %27
  %29 = call i1 @_FortranAioInputInteger(ptr %26, ptr %28, i32 16)
  %.unpack551 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %30 = add i64 %25, -1
  %31 = getelementptr i128, ptr %.unpack551, i64 %30
  %32 = call i1 @_FortranAioInputInteger(ptr %26, ptr %31, i32 16)
  %33 = call i32 @_FortranAioEndIoStatement(ptr %26)
  %34 = add nuw i64 %25, 1
  %exitcond.not = icmp eq i64 %25, %19
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.unpack479 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack486.unpack.unpack488 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %35 = icmp sgt i64 %.unpack486.unpack.unpack488, 0
  br i1 %35, label %.lr.ph.i.preheader, label %_FortranASumInteger16x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %xtraiter = and i64 %.unpack486.unpack.unpack488, 3
  %36 = icmp ult i64 %.unpack486.unpack.unpack488, 4
  br i1 %36, label %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, label %.lr.ph.i.preheader.new

.lr.ph.i.preheader.new:                           ; preds = %.lr.ph.i.preheader
  %unroll_iter = and i64 %.unpack486.unpack.unpack488, -4
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i, %.lr.ph.i.preheader.new
  %37 = phi i128 [ 0, %.lr.ph.i.preheader.new ], [ %57, %.lr.ph.i ]
  %38 = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %58, %.lr.ph.i ]
  %niter = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %niter.next.3, %.lr.ph.i ]
  %39 = shl i64 %38, 4
  %40 = getelementptr i8, ptr %.unpack479, i64 %39
  %41 = load i128, ptr %40, align 8, !tbaa !3
  %42 = add i128 %41, %37
  %43 = shl i64 %38, 4
  %44 = or i64 %43, 16
  %45 = getelementptr i8, ptr %.unpack479, i64 %44
  %46 = load i128, ptr %45, align 8, !tbaa !3
  %47 = add i128 %46, %42
  %48 = shl i64 %38, 4
  %49 = or i64 %48, 32
  %50 = getelementptr i8, ptr %.unpack479, i64 %49
  %51 = load i128, ptr %50, align 8, !tbaa !3
  %52 = add i128 %51, %47
  %53 = shl i64 %38, 4
  %54 = or i64 %53, 48
  %55 = getelementptr i8, ptr %.unpack479, i64 %54
  %56 = load i128, ptr %55, align 8, !tbaa !3
  %57 = add i128 %56, %52
  %58 = add nuw nsw i64 %38, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, label %.lr.ph.i

_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa: ; preds = %.lr.ph.i, %.lr.ph.i.preheader
  %.lcssa.ph = phi i128 [ undef, %.lr.ph.i.preheader ], [ %57, %.lr.ph.i ]
  %.unr = phi i128 [ 0, %.lr.ph.i.preheader ], [ %57, %.lr.ph.i ]
  %.unr571 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %58, %.lr.ph.i ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %_FortranASumInteger16x1_contract_simplified.exit, label %.lr.ph.i.epil

.lr.ph.i.epil:                                    ; preds = %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, %.lr.ph.i.epil
  %59 = phi i128 [ %64, %.lr.ph.i.epil ], [ %.unr, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %60 = phi i64 [ %65, %.lr.ph.i.epil ], [ %.unr571, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.i.epil ], [ 0, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %61 = shl i64 %60, 4
  %62 = getelementptr i8, ptr %.unpack479, i64 %61
  %63 = load i128, ptr %62, align 8, !tbaa !3
  %64 = add i128 %63, %59
  %65 = add nuw nsw i64 %60, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %_FortranASumInteger16x1_contract_simplified.exit, label %.lr.ph.i.epil, !llvm.loop !9

_FortranASumInteger16x1_contract_simplified.exit: ; preds = %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, %.lr.ph.i.epil, %._crit_edge
  %.lcssa.i = phi i128 [ 0, %._crit_edge ], [ %.lcssa.ph, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ], [ %64, %.lr.ph.i.epil ]
  %66 = load i128, ptr %2, align 8, !tbaa !3
  %67 = trunc i128 %66 to i64
  %68 = icmp sgt i64 %67, 0
  br i1 %68, label %.lr.ph563.preheader, label %._crit_edge564

.lr.ph563.preheader:                              ; preds = %_FortranASumInteger16x1_contract_simplified.exit
  %xtraiter573 = and i64 %67, 1
  %69 = icmp eq i64 %67, 1
  br i1 %69, label %._crit_edge564.loopexit.unr-lcssa, label %.lr.ph563.preheader.new

.lr.ph563.preheader.new:                          ; preds = %.lr.ph563.preheader
  %unroll_iter577 = and i64 %67, -2
  br label %.lr.ph563

.lr.ph563:                                        ; preds = %.lr.ph563, %.lr.ph563.preheader.new
  %70 = phi i64 [ 1, %.lr.ph563.preheader.new ], [ %86, %.lr.ph563 ]
  %niter578 = phi i64 [ 0, %.lr.ph563.preheader.new ], [ %niter578.next.1, %.lr.ph563 ]
  %71 = add nsw i64 %70, -1
  %72 = getelementptr i128, ptr %.unpack479, i64 %71
  %73 = load i128, ptr %72, align 8, !tbaa !3
  %74 = trunc i128 %73 to i64
  %75 = add i64 %74, -1
  %76 = getelementptr [100000 x i128], ptr @_QFEtable, i64 0, i64 %75
  %77 = load i128, ptr %76, align 16, !tbaa !3
  %78 = add i128 %77, 1
  store i128 %78, ptr %76, align 16, !tbaa !3
  %79 = getelementptr i128, ptr %.unpack479, i64 %70
  %80 = load i128, ptr %79, align 8, !tbaa !3
  %81 = trunc i128 %80 to i64
  %82 = add i64 %81, -1
  %83 = getelementptr [100000 x i128], ptr @_QFEtable, i64 0, i64 %82
  %84 = load i128, ptr %83, align 16, !tbaa !3
  %85 = add i128 %84, 1
  store i128 %85, ptr %83, align 16, !tbaa !3
  %86 = add nuw i64 %70, 2
  %niter578.next.1 = add i64 %niter578, 2
  %niter578.ncmp.1 = icmp eq i64 %niter578.next.1, %unroll_iter577
  br i1 %niter578.ncmp.1, label %._crit_edge564.loopexit.unr-lcssa.loopexit, label %.lr.ph563

._crit_edge564.loopexit.unr-lcssa.loopexit:       ; preds = %.lr.ph563
  %87 = add i64 %70, 1
  br label %._crit_edge564.loopexit.unr-lcssa

._crit_edge564.loopexit.unr-lcssa:                ; preds = %._crit_edge564.loopexit.unr-lcssa.loopexit, %.lr.ph563.preheader
  %.unr575 = phi i64 [ 0, %.lr.ph563.preheader ], [ %87, %._crit_edge564.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod576.not = icmp eq i64 %xtraiter573, 0
  br i1 %lcmp.mod576.not, label %._crit_edge564, label %.lr.ph563.epil

.lr.ph563.epil:                                   ; preds = %._crit_edge564.loopexit.unr-lcssa
  %88 = getelementptr i128, ptr %.unpack479, i64 %.unr575
  %89 = load i128, ptr %88, align 8, !tbaa !3
  %90 = trunc i128 %89 to i64
  %91 = add i64 %90, -1
  %92 = getelementptr [100000 x i128], ptr @_QFEtable, i64 0, i64 %91
  %93 = load i128, ptr %92, align 16, !tbaa !3
  %94 = add i128 %93, 1
  store i128 %94, ptr %92, align 16, !tbaa !3
  br label %._crit_edge564

._crit_edge564:                                   ; preds = %.lr.ph563.epil, %._crit_edge564.loopexit.unr-lcssa, %_FortranASumInteger16x1_contract_simplified.exit
  %95 = load i128, ptr %3, align 8, !tbaa !3
  %96 = trunc i128 %95 to i64
  %97 = icmp sgt i64 %96, 0
  br i1 %97, label %.lr.ph567, label %._crit_edge568

.lr.ph567:                                        ; preds = %._crit_edge564, %.lr.ph567
  %98 = phi i64 [ %121, %.lr.ph567 ], [ 1, %._crit_edge564 ]
  %.0565 = phi i128 [ %112, %.lr.ph567 ], [ %.lcssa.i, %._crit_edge564 ]
  %.unpack491 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %99 = add i64 %98, -1
  %100 = getelementptr i128, ptr %.unpack491, i64 %99
  %101 = load i128, ptr %100, align 8, !tbaa !3
  %102 = trunc i128 %101 to i64
  %103 = add i64 %102, -1
  %104 = getelementptr [100000 x i128], ptr @_QFEtable, i64 0, i64 %103
  %105 = load i128, ptr %104, align 16, !tbaa !3
  %106 = mul i128 %105, %101
  %107 = sub i128 %.0565, %106
  %.unpack503 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %108 = add i64 %98, -1
  %109 = getelementptr i128, ptr %.unpack503, i64 %108
  %110 = load i128, ptr %109, align 8, !tbaa !3
  %111 = mul i128 %110, %105
  %112 = add i128 %111, %107
  %113 = trunc i128 %110 to i64
  %114 = add i64 %113, -1
  %115 = getelementptr [100000 x i128], ptr @_QFEtable, i64 0, i64 %114
  %116 = load i128, ptr %115, align 16, !tbaa !3
  %117 = add i128 %116, %105
  store i128 %117, ptr %115, align 16, !tbaa !3
  store i128 0, ptr %104, align 16, !tbaa !3
  %118 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.8fa25026084b66412eea62f19622e341, i32 28)
  %119 = call i1 @_FortranAioOutputInteger128(ptr %118, i128 %112)
  %120 = call i32 @_FortranAioEndIoStatement(ptr %118)
  %121 = add nuw i64 %98, 1
  %exitcond570.not = icmp eq i64 %98, %96
  br i1 %exitcond570.not, label %._crit_edge568, label %.lr.ph567

._crit_edge568:                                   ; preds = %.lr.ph567, %._crit_edge564
  %122 = 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 @_FortranAioOutputInteger128(ptr, i128) 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

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}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
