program main
  implicit none

  integer :: n, i, j, s
  integer, allocatable :: a(:), b(:)

  read *, n
  allocate(a(2:n), b(n))
  read *, a
  b = 0

  do i = 2, n
     b(a(i)) = b(a(i)) + 1
  end do

  do i = 1, n
     print *, b(i)
  end do
  
  stop
end program main

; 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.7 = internal unnamed_addr global i64 1
@_QFEa.8 = internal unnamed_addr global i64 0
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEb.7 = internal unnamed_addr global i64 1
@_QFEb.8 = internal unnamed_addr global i64 0
@_QQcl.07bac5d899a1555f2b4933a252153605 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1714/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

; 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 i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.07bac5d899a1555f2b4933a252153605, i32 7)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 1)
  %8 = zext i32 %7 to i64
  %9 = add nsw i64 %8, -1
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  %12 = icmp eq i64 %9, 0
  %13 = select i1 %12, i64 1, i64 2
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %13, ptr @_QFEa.7, align 8, !tbaa !7
  store i64 %9, ptr @_QFEa.8, align 8, !tbaa !7
  %14 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %15 = zext i32 %14 to i64
  %16 = shl nuw nsw i64 %15, 2
  %17 = call ptr @malloc(i64 %16)
  store ptr %17, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEb.7, align 8, !tbaa !7
  store i64 %15, ptr @_QFEb.8, align 8, !tbaa !7
  %18 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.07bac5d899a1555f2b4933a252153605, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack307.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !7
  %.unpack307.unpack.unpack309 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %19 = icmp eq i64 %.unpack307.unpack.unpack309, 0
  %20 = select i1 %19, i64 1, i64 %.unpack307.unpack.unpack
  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 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 %20, 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 %.unpack307.unpack.unpack309, 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
  %21 = call i1 @_FortranAioInputDescriptor(ptr %18, ptr nonnull %1)
  %22 = call i32 @_FortranAioEndIoStatement(ptr %18)
  %.unpack312 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack319.unpack.unpack321 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  %.not = icmp eq ptr %.unpack312, null
  br i1 %.not, label %25, label %.preheader

.preheader:                                       ; preds = %0
  %23 = icmp sgt i64 %.unpack319.unpack.unpack321, 0
  br i1 %23, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %24 = shl nuw i64 %.unpack319.unpack.unpack321, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 4 %.unpack312, i8 0, i64 %24, i1 false), !tbaa !3
  br label %.loopexit

25:                                               ; preds = %0
  %26 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.07bac5d899a1555f2b4933a252153605, i32 10)
  %.unpack367.unpack.unpack = load i64, ptr @_QFEb.7, align 8, !tbaa !7
  %27 = icmp eq i64 %.unpack319.unpack.unpack321, 0
  %28 = select i1 %27, i64 1, i64 %.unpack367.unpack.unpack
  store ptr null, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 %28, ptr @_QFEb.7, align 8, !tbaa !7
  store i64 %.unpack319.unpack.unpack321, ptr @_QFEb.8, align 8, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %.preheader, %25
  %29 = load i32, ptr %2, align 4, !tbaa !3
  %30 = icmp sgt i32 %29, 1
  br i1 %30, label %.lr.ph381, label %._crit_edge

.lr.ph381:                                        ; preds = %.loopexit
  %31 = zext i32 %29 to i64
  %.unpack343.unpack.unpack = load i64, ptr @_QFEb.7, align 8, !tbaa !7
  %.unpack348 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack355.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !7
  %32 = add nsw i64 %31, -1
  %xtraiter = and i64 %32, 1
  %33 = icmp eq i32 %29, 2
  br i1 %33, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph381.new

.lr.ph381.new:                                    ; preds = %.lr.ph381
  %unroll_iter = and i64 %32, -2
  br label %34

34:                                               ; preds = %34, %.lr.ph381.new
  %indvars.iv = phi i64 [ 2, %.lr.ph381.new ], [ %indvars.iv.next.1, %34 ]
  %niter = phi i64 [ 0, %.lr.ph381.new ], [ %niter.next.1, %34 ]
  %35 = sub i64 %indvars.iv, %.unpack355.unpack.unpack
  %36 = getelementptr i32, ptr %.unpack348, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !3
  %38 = sext i32 %37 to i64
  %39 = sub i64 %38, %.unpack343.unpack.unpack
  %40 = getelementptr i32, ptr %.unpack312, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !3
  %42 = add i32 %41, 1
  store i32 %42, ptr %40, align 4, !tbaa !3
  %indvars.iv.next = or i64 %indvars.iv, 1
  %43 = sub i64 %indvars.iv.next, %.unpack355.unpack.unpack
  %44 = getelementptr i32, ptr %.unpack348, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !3
  %46 = sext i32 %45 to i64
  %47 = sub i64 %46, %.unpack343.unpack.unpack
  %48 = getelementptr i32, ptr %.unpack312, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !3
  %50 = add i32 %49, 1
  store i32 %50, ptr %48, align 4, !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.loopexit.unr-lcssa, label %34

._crit_edge.loopexit.unr-lcssa:                   ; preds = %34, %.lr.ph381
  %indvars.iv.unr = phi i64 [ 2, %.lr.ph381 ], [ %indvars.iv.next.1, %34 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %51 = sub i64 %indvars.iv.unr, %.unpack355.unpack.unpack
  %52 = getelementptr i32, ptr %.unpack348, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !3
  %54 = sext i32 %53 to i64
  %55 = sub i64 %54, %.unpack343.unpack.unpack
  %56 = getelementptr i32, ptr %.unpack312, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !3
  %58 = add i32 %57, 1
  store i32 %58, ptr %56, align 4, !tbaa !3
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %._crit_edge.loopexit.epilog-lcssa
  %.pre = load i32, ptr %2, align 4, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.loopexit
  %59 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %29, %.loopexit ]
  %60 = icmp sgt i32 %59, 0
  br i1 %60, label %.lr.ph383.preheader, label %._crit_edge384

.lr.ph383.preheader:                              ; preds = %._crit_edge
  %61 = zext i32 %59 to i64
  br label %.lr.ph383

.lr.ph383:                                        ; preds = %.lr.ph383.preheader, %.lr.ph383
  %indvars.iv386 = phi i64 [ 1, %.lr.ph383.preheader ], [ %indvars.iv.next387, %.lr.ph383 ]
  %62 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.07bac5d899a1555f2b4933a252153605, i32 17)
  %.unpack324 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack331.unpack.unpack = load i64, ptr @_QFEb.7, align 8, !tbaa !7
  %63 = sub i64 %indvars.iv386, %.unpack331.unpack.unpack
  %64 = getelementptr i32, ptr %.unpack324, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !3
  %66 = call i1 @_FortranAioOutputInteger32(ptr %62, i32 %65)
  %67 = call i32 @_FortranAioEndIoStatement(ptr %62)
  %indvars.iv.next387 = add nuw nsw i64 %indvars.iv386, 1
  %exitcond389.not = icmp eq i64 %indvars.iv386, %61
  br i1 %exitcond389.not, label %._crit_edge384, label %.lr.ph383

._crit_edge384:                                   ; preds = %.lr.ph383, %._crit_edge
  %68 = 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 {} @_FortranAReportFatalUserError(ptr, ptr, i32) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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) }

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