; LLVM IR from Dev-XYS/Algorithms :: Sieve-of-Eratosthenes (main)

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

@isprime = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.memset.p0.i64(ptr align 16 @isprime, i8 1, i64 101, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %38, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = mul nsw i32 %7, %8
  %10 = icmp sle i32 %9, 100
  br i1 %10, label %12, label %11

11:                                               ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %41

12:                                               ; preds = %6
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [101 x i8], ptr @isprime, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  %18 = zext i1 %17 to i32
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %37

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = mul nsw i32 %21, %22
  store i32 %23, ptr %4, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %32, %20
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp sle i32 %25, 100
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %24
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [101 x i8], ptr @isprime, i64 0, i64 %30
  store i8 0, ptr %31, align 1, !tbaa !9
  br label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = add nsw i32 %34, %33
  store i32 %35, ptr %4, align 4, !tbaa !5
  br label %24, !llvm.loop !13

36:                                               ; preds = %27
  br label %37

37:                                               ; preds = %36, %12
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !15

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

42:                                               ; preds = %58, %41
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = icmp slt i32 %43, 100
  br i1 %44, label %46, label %45

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

46:                                               ; preds = %42
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [101 x i8], ptr @isprime, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !9, !range !11, !noundef !12
  %51 = trunc i8 %50 to i1
  %52 = zext i1 %51 to i32
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %57

54:                                               ; preds = %46
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %55)
  br label %57

57:                                               ; preds = %54, %46
  br label %58

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

61:                                               ; preds = %45
  ret i32 0
}

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

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

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

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { mustprogress norecurse 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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@isprime = external dso_local local_unnamed_addr global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.loopexit.8:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(101) @isprime, i8 1, i64 101, i1 false)
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 4), align 4, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 6), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 8), align 8, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 10), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 14), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 16), align 16, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 20), align 4, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 22), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 9), align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 12), align 4, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 15), align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 18), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 21), align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 42), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 72), align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(5) getelementptr inbounds (i8, ptr @isprime, i64 24), i8 0, i64 5, i1 false)
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 30), align 2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(5) getelementptr inbounds (i8, ptr @isprime, i64 32), i8 0, i64 5, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(3) getelementptr inbounds (i8, ptr @isprime, i64 38), i8 0, i64 3, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(3) getelementptr inbounds (i8, ptr @isprime, i64 44), i8 0, i64 3, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(5) getelementptr inbounds (i8, ptr @isprime, i64 48), i8 0, i64 5, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(5) getelementptr inbounds (i8, ptr @isprime, i64 54), i8 0, i64 5, i1 false)
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 60), align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(5) getelementptr inbounds (i8, ptr @isprime, i64 62), i8 0, i64 5, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(3) getelementptr inbounds (i8, ptr @isprime, i64 68), i8 0, i64 3, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(5) getelementptr inbounds (i8, ptr @isprime, i64 74), i8 0, i64 5, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(3) getelementptr inbounds (i8, ptr @isprime, i64 80), i8 0, i64 3, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(5) getelementptr inbounds (i8, ptr @isprime, i64 84), i8 0, i64 5, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(7) getelementptr inbounds (i8, ptr @isprime, i64 90), i8 0, i64 7, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(3) getelementptr inbounds (i8, ptr @isprime, i64 98), i8 0, i64 3, i1 false)
  br label %.preheader

0:                                                ; preds = %7
  ret i32 0

.preheader:                                       ; preds = %.loopexit.8, %7
  %indvars.iv = phi i64 [ 2, %.loopexit.8 ], [ %indvars.iv.next, %7 ]
  %1 = getelementptr inbounds [101 x i8], ptr @isprime, i64 0, i64 %indvars.iv
  %2 = load i8, ptr %1, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %4, label %7

4:                                                ; preds = %.preheader
  %5 = trunc nuw nsw i64 %indvars.iv to i32
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %5)
  br label %7

7:                                                ; preds = %.preheader, %4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond.not, label %0, label %.preheader, !llvm.loop !11
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { mustprogress nofree norecurse 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nofree 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" }

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass