; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 29. Codeforces Problems/B_Omkar_and_Heavenly_Tree.ll (Z5SieveRSt6vectorIxSaIxEEx)

; 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 void @_Z5SieveRSt6vectorIxSaIxEEx(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = add nsw i64 %12, 1
  %14 = call ptr @llvm.stacksave.p0()
  store ptr %14, ptr %5, align 8
  %15 = alloca i8, i64 %13, align 16
  store i64 %13, ptr %6, align 8
  call void @llvm.memset.p0.i64(ptr align 16 %15, i8 1, i64 %13, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 2, ptr %7, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %47, %2
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = mul nsw i64 %17, %18
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = icmp sle i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %50

23:                                               ; preds = %16
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %15, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11, !range !13, !noundef !14
  %27 = trunc i8 %26 to i1
  %28 = zext i1 %27 to i32
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %46

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = mul nsw i64 %31, 2
  store i64 %32, ptr %9, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %41, %30
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = icmp sle i64 %34, %35
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %33
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %15, i64 %39
  store i8 0, ptr %40, align 1, !tbaa !11
  br label %41

41:                                               ; preds = %38
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = load i64, ptr %9, align 8, !tbaa !9
  %44 = add nsw i64 %43, %42
  store i64 %44, ptr %9, align 8, !tbaa !9
  br label %33, !llvm.loop !15

45:                                               ; preds = %37
  br label %46

46:                                               ; preds = %45, %23
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr %7, align 8, !tbaa !9
  br label %16, !llvm.loop !17

50:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 2, ptr %10, align 4, !tbaa !18
  br label %51

51:                                               ; preds = %68, %50
  %52 = load i32, ptr %10, align 4, !tbaa !18
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr %4, align 8, !tbaa !9
  %55 = icmp sle i64 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %51
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %71

57:                                               ; preds = %51
  %58 = load i32, ptr %10, align 4, !tbaa !18
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %15, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11, !range !13, !noundef !14
  %62 = trunc i8 %61 to i1
  br i1 %62, label %63, label %67

63:                                               ; preds = %57
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %65 = load i32, ptr %10, align 4, !tbaa !18
  %66 = sext i32 %65 to i64
  store i64 %66, ptr %11, align 8, !tbaa !9
  call void @_ZNSt6vectorIxSaIxEE9push_backEOx(ptr noundef nonnull align 8 dereferenceable(24) %64, ptr noundef nonnull align 8 dereferenceable(8) %11)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %67

67:                                               ; preds = %63, %57
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %10, align 4, !tbaa !18
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %10, align 4, !tbaa !18
  br label %51, !llvm.loop !20

71:                                               ; preds = %56
  %72 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %72)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

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 }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = distinct !{!20, !16}


; 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 void @_Z5SieveRSt6vectorIxSaIxEEx(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  %4 = add nsw i64 %1, 1
  %5 = alloca i8, i64 %4, align 16
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %5, i8 1, i64 %4, i1 false)
  %.not26 = icmp slt i64 %1, 4
  br i1 %.not26, label %.preheader, label %.lr.ph28

.preheader:                                       ; preds = %.loopexit, %2
  %.not2229 = icmp slt i64 %1, 2
  br i1 %.not2229, label %._crit_edge, label %.lr.ph31

.lr.ph28:                                         ; preds = %2, %.loopexit
  %.01927 = phi i64 [ %12, %.loopexit ], [ 2, %2 ]
  %6 = getelementptr inbounds i8, ptr %5, i64 %.01927
  %7 = load i8, ptr %6, align 1, !tbaa !5, !range !9, !noundef !10
  %8 = trunc nuw i8 %7 to i1
  %9 = shl nuw nsw i64 %.01927, 1
  %.not2324 = icmp sle i64 %9, %1
  %or.cond.not = select i1 %8, i1 %.not2324, i1 false
  br i1 %or.cond.not, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph28, %.lr.ph
  %.01825 = phi i64 [ %11, %.lr.ph ], [ %9, %.lr.ph28 ]
  %10 = getelementptr inbounds i8, ptr %5, i64 %.01825
  store i8 0, ptr %10, align 1, !tbaa !5
  %11 = add nuw nsw i64 %.01825, %.01927
  %.not23 = icmp sgt i64 %11, %1
  br i1 %.not23, label %.loopexit, label %.lr.ph, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph28
  %12 = add nuw nsw i64 %.01927, 1
  %13 = mul nuw nsw i64 %12, %12
  %.not = icmp sgt i64 %13, %1
  br i1 %.not, label %.preheader, label %.lr.ph28, !llvm.loop !13

._crit_edge:                                      ; preds = %18, %.preheader
  ret void

.lr.ph31:                                         ; preds = %.preheader, %18
  %indvars.iv = phi i64 [ %indvars.iv.next, %18 ], [ 2, %.preheader ]
  %14 = getelementptr inbounds i8, ptr %5, i64 %indvars.iv
  %15 = load i8, ptr %14, align 1, !tbaa !5, !range !9, !noundef !10
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %17, label %18

17:                                               ; preds = %.lr.ph31
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 %indvars.iv, ptr %3, align 8, !tbaa !14
  call void @_ZNSt6vectorIxSaIxEE9push_backEOx(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %18

18:                                               ; preds = %.lr.ph31, %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not22.not = icmp slt i64 %indvars.iv, %1
  br i1 %.not22.not, label %.lr.ph31, label %._crit_edge, !llvm.loop !16
}

; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE9push_backEOx(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) 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 nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"}
!13 = distinct !{!13, !12}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = distinct !{!16, !12}


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