      PROGRAM piyo
      IMPLICIT NONE
      integer(16) :: n
      integer(16),allocatable :: a(:),counter(:),memo(:)
      integer(16) :: i,mm,buffer,memo2
      
      read*,n
      allocate( a(n),counter(n),memo(n) )
      read*,a(:)
      
      counter = 0
      do i = 1,n
        counter( a(i) ) = counter( a(i) ) + 1
      end do
      
      do i = 1,n
        mm = counter(i)
        memo( i ) = mm*(mm-1)/2
      end do
      memo2 = sum( memo )
      
      
      do i = 1,n
        mm = counter(a(i))
        buffer = memo2
        buffer = buffer - mm*(mm-1)/2
        mm = mm-1
        buffer = buffer + mm*(mm-1)/2
        print*,buffer
      end do
      
      
      
      
      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
@_QFEcounter.0 = internal unnamed_addr global ptr null
@_QFEcounter.7 = internal unnamed_addr global i64 1
@_QFEcounter.8 = internal unnamed_addr global i64 0
@_QFEmemo.0 = internal unnamed_addr global ptr null
@_QFEmemo.8 = internal unnamed_addr global i64 0
@_QQcl.e66e18b59f8a24d0fae10c7a85f22fa4 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2066/source.f\00"
@_QQcl.16373402fa3425c6e46827601abb88fa = linkonce constant [76 x i8] c"array left hand side must be allocated when the right hand side is a scalar\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 i128, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e66e18b59f8a24d0fae10c7a85f22fa4, i32 7)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 16)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i128, ptr %2, align 8, !tbaa !3
  %7 = trunc i128 %6 to i64
  %8 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 4
  %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 @malloc(i64 %9)
  store ptr %11, ptr @_QFEcounter.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEcounter.7, align 8, !tbaa !7
  store i64 %8, ptr @_QFEcounter.8, align 8, !tbaa !7
  %12 = call ptr @malloc(i64 %9)
  store ptr %12, ptr @_QFEmemo.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEmemo.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e66e18b59f8a24d0fae10c7a85f22fa4, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack508.unpack.unpack510 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %14 = call i64 @llvm.smax.i64(i64 %.unpack508.unpack.unpack510, i64 0)
  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 %14, 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
  %15 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %1)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %.unpack513 = load ptr, ptr @_QFEcounter.0, align 8, !tbaa !7
  %.unpack520.unpack.unpack522 = load i64, ptr @_QFEcounter.8, align 8, !tbaa !7
  %.not = icmp eq ptr %.unpack513, null
  br i1 %.not, label %19, label %.preheader

.preheader:                                       ; preds = %0
  %17 = icmp sgt i64 %.unpack520.unpack.unpack522, 0
  br i1 %17, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %18 = shl nuw i64 %.unpack520.unpack.unpack522, 4
  call void @llvm.memset.p0.i64(ptr nonnull align 8 %.unpack513, i8 0, i64 %18, i1 false), !tbaa !3
  br label %.loopexit

19:                                               ; preds = %0
  %20 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.e66e18b59f8a24d0fae10c7a85f22fa4, i32 11)
  %.unpack616.unpack.unpack = load i64, ptr @_QFEcounter.7, align 8, !tbaa !7
  %21 = icmp eq i64 %.unpack520.unpack.unpack522, 0
  %22 = select i1 %21, i64 1, i64 %.unpack616.unpack.unpack
  store ptr null, ptr @_QFEcounter.0, align 8, !tbaa !7
  store i64 %22, ptr @_QFEcounter.7, align 8, !tbaa !7
  store i64 %.unpack520.unpack.unpack522, ptr @_QFEcounter.8, align 8, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %.preheader, %19
  %23 = load i128, ptr %2, align 8, !tbaa !3
  %24 = trunc i128 %23 to i64
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %.lr.ph630, label %._crit_edge.._crit_edge633_crit_edge

.lr.ph630:                                        ; preds = %.loopexit
  %.unpack592.unpack.unpack = load i64, ptr @_QFEcounter.7, align 8, !tbaa !7
  %.unpack597 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter = and i64 %24, 1
  %26 = icmp eq i64 %24, 1
  br i1 %26, label %._crit_edge.unr-lcssa, label %.lr.ph630.new

.lr.ph630.new:                                    ; preds = %.lr.ph630
  %unroll_iter = and i64 %24, -2
  br label %27

27:                                               ; preds = %27, %.lr.ph630.new
  %28 = phi i64 [ 1, %.lr.ph630.new ], [ %44, %27 ]
  %niter = phi i64 [ 0, %.lr.ph630.new ], [ %niter.next.1, %27 ]
  %29 = add nsw i64 %28, -1
  %30 = getelementptr i128, ptr %.unpack597, i64 %29
  %31 = load i128, ptr %30, align 8, !tbaa !3
  %32 = trunc i128 %31 to i64
  %33 = sub i64 %32, %.unpack592.unpack.unpack
  %34 = getelementptr i128, ptr %.unpack513, i64 %33
  %35 = load i128, ptr %34, align 8, !tbaa !3
  %36 = add i128 %35, 1
  store i128 %36, ptr %34, align 8, !tbaa !3
  %37 = getelementptr i128, ptr %.unpack597, i64 %28
  %38 = load i128, ptr %37, align 8, !tbaa !3
  %39 = trunc i128 %38 to i64
  %40 = sub i64 %39, %.unpack592.unpack.unpack
  %41 = getelementptr i128, ptr %.unpack513, i64 %40
  %42 = load i128, ptr %41, align 8, !tbaa !3
  %43 = add i128 %42, 1
  store i128 %43, ptr %41, align 8, !tbaa !3
  %44 = add nuw i64 %28, 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 %27

._crit_edge.unr-lcssa.loopexit:                   ; preds = %27
  %45 = add i64 %28, 1
  br label %._crit_edge.unr-lcssa

._crit_edge.unr-lcssa:                            ; preds = %._crit_edge.unr-lcssa.loopexit, %.lr.ph630
  %.unr = phi i64 [ 0, %.lr.ph630 ], [ %45, %._crit_edge.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %46 = getelementptr i128, ptr %.unpack597, i64 %.unr
  %47 = load i128, ptr %46, align 8, !tbaa !3
  %48 = trunc i128 %47 to i64
  %49 = sub i64 %48, %.unpack592.unpack.unpack
  %50 = getelementptr i128, ptr %.unpack513, i64 %49
  %51 = load i128, ptr %50, align 8, !tbaa !3
  %52 = add i128 %51, 1
  store i128 %52, ptr %50, align 8, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.pre = load i128, ptr %2, align 8, !tbaa !3
  %.pre640 = trunc i128 %.pre to i64
  %53 = icmp sgt i64 %.pre640, 0
  br i1 %53, label %.lr.ph632, label %._crit_edge.._crit_edge633_crit_edge

._crit_edge.._crit_edge633_crit_edge:             ; preds = %.loopexit, %._crit_edge
  %.unpack525.pre = load ptr, ptr @_QFEmemo.0, align 8, !tbaa !7
  br label %._crit_edge633

.lr.ph632:                                        ; preds = %._crit_edge
  %.unpack568.unpack.unpack = load i64, ptr @_QFEcounter.7, align 8, !tbaa !7
  %.unpack573 = load ptr, ptr @_QFEmemo.0, align 8, !tbaa !7
  br label %54

54:                                               ; preds = %.lr.ph632, %54
  %55 = phi i64 [ 1, %.lr.ph632 ], [ %64, %54 ]
  %56 = sub i64 %55, %.unpack568.unpack.unpack
  %57 = getelementptr i128, ptr %.unpack513, i64 %56
  %58 = load i128, ptr %57, align 8, !tbaa !3
  %59 = add i128 %58, -1
  %60 = mul i128 %59, %58
  %61 = sdiv i128 %60, 2
  %62 = add i64 %55, -1
  %63 = getelementptr i128, ptr %.unpack573, i64 %62
  store i128 %61, ptr %63, align 8, !tbaa !3
  %64 = add nuw i64 %55, 1
  %exitcond636.not = icmp eq i64 %55, %.pre640
  br i1 %exitcond636.not, label %._crit_edge633, label %54

._crit_edge633:                                   ; preds = %54, %._crit_edge.._crit_edge633_crit_edge
  %.unpack525 = phi ptr [ %.unpack525.pre, %._crit_edge.._crit_edge633_crit_edge ], [ %.unpack573, %54 ]
  %.unpack532.unpack.unpack534 = load i64, ptr @_QFEmemo.8, align 8, !tbaa !7
  %65 = icmp sgt i64 %.unpack532.unpack.unpack534, 0
  br i1 %65, label %.lr.ph.i.preheader, label %_FortranASumInteger16x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge633
  %xtraiter642 = and i64 %.unpack532.unpack.unpack534, 3
  %66 = icmp ult i64 %.unpack532.unpack.unpack534, 4
  br i1 %66, 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_iter647 = and i64 %.unpack532.unpack.unpack534, -4
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i, %.lr.ph.i.preheader.new
  %67 = phi i128 [ 0, %.lr.ph.i.preheader.new ], [ %87, %.lr.ph.i ]
  %68 = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %88, %.lr.ph.i ]
  %niter648 = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %niter648.next.3, %.lr.ph.i ]
  %69 = shl i64 %68, 4
  %70 = getelementptr i8, ptr %.unpack525, i64 %69
  %71 = load i128, ptr %70, align 8, !tbaa !3
  %72 = add i128 %71, %67
  %73 = shl i64 %68, 4
  %74 = or i64 %73, 16
  %75 = getelementptr i8, ptr %.unpack525, i64 %74
  %76 = load i128, ptr %75, align 8, !tbaa !3
  %77 = add i128 %76, %72
  %78 = shl i64 %68, 4
  %79 = or i64 %78, 32
  %80 = getelementptr i8, ptr %.unpack525, i64 %79
  %81 = load i128, ptr %80, align 8, !tbaa !3
  %82 = add i128 %81, %77
  %83 = shl i64 %68, 4
  %84 = or i64 %83, 48
  %85 = getelementptr i8, ptr %.unpack525, i64 %84
  %86 = load i128, ptr %85, align 8, !tbaa !3
  %87 = add i128 %86, %82
  %88 = add nuw nsw i64 %68, 4
  %niter648.next.3 = add i64 %niter648, 4
  %niter648.ncmp.3 = icmp eq i64 %niter648.next.3, %unroll_iter647
  br i1 %niter648.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 ], [ %87, %.lr.ph.i ]
  %.unr643 = phi i128 [ 0, %.lr.ph.i.preheader ], [ %87, %.lr.ph.i ]
  %.unr644 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %88, %.lr.ph.i ]
  %lcmp.mod645.not = icmp eq i64 %xtraiter642, 0
  br i1 %lcmp.mod645.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
  %89 = phi i128 [ %94, %.lr.ph.i.epil ], [ %.unr643, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %90 = phi i64 [ %95, %.lr.ph.i.epil ], [ %.unr644, %_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 ]
  %91 = shl i64 %90, 4
  %92 = getelementptr i8, ptr %.unpack525, i64 %91
  %93 = load i128, ptr %92, align 8, !tbaa !3
  %94 = add i128 %93, %89
  %95 = add nuw nsw i64 %90, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter642
  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_edge633
  %.lcssa.i = phi i128 [ 0, %._crit_edge633 ], [ %.lcssa.ph, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ], [ %94, %.lr.ph.i.epil ]
  %96 = load i128, ptr %2, align 8, !tbaa !3
  %97 = trunc i128 %96 to i64
  %98 = icmp sgt i64 %97, 0
  br i1 %98, label %.lr.ph634, label %._crit_edge635

.lr.ph634:                                        ; preds = %_FortranASumInteger16x1_contract_simplified.exit, %.lr.ph634
  %99 = phi i64 [ %117, %.lr.ph634 ], [ 1, %_FortranASumInteger16x1_contract_simplified.exit ]
  %.unpack537 = load ptr, ptr @_QFEcounter.0, align 8, !tbaa !7
  %.unpack544.unpack.unpack = load i64, ptr @_QFEcounter.7, align 8, !tbaa !7
  %.unpack549 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %100 = add i64 %99, -1
  %101 = getelementptr i128, ptr %.unpack549, i64 %100
  %102 = load i128, ptr %101, align 8, !tbaa !3
  %103 = trunc i128 %102 to i64
  %104 = sub i64 %103, %.unpack544.unpack.unpack
  %105 = getelementptr i128, ptr %.unpack537, i64 %104
  %106 = load i128, ptr %105, align 8, !tbaa !3
  %107 = add i128 %106, -1
  %108 = mul i128 %107, %106
  %.neg = sdiv i128 %108, -2
  %109 = add i128 %.neg, %.lcssa.i
  %110 = add i128 %106, -2
  %111 = mul i128 %107, %110
  %112 = sdiv i128 %111, 2
  %113 = add i128 %109, %112
  %114 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.e66e18b59f8a24d0fae10c7a85f22fa4, i32 29)
  %115 = call i1 @_FortranAioOutputInteger128(ptr %114, i128 %113)
  %116 = call i32 @_FortranAioEndIoStatement(ptr %114)
  %117 = add nuw i64 %99, 1
  %exitcond637.not = icmp eq i64 %99, %97
  br i1 %exitcond637.not, label %._crit_edge635, label %.lr.ph634

._crit_edge635:                                   ; preds = %.lr.ph634, %_FortranASumInteger16x1_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 {} @_FortranAReportFatalUserError(ptr, ptr, i32) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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"}
