; LLVM IR from ShahjalalShohag/code-library :: Number Theory/K Divisors.ll (ZN3pcf4initEv)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@_ZN3pcf6primesE = external dso_local global [1000010 x i32], align 16
@_ZN3pcf2dpE = external dso_local global [100000 x [100 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3pcf5sieveEi(i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3pcf4initEv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @_ZN3pcf5sieveEi(i32 noundef 10000009)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %15, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 100000
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %18

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %12
  %14 = getelementptr inbounds [100 x i32], ptr %13, i64 0, i64 0
  store i32 %10, ptr %14, align 16, !tbaa !5
  br label %15

15:                                               ; preds = %9
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !9

18:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %62, %18
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = icmp slt i32 %20, 100
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %65

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %58, %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 100000
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %61

28:                                               ; preds = %24
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %30
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100 x i32], ptr %31, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sdiv i32 %37, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x i32], ptr %45, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sub nsw i32 %36, %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100 x i32], ptr %54, i64 0, i64 %56
  store i32 %51, ptr %57, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %28
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !5
  br label %24, !llvm.loop !11

61:                                               ; preds = %27
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %19, !llvm.loop !12

65:                                               ; preds = %22
  ret void
}

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@_ZN3pcf6primesE = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@_ZN3pcf2dpE = external dso_local local_unnamed_addr global [100000 x [100 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3pcf5sieveEi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3pcf4initEv() local_unnamed_addr #0 {
  tail call void @_ZN3pcf5sieveEi(i32 noundef 10000009)
  br label %1

1:                                                ; preds = %1, %0
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next.4, %1 ]
  %2 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %indvars.iv
  %3 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %3, ptr %2, align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %4 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %indvars.iv.next
  %5 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %5, ptr %4, align 16, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %6 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %indvars.iv.next.1
  %7 = trunc nuw nsw i64 %indvars.iv.next.1 to i32
  store i32 %7, ptr %6, align 16, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %8 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %indvars.iv.next.2
  %9 = trunc nuw nsw i64 %indvars.iv.next.2 to i32
  store i32 %9, ptr %8, align 16, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %10 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %indvars.iv.next.3
  %11 = trunc nuw nsw i64 %indvars.iv.next.3 to i32
  store i32 %11, ptr %10, align 16, !tbaa !5
  %indvars.iv.next.4 = add nuw nsw i64 %indvars.iv, 5
  %exitcond.not.4 = icmp eq i64 %indvars.iv.next.4, 100000
  br i1 %exitcond.not.4, label %.preheader, label %1, !llvm.loop !9

.preheader:                                       ; preds = %1, %16
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %16 ], [ 1, %1 ]
  %12 = add nsw i64 %indvars.iv26, -1
  %13 = getelementptr inbounds [1000010 x i32], ptr @_ZN3pcf6primesE, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  br label %17

15:                                               ; preds = %16
  ret void

16:                                               ; preds = %17
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next27, 100
  br i1 %exitcond29.not, label %15, label %.preheader, !llvm.loop !11

17:                                               ; preds = %.preheader, %17
  %indvars.iv22 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next23, %17 ]
  %18 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %indvars.iv22, i64 %12
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = trunc nuw nsw i64 %indvars.iv22 to i32
  %21 = sdiv i32 %20, %14
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %22, i64 %12
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sub nsw i32 %19, %24
  %26 = getelementptr inbounds [100000 x [100 x i32]], ptr @_ZN3pcf2dpE, i64 0, i64 %indvars.iv22, i64 %indvars.iv26
  store i32 %25, ptr %26, align 4, !tbaa !5
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %exitcond25.not = icmp eq i64 %indvars.iv.next23, 100000
  br i1 %exitcond25.not, label %16, label %17, !llvm.loop !12
}

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass