; LLVM IR from MinhasKamal/AlgorithmImplementations :: playWithNumbers/primeNumber (PrimeNumber)

; 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"

@ara = external dso_local global [100000000 x i32], align 16

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

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

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

4:                                                ; preds = %11, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 100000000
  br i1 %6, label %7, label %14

7:                                                ; preds = %4
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %9
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %7
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !9

14:                                               ; preds = %4
  %15 = call double @sqrt(double noundef 1.000000e+08) #3
  %16 = fptosi double %15 to i32
  store i32 %16, ptr %3, align 4, !tbaa !5
  store i32 2, ptr %1, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %44, %14
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %47

21:                                               ; preds = %17
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %43

27:                                               ; preds = %21
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %39, %27
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = mul nsw i32 %29, %30
  %32 = icmp sle i32 %31, 100000000
  br i1 %32, label %33, label %42

33:                                               ; preds = %28
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = mul nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %37
  store i32 0, ptr %38, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %33
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %28, !llvm.loop !11

42:                                               ; preds = %28
  br label %43

43:                                               ; preds = %42, %21
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %1, align 4, !tbaa !5
  br label %17, !llvm.loop !12

47:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind 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 #2 = { nounwind "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 #3 = { 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/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"

@ara = external dso_local local_unnamed_addr global [100000000 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @sieve() local_unnamed_addr #0 {
vector.ph:
  br label %vector.body

vector.body:                                      ; preds = %vector.body.3, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.3, %vector.body.3 ]
  %offset.idx = or disjoint i64 %index, 2
  %0 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %offset.idx
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %0, align 8, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %1, align 8, !tbaa !5
  %offset.idx.1 = or disjoint i64 %index, 10
  %2 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %offset.idx.1
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %2, align 8, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %3, align 8, !tbaa !5
  %offset.idx.2 = or disjoint i64 %index, 18
  %4 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %offset.idx.2
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %4, align 8, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %5, align 8, !tbaa !5
  %6 = icmp eq i64 %index, 99999968
  br i1 %6, label %scalar.ph, label %vector.body.3, !llvm.loop !9

vector.body.3:                                    ; preds = %vector.body
  %offset.idx.3 = or disjoint i64 %index, 26
  %7 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %offset.idx.3
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %7, align 8, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %8, align 8, !tbaa !5
  %index.next.3 = add nuw nsw i64 %index, 32
  br label %vector.body

scalar.ph:                                        ; preds = %vector.body
  store i32 1, ptr getelementptr inbounds (i8, ptr @ara, i64 399999976), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @ara, i64 399999980), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @ara, i64 399999984), align 16, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @ara, i64 399999988), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @ara, i64 399999992), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @ara, i64 399999996), align 4, !tbaa !5
  br label %.preheader14

.preheader14:                                     ; preds = %scalar.ph, %.loopexit
  %indvars.iv23 = phi i64 [ %indvars.iv.next24, %.loopexit ], [ 2, %scalar.ph ]
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %.loopexit ], [ 4, %scalar.ph ]
  %9 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %indvars.iv23
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader14, %.lr.ph
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.lr.ph ], [ 2, %.preheader14 ]
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %.lr.ph ], [ %indvars.iv21, %.preheader14 ]
  %12 = getelementptr inbounds [100000000 x i32], ptr @ara, i64 0, i64 %indvars.iv25
  store i32 0, ptr %12, align 4, !tbaa !5
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %13 = mul nuw nsw i64 %indvars.iv.next28, %indvars.iv23
  %14 = icmp ult i64 %13, 100000001
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, %indvars.iv23
  br i1 %14, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %.preheader14
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 2
  %exitcond33.not = icmp eq i64 %indvars.iv.next24, 10001
  br i1 %exitcond33.not, label %15, label %.preheader14, !llvm.loop !14

15:                                               ; preds = %.loopexit
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass