; LLVM IR from Lakhankumawat/LearnCPP :: M-MathematicalAlgorithms/S-SegmentedSieve/SegmentedSieve.ll (Z10make_sievev)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z10make_sievev() #0 {
  %1 = alloca [100001 x i8], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 100001, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %17, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 100001
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i8], ptr %1, i64 0, i64 %15
  store i8 1, ptr %16, align 1, !tbaa !9
  br label %17

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

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

21:                                               ; preds = %51, %20
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = mul nsw i32 %22, %23
  %25 = icmp slt i32 %24, 100001
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %21
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100001 x i8], ptr %1, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !9, !range !13, !noundef !14
  %32 = trunc i8 %31 to i1
  br i1 %32, label %33, label %50

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = mul nsw i32 %34, %35
  store i32 %36, ptr %5, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %45, %33
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 100001
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %49

41:                                               ; preds = %37
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100001 x i8], ptr %1, i64 0, i64 %43
  store i8 0, ptr %44, align 1, !tbaa !9
  br label %45

45:                                               ; preds = %41
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %37, !llvm.loop !15

49:                                               ; preds = %40
  br label %50

50:                                               ; preds = %49, %27
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !16

54:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %55 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  call void @llvm.memset.p0.i64(ptr align 16 %55, i8 0, i64 24, i1 false)
  call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %55) #5
  store ptr %55, ptr %6, align 8, !tbaa !17
  %56 = load ptr, ptr %6, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 2, ptr %7, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) %56, ptr noundef nonnull align 4 dereferenceable(4) %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 3, ptr %8, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %70, %54
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = icmp slt i32 %58, 100001
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %73

61:                                               ; preds = %57
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100001 x i8], ptr %1, i64 0, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !9, !range !13, !noundef !14
  %66 = trunc i8 %65 to i1
  br i1 %66, label %67, label %69

67:                                               ; preds = %61
  %68 = load ptr, ptr %6, align 8, !tbaa !17
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %68, ptr noundef nonnull align 4 dereferenceable(4) %8)
  br label %69

69:                                               ; preds = %67, %61
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = add nsw i32 %71, 2
  store i32 %72, ptr %8, align 4, !tbaa !5
  br label %57, !llvm.loop !19

73:                                               ; preds = %60
  %74 = load ptr, ptr %6, align 8, !tbaa !17
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 100001, ptr %1) #5
  ret ptr %74
}

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #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: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

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 = { nobuiltin allocsize(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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = !{!18, !18, i64 0}
!18 = !{!"any pointer", !7, i64 0}
!19 = distinct !{!19, !12}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_Z10make_sievev() local_unnamed_addr #0 {
.preheader19.preheader:
  %0 = alloca [100001 x i8], align 16
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 100001, ptr nonnull %0) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100001) %0, i8 1, i64 100001, i1 false), !tbaa !5
  br label %.preheader19

3:                                                ; preds = %.loopexit
  %4 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #6
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %4, i8 0, i64 24, i1 false)
  tail call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  store i32 2, ptr %1, align 4, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 3, ptr %2, align 4, !tbaa !9
  br label %23

.preheader19:                                     ; preds = %.loopexit.1, %.preheader19.preheader
  %indvars.iv = phi i64 [ 2, %.preheader19.preheader ], [ %indvars.iv.next.1, %.loopexit.1 ]
  %5 = phi i32 [ 4, %.preheader19.preheader ], [ %21, %.loopexit.1 ]
  %6 = getelementptr inbounds [100001 x i8], ptr %0, i64 0, i64 %indvars.iv
  %7 = load i8, ptr %6, align 2, !tbaa !5, !range !11, !noundef !12
  %8 = trunc nuw i8 %7 to i1
  %9 = icmp ult i32 %5, 100001
  %or.cond = and i1 %9, %8
  br i1 %or.cond, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader19
  %10 = zext nneg i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv25 = phi i64 [ %10, %.lr.ph.preheader ], [ %indvars.iv.next26, %.lr.ph ]
  %11 = getelementptr inbounds [100001 x i8], ptr %0, i64 0, i64 %indvars.iv25
  store i8 0, ptr %11, align 1, !tbaa !5
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, %indvars.iv
  %12 = icmp ult i64 %indvars.iv.next26, 100001
  br i1 %12, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %.preheader19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %13 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %exitcond.not = icmp eq i64 %indvars.iv, 316
  br i1 %exitcond.not, label %3, label %.preheader19.1, !llvm.loop !15

.preheader19.1:                                   ; preds = %.loopexit
  %14 = getelementptr inbounds [100001 x i8], ptr %0, i64 0, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !5, !range !11, !noundef !12
  %16 = trunc nuw i8 %15 to i1
  %17 = icmp ult i64 %13, 100001
  %or.cond.1 = and i1 %17, %16
  br i1 %or.cond.1, label %.lr.ph.1, label %.loopexit.1

.lr.ph.1:                                         ; preds = %.preheader19.1, %.lr.ph.1
  %indvars.iv25.1 = phi i64 [ %indvars.iv.next26.1, %.lr.ph.1 ], [ %13, %.preheader19.1 ]
  %18 = getelementptr inbounds [100001 x i8], ptr %0, i64 0, i64 %indvars.iv25.1
  store i8 0, ptr %18, align 1, !tbaa !5
  %indvars.iv.next26.1 = add nuw nsw i64 %indvars.iv25.1, %indvars.iv.next
  %19 = icmp ult i64 %indvars.iv.next26.1, 100001
  br i1 %19, label %.lr.ph.1, label %.loopexit.1, !llvm.loop !13

.loopexit.1:                                      ; preds = %.lr.ph.1, %.preheader19.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %20 = mul nuw nsw i64 %indvars.iv.next.1, %indvars.iv.next.1
  %21 = trunc nuw i64 %20 to i32
  br label %.preheader19

22:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 100001, ptr nonnull %0) #5
  ret ptr %4

23:                                               ; preds = %3, %29
  %storemerge23 = phi i32 [ 3, %3 ], [ %31, %29 ]
  %24 = sext i32 %storemerge23 to i64
  %25 = getelementptr inbounds [100001 x i8], ptr %0, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !5, !range !11, !noundef !12
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %.pre = load i32, ptr %2, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %23, %28
  %30 = phi i32 [ %storemerge23, %23 ], [ %.pre, %28 ]
  %31 = add nsw i32 %30, 2
  store i32 %31, ptr %2, align 4, !tbaa !9
  %32 = icmp slt i32 %30, 99999
  br i1 %32, label %23, label %22, !llvm.loop !16
}

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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin allocsize(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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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 = !{!10, !10, i64 0}
!10 = !{!"int", !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}


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