; LLVM IR from 0r-gh0/NUMERICAL_ANALYSIS :: CODES (bisection)

; 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 [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local float @function(float noundef) #0

; Function Attrs: nounwind uwtable
define dso_local float @bisect(float noundef %0, float noundef %1, float noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #0 {
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca float, align 4
  %15 = alloca i32, align 4
  store float %0, ptr %8, align 4, !tbaa !5
  store float %1, ptr %9, align 4, !tbaa !5
  store float %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !11
  %16 = load i32, ptr %11, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %18 = load float, ptr %8, align 4, !tbaa !5
  %19 = load float, ptr %9, align 4, !tbaa !5
  %20 = fadd float %18, %19
  %21 = fdiv float %20, 2.000000e+00
  store float %21, ptr %14, align 4, !tbaa !5
  %22 = load ptr, ptr %13, align 8, !tbaa !11
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = load float, ptr %8, align 4, !tbaa !5
  %25 = fpext float %24 to double
  %26 = load float, ptr %9, align 4, !tbaa !5
  %27 = fpext float %26 to double
  %28 = load float, ptr %14, align 4, !tbaa !5
  %29 = fpext float %28 to double
  %30 = load float, ptr %14, align 4, !tbaa !5
  %31 = call float @function(float noundef %30)
  %32 = fpext float %31 to double
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str, i32 noundef %23, double noundef %25, double noundef %27, double noundef %29, double noundef %32) #5
  %34 = load float, ptr %14, align 4, !tbaa !5
  %35 = call float @function(float noundef %34)
  %36 = fpext float %35 to double
  %37 = call double @llvm.fabs.f64(double %36)
  %38 = load float, ptr %10, align 4, !tbaa !5
  %39 = fpext float %38 to double
  %40 = fcmp oge double %37, %39
  br i1 %40, label %41, label %70

41:                                               ; preds = %6
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %70

45:                                               ; preds = %41
  %46 = load float, ptr %8, align 4, !tbaa !5
  %47 = call float @function(float noundef %46)
  %48 = load float, ptr %14, align 4, !tbaa !5
  %49 = call float @function(float noundef %48)
  %50 = fmul float %47, %49
  %51 = fpext float %50 to double
  %52 = fcmp olt double %51, 0.000000e+00
  br i1 %52, label %53, label %61

53:                                               ; preds = %45
  %54 = load float, ptr %8, align 4, !tbaa !5
  %55 = load float, ptr %14, align 4, !tbaa !5
  %56 = load float, ptr %10, align 4, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = load ptr, ptr %13, align 8, !tbaa !11
  %60 = call float @bisect(float noundef %54, float noundef %55, float noundef %56, i32 noundef %57, i32 noundef %58, ptr noundef %59)
  br label %69

61:                                               ; preds = %45
  %62 = load float, ptr %14, align 4, !tbaa !5
  %63 = load float, ptr %9, align 4, !tbaa !5
  %64 = load float, ptr %10, align 4, !tbaa !5
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = load ptr, ptr %13, align 8, !tbaa !11
  %68 = call float @bisect(float noundef %62, float noundef %63, float noundef %64, i32 noundef %65, i32 noundef %66, ptr noundef %67)
  br label %69

69:                                               ; preds = %61, %53
  br label %83

70:                                               ; preds = %41, %6
  %71 = load ptr, ptr %13, align 8, !tbaa !11
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = load float, ptr %14, align 4, !tbaa !5
  %74 = fpext float %73 to double
  %75 = load float, ptr %14, align 4, !tbaa !5
  %76 = call float @function(float noundef %75)
  %77 = fpext float %76 to double
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str.1, i32 noundef %72, double noundef %74, double noundef %77) #5
  %79 = load ptr, ptr %13, align 8, !tbaa !11
  %80 = call i32 @fclose(ptr noundef %79)
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store float 0.000000e+00, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %84

83:                                               ; preds = %69
  store i32 0, ptr %15, align 4
  br label %84

84:                                               ; preds = %83, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %85 = load i32, ptr %15, align 4
  switch i32 %85, label %88 [
    i32 0, label %86
    i32 1, label %86
  ]

86:                                               ; preds = %84, %84
  %87 = load float, ptr %7, align 4
  ret float %87

88:                                               ; preds = %84
  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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

declare i32 @fclose(ptr noundef) #4

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

; 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 "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 speculatable willreturn memory(none) }
attributes #4 = { "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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; 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 [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local float @function(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef float @bisect(float noundef %0, float noundef %1, float noundef %2, i32 noundef %3, i32 noundef %4, ptr nocapture noundef %5) local_unnamed_addr #0 {
  br label %tailrecurse.outer.outer

tailrecurse.outer.outer:                          ; preds = %37, %6
  %.tr.ph.ph = phi float [ %0, %6 ], [ %27, %37 ]
  %.tr33.ph.ph = phi float [ %1, %6 ], [ %.tr33, %37 ]
  %.tr35.ph.ph = phi i32 [ %3, %6 ], [ %25, %37 ]
  %7 = fpext float %.tr33.ph.ph to double
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %tailrecurse.outer.outer, %20
  %.tr.ph = phi float [ %11, %20 ], [ %.tr.ph.ph, %tailrecurse.outer.outer ]
  %.tr35.ph = phi i32 [ %9, %20 ], [ %.tr35.ph.ph, %tailrecurse.outer.outer ]
  %8 = fpext float %.tr.ph to double
  %9 = add nsw i32 %.tr35.ph, 1
  %10 = fadd float %.tr.ph, %.tr33.ph.ph
  %11 = fmul float %10, 5.000000e-01
  %12 = fpext float %11 to double
  %13 = tail call float @function(float noundef %11)
  %14 = fpext float %13 to double
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, i32 noundef %9, double noundef %8, double noundef %7, double noundef %12, double noundef %14) #3
  %16 = tail call float @function(float noundef %11)
  %17 = tail call float @llvm.fabs.f32(float %16)
  %18 = fcmp oge float %17, %2
  %19 = icmp slt i32 %9, %4
  %or.cond.peel = select i1 %18, i1 %19, i1 false
  br i1 %or.cond.peel, label %20, label %.loopexit

20:                                               ; preds = %tailrecurse.outer
  %21 = tail call float @function(float noundef %.tr.ph)
  %22 = tail call float @function(float noundef %11)
  %23 = fmul float %21, %22
  %24 = fcmp olt float %23, 0.000000e+00
  br i1 %24, label %tailrecurse, label %tailrecurse.outer

tailrecurse:                                      ; preds = %20, %37
  %.tr33 = phi float [ %27, %37 ], [ %11, %20 ]
  %.tr35 = phi i32 [ %25, %37 ], [ %9, %20 ]
  %25 = add nsw i32 %.tr35, 1
  %26 = fadd float %.tr.ph, %.tr33
  %27 = fmul float %26, 5.000000e-01
  %28 = fpext float %.tr33 to double
  %29 = fpext float %27 to double
  %30 = tail call float @function(float noundef %27)
  %31 = fpext float %30 to double
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, i32 noundef %25, double noundef %8, double noundef %28, double noundef %29, double noundef %31) #3
  %33 = tail call float @function(float noundef %27)
  %34 = tail call float @llvm.fabs.f32(float %33)
  %35 = fcmp oge float %34, %2
  %36 = icmp slt i32 %25, %4
  %or.cond = select i1 %35, i1 %36, i1 false
  br i1 %or.cond, label %37, label %.loopexit

37:                                               ; preds = %tailrecurse
  %38 = tail call float @function(float noundef %.tr.ph)
  %39 = tail call float @function(float noundef %27)
  %40 = fmul float %38, %39
  %41 = fcmp olt float %40, 0.000000e+00
  br i1 %41, label %tailrecurse, label %tailrecurse.outer.outer, !llvm.loop !5

.loopexit:                                        ; preds = %tailrecurse.outer, %tailrecurse
  %.lcssa51 = phi i32 [ %25, %tailrecurse ], [ %9, %tailrecurse.outer ]
  %.lcssa49 = phi float [ %27, %tailrecurse ], [ %11, %tailrecurse.outer ]
  %.lcssa = phi double [ %29, %tailrecurse ], [ %12, %tailrecurse.outer ]
  %42 = tail call float @function(float noundef %.lcssa49)
  %43 = fpext float %42 to double
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.1, i32 noundef %.lcssa51, double noundef %.lcssa, double noundef %43) #3
  %45 = tail call i32 @fclose(ptr noundef %5)
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  ret float 0.000000e+00
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass