; LLVM IR from kenjin/Awesome-LC-C-Cracker :: leetcode-c-sol/0502_ipo (0502_ipo)

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

%struct.heap_t = type { ptr, i32, i32 }
%struct.proj_t = type { i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @findMaximizedCapital(i32 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca %struct.heap_t, align 8
  %14 = alloca %struct.heap_t, align 8
  %15 = alloca i32, align 4
  %16 = alloca %struct.proj_t, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca %struct.proj_t, align 4
  %20 = alloca %struct.proj_t, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #5
  %21 = getelementptr inbounds %struct.heap_t, ptr %13, i32 0, i32 0
  %22 = load i32, ptr %12, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul i64 %23, 8
  %25 = call noalias ptr @malloc(i64 noundef %24) #6
  store ptr %25, ptr %21, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.heap_t, ptr %13, i32 0, i32 1
  store i32 0, ptr %26, align 8, !tbaa !13
  %27 = getelementptr inbounds %struct.heap_t, ptr %13, i32 0, i32 2
  %28 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %28, ptr %27, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  %29 = getelementptr inbounds %struct.heap_t, ptr %14, i32 0, i32 0
  %30 = load i32, ptr %12, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = mul i64 %31, 8
  %33 = call noalias ptr @malloc(i64 noundef %32) #6
  store ptr %33, ptr %29, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.heap_t, ptr %14, i32 0, i32 1
  store i32 0, ptr %34, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.heap_t, ptr %14, i32 0, i32 2
  %36 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %36, ptr %35, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %56, %6
  %38 = load i32, ptr %15, align 4, !tbaa !5
  %39 = load i32, ptr %12, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %59

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %43 = getelementptr inbounds %struct.proj_t, ptr %16, i32 0, i32 0
  %44 = load ptr, ptr %11, align 8, !tbaa !9
  %45 = load i32, ptr %15, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  store i32 %48, ptr %43, align 4, !tbaa !15
  %49 = getelementptr inbounds %struct.proj_t, ptr %16, i32 0, i32 1
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = load i32, ptr %15, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  store i32 %54, ptr %49, align 4, !tbaa !17
  %55 = load i64, ptr %16, align 4
  call void @__heap_push(ptr noundef %13, i64 %55, i1 noundef zeroext false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %56

56:                                               ; preds = %42
  %57 = load i32, ptr %15, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %15, align 4, !tbaa !5
  br label %37, !llvm.loop !18

59:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %90, %59
  %61 = load i32, ptr %17, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %60
  store i32 5, ptr %18, align 4
  br label %93

65:                                               ; preds = %60
  br label %66

66:                                               ; preds = %76, %65
  %67 = getelementptr inbounds %struct.heap_t, ptr %13, i32 0, i32 1
  %68 = load i32, ptr %67, align 8, !tbaa !13
  %69 = icmp sgt i32 %68, 0
  br i1 %69, label %70, label %74

70:                                               ; preds = %66
  %71 = call i32 @min_heap_top_capital(ptr noundef %13)
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = icmp sle i32 %71, %72
  br label %74

74:                                               ; preds = %70, %66
  %75 = phi i1 [ false, %66 ], [ %73, %70 ]
  br i1 %75, label %76, label %79

76:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %77 = call i64 @__heap_pop(ptr noundef %13, i1 noundef zeroext false)
  store i64 %77, ptr %19, align 4
  %78 = load i64, ptr %19, align 4
  call void @__heap_push(ptr noundef %14, i64 %78, i1 noundef zeroext true)
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  br label %66, !llvm.loop !20

79:                                               ; preds = %74
  %80 = getelementptr inbounds %struct.heap_t, ptr %14, i32 0, i32 1
  %81 = load i32, ptr %80, align 8, !tbaa !13
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %84, label %83

83:                                               ; preds = %79
  store i32 5, ptr %18, align 4
  br label %93

84:                                               ; preds = %79
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %85 = call i64 @__heap_pop(ptr noundef %14, i1 noundef zeroext true)
  store i64 %85, ptr %20, align 4
  %86 = getelementptr inbounds %struct.proj_t, ptr %20, i32 0, i32 1
  %87 = load i32, ptr %86, align 4, !tbaa !17
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = add nsw i32 %88, %87
  store i32 %89, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  br label %90

90:                                               ; preds = %84
  %91 = load i32, ptr %17, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %17, align 4, !tbaa !5
  br label %60, !llvm.loop !21

93:                                               ; preds = %83, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %94

94:                                               ; preds = %93
  %95 = getelementptr inbounds %struct.heap_t, ptr %13, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !11
  call void @free(ptr noundef %96) #5
  %97 = getelementptr inbounds %struct.heap_t, ptr %14, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !11
  call void @free(ptr noundef %98) #5
  %99 = load i32, ptr %8, align 4, !tbaa !5
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  ret i32 %99
}

; 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 uwtable
declare hidden void @__heap_push(ptr noundef, i64, i1 noundef zeroext) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @min_heap_top_capital(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i64 @__heap_pop(ptr noundef, i1 noundef zeroext) #0

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

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 = { inlinehint 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !6, i64 8, !6, i64 12}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 12}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 4}
!17 = !{!16, !6, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}


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

%struct.heap_t = type { ptr, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @findMaximizedCapital(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, ptr nocapture noundef readonly %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca %struct.heap_t, align 8
  %8 = alloca %struct.heap_t, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  %9 = sext i32 %5 to i64
  %10 = shl nsw i64 %9, 3
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #6
  store ptr %11, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 0, ptr %12, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %7, i64 12
  store i32 %5, ptr %13, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #5
  %14 = tail call noalias ptr @malloc(i64 noundef %10) #6
  store ptr %14, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %8, i64 8
  store i32 0, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %8, i64 12
  store i32 %5, ptr %16, align 4, !tbaa !12
  %17 = icmp sgt i32 %5, 0
  br i1 %17, label %.lr.ph.preheader, label %.preheader21

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph

.preheader21:                                     ; preds = %.lr.ph, %6
  %18 = icmp sgt i32 %0, 0
  br i1 %18, label %.preheader, label %.critedge._crit_edge

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %19 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %.sroa.4.0.insert.ext = zext i32 %22 to i64
  %.sroa.4.0.insert.shift = shl nuw i64 %.sroa.4.0.insert.ext, 32
  %.sroa.03.0.insert.ext = zext i32 %20 to i64
  %.sroa.03.0.insert.insert = or disjoint i64 %.sroa.4.0.insert.shift, %.sroa.03.0.insert.ext
  call void @__heap_push(ptr noundef nonnull %7, i64 %.sroa.03.0.insert.insert, i1 noundef zeroext false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader21, label %.lr.ph, !llvm.loop !14

.preheader:                                       ; preds = %.preheader21, %31
  %.026 = phi i32 [ %33, %31 ], [ %1, %.preheader21 ]
  %.01925 = phi i32 [ %34, %31 ], [ 0, %.preheader21 ]
  %23 = load i32, ptr %12, align 8, !tbaa !11
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph23, label %.critedge

.lr.ph23:                                         ; preds = %.preheader, %26
  %25 = call i32 @min_heap_top_capital(ptr noundef nonnull %7)
  %.not = icmp sgt i32 %25, %.026
  br i1 %.not, label %.critedge, label %26

26:                                               ; preds = %.lr.ph23
  %27 = call i64 @__heap_pop(ptr noundef nonnull %7, i1 noundef zeroext false)
  call void @__heap_push(ptr noundef nonnull %8, i64 %27, i1 noundef zeroext true)
  %28 = load i32, ptr %12, align 8, !tbaa !11
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph23, label %.critedge, !llvm.loop !16

.critedge:                                        ; preds = %.lr.ph23, %26, %.preheader
  %30 = load i32, ptr %15, align 8, !tbaa !11
  %.not20 = icmp eq i32 %30, 0
  br i1 %.not20, label %.critedge._crit_edge, label %31

31:                                               ; preds = %.critedge
  %32 = call i64 @__heap_pop(ptr noundef nonnull %8, i1 noundef zeroext true)
  %.sroa.3.0.extract.shift = lshr i64 %32, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %33 = add nsw i32 %.026, %.sroa.3.0.extract.trunc
  %34 = add nuw nsw i32 %.01925, 1
  %exitcond29.not = icmp eq i32 %34, %0
  br i1 %exitcond29.not, label %.critedge._crit_edge, label %.preheader, !llvm.loop !17

.critedge._crit_edge:                             ; preds = %31, %.critedge, %.preheader21
  %.0.lcssa = phi i32 [ %1, %.preheader21 ], [ %.026, %.critedge ], [ %33, %31 ]
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %35) #5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %36) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  ret i32 %.0.lcssa
}

; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @__heap_push(ptr noundef, i64, i1 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @min_heap_top_capital(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i64 @__heap_pop(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { inlinehint 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 #4 = { mustprogress nounwind willreturn allockind("free") 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 #5 = { nounwind }
attributes #6 = { nounwind 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 12}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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