; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Searching/Ternary-Search/unimodal_func.ll (Z11find_maximadd)

; 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: mustprogress nounwind uwtable
declare dso_local noundef double @_Z5func1d(double noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z11find_maximadd(double noundef %0, double noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  %9 = load double, ptr %4, align 8, !tbaa !5
  %10 = load double, ptr %5, align 8, !tbaa !5
  %11 = fsub double %9, %10
  %12 = call noundef double @_ZSt3absd(double noundef %11)
  %13 = fcmp ole double %12, 0x3E7AD7F29ABCAF48
  br i1 %13, label %14, label %17

14:                                               ; preds = %2
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = call noundef double @_Z5func1d(double noundef %15)
  store double %16, ptr %3, align 8
  br label %56

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load double, ptr %4, align 8, !tbaa !5
  %19 = load double, ptr %5, align 8, !tbaa !5
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = fsub double %19, %20
  %22 = fdiv double %21, 3.000000e+00
  %23 = fadd double %18, %22
  store double %23, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %24 = load double, ptr %4, align 8, !tbaa !5
  %25 = load double, ptr %5, align 8, !tbaa !5
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = fsub double %25, %26
  %28 = fmul double 2.000000e+00, %27
  %29 = fdiv double %28, 3.000000e+00
  %30 = fadd double %24, %29
  store double %30, ptr %7, align 8, !tbaa !5
  %31 = load double, ptr %6, align 8, !tbaa !5
  %32 = call noundef double @_Z5func1d(double noundef %31)
  %33 = load double, ptr %7, align 8, !tbaa !5
  %34 = call noundef double @_Z5func1d(double noundef %33)
  %35 = fcmp olt double %32, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %17
  %37 = load double, ptr %6, align 8, !tbaa !5
  %38 = load double, ptr %5, align 8, !tbaa !5
  %39 = call noundef double @_Z11find_maximadd(double noundef %37, double noundef %38)
  store double %39, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %55

40:                                               ; preds = %17
  %41 = load double, ptr %6, align 8, !tbaa !5
  %42 = call noundef double @_Z5func1d(double noundef %41)
  %43 = load double, ptr %7, align 8, !tbaa !5
  %44 = call noundef double @_Z5func1d(double noundef %43)
  %45 = fcmp ogt double %42, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %40
  %47 = load double, ptr %4, align 8, !tbaa !5
  %48 = load double, ptr %7, align 8, !tbaa !5
  %49 = call noundef double @_Z11find_maximadd(double noundef %47, double noundef %48)
  store double %49, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %55

50:                                               ; preds = %40
  br label %51

51:                                               ; preds = %50
  %52 = load double, ptr %6, align 8, !tbaa !5
  %53 = load double, ptr %7, align 8, !tbaa !5
  %54 = call noundef double @_Z11find_maximadd(double noundef %52, double noundef %53)
  store double %54, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %55

55:                                               ; preds = %51, %46, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %56

56:                                               ; preds = %55, %14
  %57 = load double, ptr %3, align 8
  ret double %57
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) #2

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

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

attributes #0 = { mustprogress 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 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 = { inlinehint mustprogress 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; 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: mustprogress nounwind uwtable
declare dso_local noundef double @_Z5func1d(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z11find_maximadd(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %18, %2
  %.tr.ph = phi double [ %.tr., %18 ], [ %0, %2 ]
  %.tr20.ph = phi double [ %14, %18 ], [ %1, %2 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %8
  %.tr = phi double [ %11, %8 ], [ %.tr.ph, %tailrecurse.outer ]
  %3 = fsub double %.tr, %.tr20.ph
  %4 = tail call noundef double @_ZSt3absd(double noundef %3)
  %5 = fcmp ugt double %4, 0x3E7AD7F29ABCAF48
  br i1 %5, label %8, label %6

6:                                                ; preds = %tailrecurse
  %7 = tail call noundef double @_Z5func1d(double noundef %.tr)
  ret double %7

8:                                                ; preds = %tailrecurse
  %9 = fsub double %.tr20.ph, %.tr
  %10 = fdiv double %9, 3.000000e+00
  %11 = fadd double %.tr, %10
  %12 = fmul double %9, 2.000000e+00
  %13 = fdiv double %12, 3.000000e+00
  %14 = fadd double %.tr, %13
  %15 = tail call noundef double @_Z5func1d(double noundef %11)
  %16 = tail call noundef double @_Z5func1d(double noundef %14)
  %17 = fcmp olt double %15, %16
  br i1 %17, label %tailrecurse, label %18

18:                                               ; preds = %8
  %19 = tail call noundef double @_Z5func1d(double noundef %11)
  %20 = tail call noundef double @_Z5func1d(double noundef %14)
  %21 = fcmp ogt double %19, %20
  %.tr. = select i1 %21, double %.tr, double %11
  br label %tailrecurse.outer
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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" }

!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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass