program sample
    implicit none
  
    integer(8) :: i,j,m,n,b
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n
    allocate(a(n),y(n))
    read(*,*)a
    y(:)=0
    do i=1,n
        b=a(i)
        y(b)=y(b)+1
    end do
    m=0
    do i=1,n
        b=y(i)
        m=m+b*(b-1)/2
       
    end do
    do i=1,n
        b=a(i)
        if(y(b)<2)then
            write(*,*)m
        else
            write(*,*)m-y(b)+1
        end if
    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
@_QFEy.0 = internal unnamed_addr global ptr null
@_QFEy.8 = internal unnamed_addr global i64 0
@_QQcl.a6855023e70bb1775a3f59e30777d1ac = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2062/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 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.a6855023e70bb1775a3f59e30777d1ac, i32 7)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i64, ptr %2, align 8, !tbaa !3
  %7 = call i64 @llvm.smax.i64(i64 %6, i64 0)
  %8 = shl i64 %7, 3
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %7, ptr @_QFEa.8, align 8, !tbaa !7
  %10 = call ptr @malloc(i64 %8)
  store ptr %10, ptr @_QFEy.0, align 8, !tbaa !7
  store i64 %7, ptr @_QFEy.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.a6855023e70bb1775a3f59e30777d1ac, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack328.unpack.unpack330 = 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 %.unpack328.unpack.unpack330, 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)
  %.unpack333 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %.unpack340.unpack.unpack342 = load i64, ptr @_QFEy.8, align 8, !tbaa !7
  %.not = icmp slt i64 %.unpack340.unpack.unpack342, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %14 = shl nuw i64 %.unpack340.unpack.unpack342, 3
  call void @llvm.memset.p0.i64(ptr align 8 %.unpack333, i8 0, i64 %14, i1 false), !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %0
  %15 = load i64, ptr %2, align 8, !tbaa !3
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %.lr.ph418, label %._crit_edge424

.lr.ph418:                                        ; preds = %._crit_edge
  %.unpack393 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter = and i64 %15, 1
  %17 = icmp eq i64 %15, 1
  br i1 %17, label %._crit_edge419.unr-lcssa, label %.lr.ph418.new

.lr.ph418.new:                                    ; preds = %.lr.ph418
  %unroll_iter = and i64 %15, -2
  br label %18

18:                                               ; preds = %18, %.lr.ph418.new
  %19 = phi i64 [ 1, %.lr.ph418.new ], [ %33, %18 ]
  %niter = phi i64 [ 0, %.lr.ph418.new ], [ %niter.next.1, %18 ]
  %20 = add nsw i64 %19, -1
  %21 = getelementptr i64, ptr %.unpack393, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !3
  %23 = add i64 %22, -1
  %24 = getelementptr i64, ptr %.unpack333, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !3
  %26 = add i64 %25, 1
  store i64 %26, ptr %24, align 8, !tbaa !3
  %27 = getelementptr i64, ptr %.unpack393, i64 %19
  %28 = load i64, ptr %27, align 8, !tbaa !3
  %29 = add i64 %28, -1
  %30 = getelementptr i64, ptr %.unpack333, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !3
  %32 = add i64 %31, 1
  store i64 %32, ptr %30, align 8, !tbaa !3
  %33 = add nuw i64 %19, 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_edge419.unr-lcssa.loopexit, label %18

._crit_edge419.unr-lcssa.loopexit:                ; preds = %18
  %34 = add i64 %19, 1
  br label %._crit_edge419.unr-lcssa

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

._crit_edge419.epilog-lcssa:                      ; preds = %._crit_edge419.unr-lcssa
  %35 = getelementptr i64, ptr %.unpack393, i64 %.unr
  %36 = load i64, ptr %35, align 8, !tbaa !3
  %37 = add i64 %36, -1
  %38 = getelementptr i64, ptr %.unpack333, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !3
  %40 = add i64 %39, 1
  store i64 %40, ptr %38, align 8, !tbaa !3
  br label %._crit_edge419

._crit_edge419:                                   ; preds = %._crit_edge419.unr-lcssa, %._crit_edge419.epilog-lcssa
  %.pre = load i64, ptr %2, align 8, !tbaa !3
  %41 = icmp sgt i64 %.pre, 0
  br i1 %41, label %.lr.ph422, label %._crit_edge424

