; LLVM IR from devparthgarg/Data-Structures-and-Algorithms :: 02. Mathematics/08 Prime Factors/08c.ll (Z12primeFactorsi)

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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12primeFactorsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = icmp sle i32 %4, 1
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  br label %74

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %12, %7
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = srem i32 %9, 2
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %8
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef 2)
  %14 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef @.str)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sdiv i32 %15, 2
  store i32 %16, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

17:                                               ; preds = %8
  br label %18

18:                                               ; preds = %22, %17
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = srem i32 %19, 3
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %18
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef 3)
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef @.str)
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sdiv i32 %25, 3
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %18, !llvm.loop !11

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

28:                                               ; preds = %65, %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = mul nsw i32 %29, %30
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %68

35:                                               ; preds = %28
  br label %36

36:                                               ; preds = %41, %35
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = srem i32 %37, %38
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %48

41:                                               ; preds = %36
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %42)
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %43, ptr noundef @.str)
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sdiv i32 %45, %46
  store i32 %47, ptr %2, align 4, !tbaa !5
  br label %36, !llvm.loop !12

48:                                               ; preds = %36
  br label %49

49:                                               ; preds = %55, %48
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %51, 2
  %53 = srem i32 %50, %52
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %64

55:                                               ; preds = %49
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = add nsw i32 %56, 2
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %57)
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %58, ptr noundef @.str)
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 2
  %63 = sdiv i32 %60, %62
  store i32 %63, ptr %2, align 4, !tbaa !5
  br label %49, !llvm.loop !13

64:                                               ; preds = %49
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = add nsw i32 %66, 6
  store i32 %67, ptr %3, align 4, !tbaa !5
  br label %28, !llvm.loop !14

68:                                               ; preds = %34
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = icmp sgt i32 %69, 1
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %72)
  br label %74

74:                                               ; preds = %71, %68, %6
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #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

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 = { inlinehint 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 #2 = { "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 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 = !{!"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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12primeFactorsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 2
  br i1 %2, label %37, label %.preheader26

.preheader26:                                     ; preds = %1
  %3 = and i32 %0, 1
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.lr.ph, label %.preheader25

.preheader25:                                     ; preds = %.lr.ph, %.preheader26
  %.021.lcssa = phi i32 [ %0, %.preheader26 ], [ %9, %.lr.ph ]
  %5 = urem i32 %.021.lcssa, 3
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %.lr.ph29, label %.preheader24

.lr.ph:                                           ; preds = %.preheader26, %.lr.ph
  %.02127 = phi i32 [ %9, %.lr.ph ], [ %0, %.preheader26 ]
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef 2)
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull @.str)
  %9 = lshr exact i32 %.02127, 1
  %10 = and i32 %.02127, 2
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.lr.ph, label %.preheader25, !llvm.loop !5

.preheader24:                                     ; preds = %.lr.ph29, %.preheader25
  %.1.lcssa = phi i32 [ %.021.lcssa, %.preheader25 ], [ %14, %.lr.ph29 ]
  %.not37 = icmp ult i32 %.1.lcssa, 25
  br i1 %.not37, label %._crit_edge40, label %.preheader23

.lr.ph29:                                         ; preds = %.preheader25, %.lr.ph29
  %.128 = phi i32 [ %14, %.lr.ph29 ], [ %.021.lcssa, %.preheader25 ]
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef 3)
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull @.str)
  %14 = udiv i32 %.128, 3
  %15 = urem i32 %14, 3
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.lr.ph29, label %.preheader24, !llvm.loop !7

.preheader23:                                     ; preds = %.preheader24, %._crit_edge
  %.039 = phi i32 [ %33, %._crit_edge ], [ 5, %.preheader24 ]
  %.238 = phi i32 [ %.4.lcssa, %._crit_edge ], [ %.1.lcssa, %.preheader24 ]
  %17 = srem i32 %.238, %.039
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %.lr.ph32, label %.preheader

._crit_edge40:                                    ; preds = %._crit_edge, %.preheader24
  %.2.lcssa = phi i32 [ %.1.lcssa, %.preheader24 ], [ %.4.lcssa, %._crit_edge ]
  %19 = icmp sgt i32 %.2.lcssa, 1
  br i1 %19, label %35, label %37

.preheader:                                       ; preds = %.lr.ph32, %.preheader23
  %.3.lcssa = phi i32 [ %.238, %.preheader23 ], [ %25, %.lr.ph32 ]
  %20 = add nuw nsw i32 %.039, 2
  %21 = srem i32 %.3.lcssa, %20
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.lr.ph35, label %._crit_edge

.lr.ph32:                                         ; preds = %.preheader23, %.lr.ph32
  %.331 = phi i32 [ %25, %.lr.ph32 ], [ %.238, %.preheader23 ]
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.039)
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef nonnull @.str)
  %25 = sdiv i32 %.331, %.039
  %26 = srem i32 %25, %.039
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %.lr.ph32, label %.preheader, !llvm.loop !8

.lr.ph35:                                         ; preds = %.preheader, %.lr.ph35
  %.434 = phi i32 [ %30, %.lr.ph35 ], [ %.3.lcssa, %.preheader ]
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %20)
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %28, ptr noundef nonnull @.str)
  %30 = sdiv i32 %.434, %20
  %31 = srem i32 %30, %20
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %.lr.ph35, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph35, %.preheader
  %.4.lcssa = phi i32 [ %.3.lcssa, %.preheader ], [ %30, %.lr.ph35 ]
  %33 = add nuw nsw i32 %.039, 6
  %34 = mul nuw nsw i32 %33, %33
  %.not = icmp sgt i32 %34, %.4.lcssa
  br i1 %.not, label %._crit_edge40, label %.preheader23, !llvm.loop !10

35:                                               ; preds = %._crit_edge40
  %36 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.2.lcssa)
  br label %37

37:                                               ; preds = %1, %35, %._crit_edge40
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #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 = { inlinehint 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 #2 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = distinct !{!9, !6}
!10 = distinct !{!10, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass