; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C/Algorithms/Greedy-Algorithms (FractionalKnapsack)

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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @knapsack(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca float, align 4
  %11 = alloca [20 x float], align 16
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store float %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 80, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store float 0.000000e+00, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %19 = load float, ptr %10, align 4, !tbaa !11
  store float %19, ptr %15, align 4, !tbaa !11
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %28, %5
  %21 = load i32, ptr %13, align 4, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %31

24:                                               ; preds = %20
  %25 = load i32, ptr %13, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [20 x float], ptr %11, i64 0, i64 %26
  store float 0.000000e+00, ptr %27, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %24
  %29 = load i32, ptr %13, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %13, align 4, !tbaa !5
  br label %20, !llvm.loop !13

31:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store float 0.000000e+00, ptr %16, align 4, !tbaa !11
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %98, %31
  %33 = load i32, ptr %13, align 4, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %101

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = load i32, ptr %13, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %37, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  store i32 %41, ptr %17, align 4, !tbaa !5
  %42 = load float, ptr %16, align 4, !tbaa !11
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load i32, ptr %13, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %43, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = fadd float %42, %47
  %49 = load float, ptr %15, align 4, !tbaa !11
  %50 = fcmp ole float %48, %49
  br i1 %50, label %51, label %69

51:                                               ; preds = %36
  %52 = load i32, ptr %17, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [20 x float], ptr %11, i64 0, i64 %53
  store float 1.000000e+00, ptr %54, align 4, !tbaa !11
  %55 = load float, ptr %16, align 4, !tbaa !11
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = load i32, ptr %13, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds float, ptr %56, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !11
  %61 = fadd float %55, %60
  store float %61, ptr %16, align 4, !tbaa !11
  %62 = load float, ptr %12, align 4, !tbaa !11
  %63 = load ptr, ptr %9, align 8, !tbaa !9
  %64 = load i32, ptr %13, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds float, ptr %63, i64 %65
  %67 = load float, ptr %66, align 4, !tbaa !11
  %68 = fadd float %62, %67
  store float %68, ptr %12, align 4, !tbaa !11
  br label %94

69:                                               ; preds = %36
  %70 = load float, ptr %15, align 4, !tbaa !11
  %71 = load float, ptr %16, align 4, !tbaa !11
  %72 = fsub float %70, %71
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  %74 = load i32, ptr %13, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds float, ptr %73, i64 %75
  %77 = load float, ptr %76, align 4, !tbaa !11
  %78 = fdiv float %72, %77
  %79 = load i32, ptr %17, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [20 x float], ptr %11, i64 0, i64 %80
  store float %78, ptr %81, align 4, !tbaa !11
  %82 = load i32, ptr %17, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [20 x float], ptr %11, i64 0, i64 %83
  %85 = load float, ptr %84, align 4, !tbaa !11
  %86 = load ptr, ptr %9, align 8, !tbaa !9
  %87 = load i32, ptr %13, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds float, ptr %86, i64 %88
  %90 = load float, ptr %89, align 4, !tbaa !11
  %91 = load float, ptr %12, align 4, !tbaa !11
  %92 = call float @llvm.fmuladd.f32(float %85, float %90, float %91)
  store float %92, ptr %12, align 4, !tbaa !11
  %93 = load float, ptr %15, align 4, !tbaa !11
  store float %93, ptr %16, align 4, !tbaa !11
  store i32 5, ptr %18, align 4
  br label %95

94:                                               ; preds = %51
  store i32 0, ptr %18, align 4
  br label %95

95:                                               ; preds = %94, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  %96 = load i32, ptr %18, align 4
  switch i32 %96, label %123 [
    i32 0, label %97
    i32 5, label %101
  ]

97:                                               ; preds = %95
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %13, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %13, align 4, !tbaa !5
  br label %32, !llvm.loop !15

101:                                              ; preds = %95, %32
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %104

104:                                              ; preds = %115, %101
  %105 = load i32, ptr %13, align 4, !tbaa !5
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = icmp slt i32 %105, %106
  br i1 %107, label %108, label %118

108:                                              ; preds = %104
  %109 = load i32, ptr %13, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [20 x float], ptr %11, i64 0, i64 %110
  %112 = load float, ptr %111, align 4, !tbaa !11
  %113 = fpext float %112 to double
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %113)
  br label %115

115:                                              ; preds = %108
  %116 = load i32, ptr %13, align 4, !tbaa !5
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %13, align 4, !tbaa !5
  br label %104, !llvm.loop !16

118:                                              ; preds = %104
  %119 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %120 = load float, ptr %12, align 4, !tbaa !11
  %121 = fpext float %120 to double
  %122 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, double noundef %121)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 80, ptr %11) #4
  ret void

123:                                              ; preds = %95
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

declare i32 @printf(ptr noundef, ...) #3

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

!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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1

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

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @knapsack(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, float noundef %4) local_unnamed_addr #1 {
  %6 = alloca [20 x float], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %6) #5
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph58.preheader, label %.loopexit

.lr.ph58.preheader:                               ; preds = %5
  %8 = zext nneg i32 %0 to i64
  %9 = shl nuw nsw i64 %8, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %6, i8 0, i64 %9, i1 false), !tbaa !5
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph58

.lr.ph58:                                         ; preds = %.lr.ph58.preheader, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph58.preheader ], [ %indvars.iv.next, %24 ]
  %.03657 = phi float [ 0.000000e+00, %.lr.ph58.preheader ], [ %29, %24 ]
  %.03756 = phi float [ 0.000000e+00, %.lr.ph58.preheader ], [ %14, %24 ]
  %10 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = getelementptr inbounds float, ptr %2, i64 %indvars.iv
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = fadd float %.03756, %13
  %15 = fcmp ugt float %14, %4
  br i1 %15, label %16, label %24

16:                                               ; preds = %.lr.ph58
  %17 = fsub float %4, %.03756
  %18 = fdiv float %17, %13
  %19 = sext i32 %11 to i64
  %20 = getelementptr inbounds [20 x float], ptr %6, i64 0, i64 %19
  store float %18, ptr %20, align 4, !tbaa !5
  %21 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  %22 = load float, ptr %21, align 4, !tbaa !5
  %23 = tail call float @llvm.fmuladd.f32(float %18, float %22, float %.03657)
  br label %.loopexit

24:                                               ; preds = %.lr.ph58
  %25 = sext i32 %11 to i64
  %26 = getelementptr inbounds [20 x float], ptr %6, i64 0, i64 %25
  store float 1.000000e+00, ptr %26, align 4, !tbaa !5
  %27 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  %28 = load float, ptr %27, align 4, !tbaa !5
  %29 = fadd float %.03657, %28
  %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 %.loopexit, label %.lr.ph58, !llvm.loop !11

.loopexit:                                        ; preds = %24, %5, %16
  %.2 = phi float [ %23, %16 ], [ 0.000000e+00, %5 ], [ %29, %24 ]
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br i1 %7, label %.lr.ph60.preheader, label %._crit_edge

.lr.ph60.preheader:                               ; preds = %.loopexit
  %wide.trip.count74 = zext nneg i32 %0 to i64
  br label %.lr.ph60

.lr.ph60:                                         ; preds = %.lr.ph60.preheader, %.lr.ph60
  %indvars.iv71 = phi i64 [ 0, %.lr.ph60.preheader ], [ %indvars.iv.next72, %.lr.ph60 ]
  %32 = getelementptr inbounds [20 x float], ptr %6, i64 0, i64 %indvars.iv71
  %33 = load float, ptr %32, align 4, !tbaa !5
  %34 = fpext float %33 to double
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %34)
  %indvars.iv.next72 = add nuw nsw i64 %indvars.iv71, 1
  %exitcond75.not = icmp eq i64 %indvars.iv.next72, %wide.trip.count74
  br i1 %exitcond75.not, label %._crit_edge, label %.lr.ph60, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph60, %.loopexit
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %37 = fpext float %.2 to double
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, double noundef %37)
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %6) #5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nofree 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"float", !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}


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