; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (728)

; 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: nounwind uwtable
define dso_local ptr @selfDividingNumbers(i32 noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 10, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul i64 %20, 4
  %22 = call noalias ptr @malloc(i64 noundef %21) #6
  store ptr %22, ptr %10, align 8, !tbaa !9
  %23 = load ptr, ptr %10, align 8, !tbaa !9
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %123

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

28:                                               ; preds = %114, %26
  %29 = load i32, ptr %12, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  store i32 2, ptr %11, align 4
  br label %117

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %35 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %35, ptr %14, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %41, %34
  %37 = load i32, ptr %14, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %46

40:                                               ; preds = %36
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %13, align 4, !tbaa !5
  %43 = add i32 %42, 1
  store i32 %43, ptr %13, align 4, !tbaa !5
  %44 = load i32, ptr %14, align 4, !tbaa !5
  %45 = sdiv i32 %44, 10
  store i32 %45, ptr %14, align 4, !tbaa !5
  br label %36, !llvm.loop !11

46:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %47 = load i32, ptr %13, align 4, !tbaa !5
  %48 = sub i32 %47, 1
  %49 = uitofp i32 %48 to double
  %50 = call double @pow(double noundef 1.000000e+01, double noundef %49) #5
  %51 = fptosi double %50 to i32
  store i32 %51, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 0, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %52 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %52, ptr %17, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %79, %46
  %54 = load i32, ptr %15, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %80

56:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %57 = load i32, ptr %17, align 4, !tbaa !5
  %58 = load i32, ptr %15, align 4, !tbaa !5
  %59 = sdiv i32 %57, %58
  store i32 %59, ptr %18, align 4, !tbaa !5
  %60 = load i32, ptr %15, align 4, !tbaa !5
  %61 = load i32, ptr %17, align 4, !tbaa !5
  %62 = srem i32 %61, %60
  store i32 %62, ptr %17, align 4, !tbaa !5
  %63 = load i32, ptr %18, align 4, !tbaa !5
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %73

65:                                               ; preds = %56
  %66 = load i32, ptr %12, align 4, !tbaa !5
  %67 = load i32, ptr %18, align 4, !tbaa !5
  %68 = srem i32 %66, %67
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %73, label %70

70:                                               ; preds = %65
  %71 = load i32, ptr %16, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %16, align 4, !tbaa !5
  br label %74

73:                                               ; preds = %65, %56
  store i32 9, ptr %11, align 4
  br label %77

74:                                               ; preds = %70
  %75 = load i32, ptr %15, align 4, !tbaa !5
  %76 = sdiv i32 %75, 10
  store i32 %76, ptr %15, align 4, !tbaa !5
  store i32 0, ptr %11, align 4
  br label %77

77:                                               ; preds = %74, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  %78 = load i32, ptr %11, align 4
  switch i32 %78, label %125 [
    i32 0, label %79
    i32 9, label %80
  ]

79:                                               ; preds = %77
  br label %53, !llvm.loop !13

80:                                               ; preds = %77, %53
  %81 = load i32, ptr %16, align 4, !tbaa !5
  %82 = load i32, ptr %13, align 4, !tbaa !5
  %83 = icmp eq i32 %81, %82
  br i1 %83, label %84, label %110

84:                                               ; preds = %80
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = icmp sge i32 %85, %86
  br i1 %87, label %88, label %103

88:                                               ; preds = %84
  %89 = load i32, ptr %8, align 4, !tbaa !5
  %90 = sitofp i32 %89 to double
  %91 = fmul double %90, 1.500000e+00
  %92 = fptosi double %91 to i32
  store i32 %92, ptr %8, align 4, !tbaa !5
  %93 = load ptr, ptr %10, align 8, !tbaa !9
  %94 = load i32, ptr %8, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = mul i64 %95, 4
  %97 = call ptr @realloc(ptr noundef %93, i64 noundef %96) #7
  store ptr %97, ptr %10, align 8, !tbaa !9
  %98 = load ptr, ptr %10, align 8, !tbaa !9
  %99 = icmp ne ptr %98, null
  br i1 %99, label %102, label %100

100:                                              ; preds = %88
  %101 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %101) #5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %111

102:                                              ; preds = %88
  br label %103

103:                                              ; preds = %102, %84
  %104 = load i32, ptr %12, align 4, !tbaa !5
  %105 = load ptr, ptr %10, align 8, !tbaa !9
  %106 = load i32, ptr %9, align 4, !tbaa !5
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %9, align 4, !tbaa !5
  %108 = sext i32 %106 to i64
  %109 = getelementptr inbounds i32, ptr %105, i64 %108
  store i32 %104, ptr %109, align 4, !tbaa !5
  br label %110

110:                                              ; preds = %103, %80
  store i32 0, ptr %11, align 4
  br label %111

111:                                              ; preds = %110, %100
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  %112 = load i32, ptr %11, align 4
  switch i32 %112, label %117 [
    i32 0, label %113
  ]

113:                                              ; preds = %111
  br label %114

114:                                              ; preds = %113
  %115 = load i32, ptr %12, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %12, align 4, !tbaa !5
  br label %28, !llvm.loop !14

117:                                              ; preds = %111, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %118 = load i32, ptr %11, align 4
  switch i32 %118, label %123 [
    i32 2, label %119
  ]

119:                                              ; preds = %117
  %120 = load i32, ptr %9, align 4, !tbaa !5
  %121 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %120, ptr %121, align 4, !tbaa !5
  %122 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %122, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %123

123:                                              ; preds = %119, %117, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %124 = load ptr, ptr %4, align 8
  ret ptr %124

125:                                              ; preds = %77
  unreachable
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #3

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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: nounwind uwtable
define dso_local noalias ptr @selfDividingNumbers(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #4
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %.loopexit, label %.preheader94

.preheader94:                                     ; preds = %3
  %.not69112 = icmp sgt i32 %0, %1
  br i1 %.not69112, label %.thread89, label %.preheader

.preheader:                                       ; preds = %.preheader94, %31
  %.049116 = phi i32 [ %32, %31 ], [ %0, %.preheader94 ]
  %.053115 = phi ptr [ %.356.ph, %31 ], [ %4, %.preheader94 ]
  %.057114 = phi i32 [ %.259.ph, %31 ], [ 0, %.preheader94 ]
  %.061113 = phi i32 [ %.364.ph, %31 ], [ 10, %.preheader94 ]
  %.not7098 = icmp eq i32 %.049116, 0
  br i1 %.not7098, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.048.lcssa = phi i32 [ 0, %.preheader ], [ %9, %.lr.ph ]
  %5 = add i32 %.048.lcssa, -1
  %6 = uitofp i32 %5 to double
  %7 = tail call double @pow(double noundef 1.000000e+01, double noundef %6) #5
  %8 = fptosi double %7 to i32
  %.not71101 = icmp eq i32 %8, 0
  br i1 %.not71101, label %.thread, label %.lr.ph106

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.047100 = phi i32 [ %10, %.lr.ph ], [ %.049116, %.preheader ]
  %.04899 = phi i32 [ %9, %.lr.ph ], [ 0, %.preheader ]
  %9 = add i32 %.04899, 1
  %10 = sdiv i32 %.047100, 10
  %.047100.off = add i32 %.047100, 9
  %.not70 = icmp ult i32 %.047100.off, 19
  br i1 %.not70, label %._crit_edge, label %.lr.ph, !llvm.loop !5

.lr.ph106:                                        ; preds = %._crit_edge, %15
  %.041104 = phi i32 [ %12, %15 ], [ %.049116, %._crit_edge ]
  %.042103 = phi i32 [ %16, %15 ], [ 0, %._crit_edge ]
  %.045102 = phi i32 [ %17, %15 ], [ %8, %._crit_edge ]
  %11 = sdiv i32 %.041104, %.045102
  %12 = srem i32 %.041104, %.045102
  %.not72 = icmp eq i32 %11, 0
  br i1 %.not72, label %.thread, label %13

13:                                               ; preds = %.lr.ph106
  %14 = srem i32 %.049116, %11
  %.not73 = icmp eq i32 %14, 0
  br i1 %.not73, label %15, label %.thread

15:                                               ; preds = %13
  %16 = add nuw nsw i32 %.042103, 1
  %17 = sdiv i32 %.045102, 10
  %.045102.off = add i32 %.045102, 9
  %.not71 = icmp ult i32 %.045102.off, 19
  br i1 %.not71, label %.thread, label %.lr.ph106

.thread:                                          ; preds = %15, %13, %.lr.ph106, %._crit_edge
  %.042.lcssa = phi i32 [ 0, %._crit_edge ], [ %.042103, %.lr.ph106 ], [ %.042103, %13 ], [ %16, %15 ]
  %18 = icmp eq i32 %.042.lcssa, %.048.lcssa
  br i1 %18, label %19, label %31

19:                                               ; preds = %.thread
  %.not74 = icmp slt i32 %.057114, %.061113
  br i1 %.not74, label %27, label %20

20:                                               ; preds = %19
  %21 = sitofp i32 %.061113 to double
  %22 = fmul double %21, 1.500000e+00
  %23 = fptosi double %22 to i32
  %24 = sext i32 %23 to i64
  %25 = shl nsw i64 %24, 2
  %26 = tail call ptr @realloc(ptr noundef %.053115, i64 noundef %25) #6
  %.not75 = icmp eq ptr %26, null
  br i1 %.not75, label %.loopexit, label %27

27:                                               ; preds = %20, %19
  %.162 = phi i32 [ %23, %20 ], [ %.061113, %19 ]
  %.154 = phi ptr [ %26, %20 ], [ %.053115, %19 ]
  %28 = add nsw i32 %.057114, 1
  %29 = sext i32 %.057114 to i64
  %30 = getelementptr inbounds i32, ptr %.154, i64 %29
  store i32 %.049116, ptr %30, align 4, !tbaa !7
  br label %31

31:                                               ; preds = %27, %.thread
  %.364.ph = phi i32 [ %.061113, %.thread ], [ %.162, %27 ]
  %.259.ph = phi i32 [ %.057114, %.thread ], [ %28, %27 ]
  %.356.ph = phi ptr [ %.053115, %.thread ], [ %.154, %27 ]
  %32 = add i32 %.049116, 1
  %exitcond.not = icmp eq i32 %.049116, %1
  br i1 %exitcond.not, label %.thread89, label %.preheader, !llvm.loop !11

.thread89:                                        ; preds = %31, %.preheader94
  %.057.lcssa = phi i32 [ 0, %.preheader94 ], [ %.259.ph, %31 ]
  %.053.lcssa = phi ptr [ %4, %.preheader94 ], [ %.356.ph, %31 ]
  store i32 %.057.lcssa, ptr %2, align 4, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %20, %3, %.thread89
  %.3 = phi ptr [ %.053.lcssa, %.thread89 ], [ null, %3 ], [ null, %20 ]
  ret ptr %.3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(write) "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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!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 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}


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