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

; 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 @findSolution(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 15, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = mul i64 %18, 8
  %20 = call noalias ptr @malloc(i64 noundef %19) #5
  store ptr %20, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %88, %4
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 101
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %91

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 1, ptr %14, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %83, %25
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 101
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 5, ptr %13, align 4
  br label %86

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = load i32, ptr %14, align 4, !tbaa !9
  %34 = call i32 %31(i32 noundef %32, i32 noundef %33)
  store i32 %34, ptr %15, align 4, !tbaa !9
  %35 = load i32, ptr %15, align 4, !tbaa !9
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %38, label %74

38:                                               ; preds = %30
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = sub nsw i32 %40, 1
  %42 = icmp eq i32 %39, %41
  br i1 %42, label %43, label %53

43:                                               ; preds = %38
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = sitofp i32 %44 to double
  %46 = fmul double %45, 1.500000e+00
  %47 = fptosi double %46 to i32
  store i32 %47, ptr %9, align 4, !tbaa !9
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = mul i64 %50, 8
  %52 = call ptr @realloc(ptr noundef %48, i64 noundef %51) #6
  store ptr %52, ptr %11, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %43, %38
  %54 = call noalias ptr @malloc(i64 noundef 8) #5
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds ptr, ptr %55, i64 %57
  store ptr %54, ptr %58, align 8, !tbaa !5
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %60, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = getelementptr inbounds i32, ptr %64, i64 0
  store i32 %59, ptr %65, align 4, !tbaa !9
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %10, align 4, !tbaa !9
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds ptr, ptr %67, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = getelementptr inbounds i32, ptr %72, i64 1
  store i32 %66, ptr %73, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %53, %30
  %75 = load i32, ptr %15, align 4, !tbaa !9
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = icmp sgt i32 %75, %76
  br i1 %77, label %78, label %79

78:                                               ; preds = %74
  store i32 5, ptr %13, align 4
  br label %80

79:                                               ; preds = %74
  store i32 0, ptr %13, align 4
  br label %80

80:                                               ; preds = %79, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  %81 = load i32, ptr %13, align 4
  switch i32 %81, label %86 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %14, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %14, align 4, !tbaa !9
  br label %26, !llvm.loop !11

86:                                               ; preds = %80, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %12, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %12, align 4, !tbaa !9
  br label %21, !llvm.loop !13

91:                                               ; preds = %24
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = mul i64 %93, 4
  %95 = call noalias ptr @malloc(i64 noundef %94) #5
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %95, ptr %96, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %108, %91
  %98 = load i32, ptr %16, align 4, !tbaa !9
  %99 = load i32, ptr %10, align 4, !tbaa !9
  %100 = icmp slt i32 %98, %99
  br i1 %100, label %102, label %101

101:                                              ; preds = %97
  store i32 8, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %111

102:                                              ; preds = %97
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = load ptr, ptr %103, align 8, !tbaa !5
  %105 = load i32, ptr %16, align 4, !tbaa !9
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds i32, ptr %104, i64 %106
  store i32 2, ptr %107, align 4, !tbaa !9
  br label %108

108:                                              ; preds = %102
  %109 = load i32, ptr %16, align 4, !tbaa !9
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %16, align 4, !tbaa !9
  br label %97, !llvm.loop !14

111:                                              ; preds = %101
  %112 = load i32, ptr %10, align 4, !tbaa !9
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %112, ptr %113, align 4, !tbaa !9
  %114 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret ptr %114
}

; 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: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

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

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 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }
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 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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 ptr @findSolution(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = tail call noalias dereferenceable_or_null(120) ptr @malloc(i64 noundef 120) #3
  br label %.preheader

.preheader:                                       ; preds = %4, %36
  %.03555 = phi i32 [ 15, %4 ], [ %.3, %36 ]
  %.03854 = phi i32 [ 1, %4 ], [ %37, %36 ]
  %.03953 = phi ptr [ %5, %4 ], [ %.342, %36 ]
  %.04452 = phi i32 [ 0, %4 ], [ %.246, %36 ]
  br label %14

6:                                                ; preds = %36
  %7 = sext i32 %.246 to i64
  %8 = shl nsw i64 %7, 2
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #3
  store ptr %9, ptr %3, align 8, !tbaa !5
  %10 = icmp sgt i32 %.246, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %.246 to i64
  %min.iters.check = icmp ult i32 %.246, 8
  br i1 %min.iters.check, label %.lr.ph.preheader59, label %vector.ph

.lr.ph.preheader59:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %11 = getelementptr inbounds i32, ptr %9, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, ptr %11, align 4, !tbaa !9
  store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, ptr %12, align 4, !tbaa !9
  %index.next = add nuw i64 %index, 8
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader59

14:                                               ; preds = %33, %.preheader
  %.151 = phi i32 [ %.03555, %.preheader ], [ %.3, %33 ]
  %.03650 = phi i32 [ 1, %.preheader ], [ %34, %33 ]
  %.14049 = phi ptr [ %.03953, %.preheader ], [ %.342, %33 ]
  %.14548 = phi i32 [ %.04452, %.preheader ], [ %.246, %33 ]
  %15 = tail call i32 %0(i32 noundef %.03854, i32 noundef %.03650) #4
  %16 = icmp eq i32 %15, %1
  br i1 %16, label %17, label %33

17:                                               ; preds = %14
  %18 = add nsw i32 %.151, -1
  %19 = icmp eq i32 %.14548, %18
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = sitofp i32 %.151 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, 3
  %26 = tail call ptr @realloc(ptr noundef %.14049, i64 noundef %25) #5
  br label %27

27:                                               ; preds = %20, %17
  %.241 = phi ptr [ %26, %20 ], [ %.14049, %17 ]
  %.2 = phi i32 [ %23, %20 ], [ %.151, %17 ]
  %28 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #3
  %29 = sext i32 %.14548 to i64
  %30 = getelementptr inbounds ptr, ptr %.241, i64 %29
  store ptr %28, ptr %30, align 8, !tbaa !5
  store i32 %.03854, ptr %28, align 4, !tbaa !9
  %31 = add nsw i32 %.14548, 1
  %32 = getelementptr inbounds i8, ptr %28, i64 4
  store i32 %.03650, ptr %32, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %27, %14
  %.246 = phi i32 [ %31, %27 ], [ %.14548, %14 ]
  %.342 = phi ptr [ %.241, %27 ], [ %.14049, %14 ]
  %.3 = phi i32 [ %.2, %27 ], [ %.151, %14 ]
  %.not = icmp sle i32 %15, %1
  %34 = add nuw nsw i32 %.03650, 1
  %35 = icmp ult i32 %.03650, 100
  %or.cond = and i1 %.not, %35
  br i1 %or.cond, label %14, label %36, !llvm.loop !15

36:                                               ; preds = %33
  %37 = add nuw nsw i32 %.03854, 1
  %exitcond.not = icmp eq i32 %37, 101
  br i1 %exitcond.not, label %6, label %.preheader, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %6
  store i32 %.246, ptr %2, align 4, !tbaa !9
  ret ptr %.342

.lr.ph:                                           ; preds = %.lr.ph.preheader59, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader59 ]
  %38 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv
  store i32 2, ptr %38, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond58.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond58.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17
}

; 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 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 #2

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 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 #3 = { nounwind allocsize(0) }
attributes #4 = { nounwind }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12, !14, !13}


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