.lr.ph422:                                        ; preds = %._crit_edge419
  %min.iters.check = icmp ult i64 %.pre, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph422
  %n.vec = and i64 %.pre, -4
  %ind.end = or i64 %n.vec, 1
  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 ], [ %50, %vector.body ]
  %vec.phi429 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %51, %vector.body ]
  %42 = getelementptr i64, ptr %.unpack333, i64 %index
  %wide.load = load <2 x i64>, ptr %42, align 8, !tbaa !3
  %43 = getelementptr i64, ptr %42, i64 2
  %wide.load430 = load <2 x i64>, ptr %43, align 8, !tbaa !3
  %44 = add <2 x i64> %wide.load, <i64 -1, i64 -1>
  %45 = add <2 x i64> %wide.load430, <i64 -1, i64 -1>
  %46 = mul <2 x i64> %44, %wide.load
  %47 = mul <2 x i64> %45, %wide.load430
  %48 = sdiv <2 x i64> %46, <i64 2, i64 2>
  %49 = sdiv <2 x i64> %47, <i64 2, i64 2>
  %50 = add <2 x i64> %48, %vec.phi
  %51 = add <2 x i64> %49, %vec.phi429
  %index.next = add nuw i64 %index, 4
  %52 = icmp eq i64 %index.next, %n.vec
  br i1 %52, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %51, %50
  %53 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %.pre, %n.vec
  br i1 %cmp.n, label %.preheader, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph422, %middle.block
  %.ph = phi i64 [ 1, %.lr.ph422 ], [ %ind.end, %middle.block ]
  %.0420.ph = phi i64 [ 0, %.lr.ph422 ], [ %53, %middle.block ]
  br label %scalar.ph

.preheader:                                       ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i64 [ %53, %middle.block ], [ %62, %scalar.ph ]
  br i1 %41, label %.lr.ph423, label %._crit_edge424

.lr.ph423:                                        ; preds = %.preheader
  %54 = add i64 %.lcssa, 1
  br label %64

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %55 = phi i64 [ %63, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %.0420 = phi i64 [ %62, %scalar.ph ], [ %.0420.ph, %scalar.ph.preheader ]
  %56 = add i64 %55, -1
  %57 = getelementptr i64, ptr %.unpack333, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !3
  %59 = add i64 %58, -1
  %60 = mul i64 %59, %58
  %61 = sdiv i64 %60, 2
  %62 = add i64 %61, %.0420
  %63 = add nuw i64 %55, 1
  %exitcond425.not = icmp eq i64 %55, %.pre
  br i1 %exitcond425.not, label %.preheader, label %scalar.ph, !llvm.loop !12

64:                                               ; preds = %.lr.ph423, %83
  %65 = phi i64 [ 1, %.lr.ph423 ], [ %85, %83 ]
  %.unpack345 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %66 = add i64 %65, -1
  %67 = getelementptr i64, ptr %.unpack345, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !3
  %.unpack357 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %69 = add i64 %68, -1
  %70 = getelementptr i64, ptr %.unpack357, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !3
  %72 = icmp slt i64 %71, 2
  br i1 %72, label %73, label %76

73:                                               ; preds = %64
  %74 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.a6855023e70bb1775a3f59e30777d1ac, i32 24)
  %75 = call i1 @_FortranAioOutputInteger64(ptr %74, i64 %.lcssa)
  br label %83

76:                                               ; preds = %64
  %77 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.a6855023e70bb1775a3f59e30777d1ac, i32 26)
  %.unpack369 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %78 = add i64 %68, -1
  %79 = getelementptr i64, ptr %.unpack369, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !3
  %81 = sub i64 %54, %80
  %82 = call i1 @_FortranAioOutputInteger64(ptr %77, i64 %81)
  br label %83

83:                                               ; preds = %73, %76
  %.sink = phi ptr [ %74, %73 ], [ %77, %76 ]
  %84 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  %85 = add nuw i64 %65, 1
  %exitcond426.not = icmp eq i64 %65, %.pre
  br i1 %exitcond426.not, label %._crit_edge424, label %64

._crit_edge424:                                   ; preds = %83, %._crit_edge419, %._crit_edge, %.preheader
  %86 = 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}
