; LLVM IR from tivole/Numerary :: src/maximum.ll (ZN8numerary8Numerary20maximum_golden_ratioEPFddEddPdRKd)

; 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: 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 speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef signext i16 @_ZN8numerary8Numerary20maximum_golden_ratioEPFddEddPdRKd(ptr noundef %0, double noundef %1, double noundef %2, ptr noundef %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #2 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !9
  store double %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store double 0x3FF9E3779B97F4A8, ptr %15, align 8, !tbaa !9
  %16 = load double, ptr %8, align 8, !tbaa !9
  %17 = load double, ptr %8, align 8, !tbaa !9
  %18 = load double, ptr %7, align 8, !tbaa !9
  %19 = fsub double %17, %18
  %20 = fdiv double %19, 0x3FF9E3779B97F4A8
  %21 = fsub double %16, %20
  store double %21, ptr %11, align 8, !tbaa !9
  %22 = load double, ptr %7, align 8, !tbaa !9
  %23 = load double, ptr %8, align 8, !tbaa !9
  %24 = load double, ptr %7, align 8, !tbaa !9
  %25 = fsub double %23, %24
  %26 = fdiv double %25, 0x3FF9E3779B97F4A8
  %27 = fadd double %22, %26
  store double %27, ptr %12, align 8, !tbaa !9
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load double, ptr %11, align 8, !tbaa !9
  %30 = call noundef double %28(double noundef %29)
  store double %30, ptr %13, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load double, ptr %12, align 8, !tbaa !9
  %33 = call noundef double %31(double noundef %32)
  store double %33, ptr %14, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %72, %5
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = load double, ptr %7, align 8, !tbaa !9
  %37 = fsub double %35, %36
  %38 = call double @llvm.fabs.f64(double %37)
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = fcmp ogt double %38, %40
  br i1 %41, label %42, label %73

42:                                               ; preds = %34
  %43 = load double, ptr %13, align 8, !tbaa !9
  %44 = load double, ptr %14, align 8, !tbaa !9
  %45 = fcmp ole double %43, %44
  br i1 %45, label %46, label %59

46:                                               ; preds = %42
  %47 = load double, ptr %11, align 8, !tbaa !9
  store double %47, ptr %7, align 8, !tbaa !9
  %48 = load double, ptr %12, align 8, !tbaa !9
  store double %48, ptr %11, align 8, !tbaa !9
  %49 = load double, ptr %14, align 8, !tbaa !9
  store double %49, ptr %13, align 8, !tbaa !9
  %50 = load double, ptr %7, align 8, !tbaa !9
  %51 = load double, ptr %8, align 8, !tbaa !9
  %52 = load double, ptr %7, align 8, !tbaa !9
  %53 = fsub double %51, %52
  %54 = fdiv double %53, 0x3FF9E3779B97F4A8
  %55 = fadd double %50, %54
  store double %55, ptr %12, align 8, !tbaa !9
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load double, ptr %12, align 8, !tbaa !9
  %58 = call noundef double %56(double noundef %57)
  store double %58, ptr %14, align 8, !tbaa !9
  br label %72

59:                                               ; preds = %42
  %60 = load double, ptr %12, align 8, !tbaa !9
  store double %60, ptr %8, align 8, !tbaa !9
  %61 = load double, ptr %11, align 8, !tbaa !9
  store double %61, ptr %12, align 8, !tbaa !9
  %62 = load double, ptr %13, align 8, !tbaa !9
  store double %62, ptr %14, align 8, !tbaa !9
  %63 = load double, ptr %8, align 8, !tbaa !9
  %64 = load double, ptr %8, align 8, !tbaa !9
  %65 = load double, ptr %7, align 8, !tbaa !9
  %66 = fsub double %64, %65
  %67 = fdiv double %66, 0x3FF9E3779B97F4A8
  %68 = fsub double %63, %67
  store double %68, ptr %11, align 8, !tbaa !9
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load double, ptr %11, align 8, !tbaa !9
  %71 = call noundef double %69(double noundef %70)
  store double %71, ptr %13, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %59, %46
  br label %34, !llvm.loop !11

73:                                               ; preds = %34
  %74 = load double, ptr %7, align 8, !tbaa !9
  %75 = load double, ptr %8, align 8, !tbaa !9
  %76 = fadd double %74, %75
  %77 = fdiv double %76, 2.000000e+00
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  store double %77, ptr %78, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret i16 1
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef signext i16 @_ZN8numerary8Numerary20maximum_golden_ratioEPFddEddPdRKd(ptr nocapture noundef readonly %0, double noundef %1, double noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %4) local_unnamed_addr #1 align 2 {
  %6 = fsub double %2, %1
  %7 = fdiv double %6, 0x3FF9E3779B97F4A8
  %8 = fsub double %2, %7
  %9 = fadd double %7, %1
  %10 = tail call noundef double %0(double noundef %8)
  %11 = tail call noundef double %0(double noundef %9)
  %12 = tail call double @llvm.fabs.f64(double %6)
  %13 = load double, ptr %4, align 8, !tbaa !5
  %14 = fcmp ogt double %12, %13
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %26
  %.049 = phi double [ %.1, %26 ], [ %1, %5 ]
  %.03448 = phi double [ %.135, %26 ], [ %11, %5 ]
  %.03647 = phi double [ %.137, %26 ], [ %10, %5 ]
  %.03846 = phi double [ %.139, %26 ], [ %9, %5 ]
  %.04045 = phi double [ %.141, %26 ], [ %8, %5 ]
  %.04244 = phi double [ %.143, %26 ], [ %2, %5 ]
  %15 = fcmp ugt double %.03647, %.03448
  br i1 %15, label %21, label %16

16:                                               ; preds = %.lr.ph
  %17 = fsub double %.04244, %.04045
  %18 = fdiv double %17, 0x3FF9E3779B97F4A8
  %19 = fadd double %.04045, %18
  %20 = tail call noundef double %0(double noundef %19)
  br label %26

21:                                               ; preds = %.lr.ph
  %22 = fsub double %.03846, %.049
  %23 = fdiv double %22, 0x3FF9E3779B97F4A8
  %24 = fsub double %.03846, %23
  %25 = tail call noundef double %0(double noundef %24)
  br label %26

26:                                               ; preds = %21, %16
  %.pre-phi = phi double [ %22, %21 ], [ %17, %16 ]
  %.143 = phi double [ %.03846, %21 ], [ %.04244, %16 ]
  %.141 = phi double [ %24, %21 ], [ %.03846, %16 ]
  %.139 = phi double [ %.04045, %21 ], [ %19, %16 ]
  %.137 = phi double [ %25, %21 ], [ %.03448, %16 ]
  %.135 = phi double [ %.03647, %21 ], [ %20, %16 ]
  %.1 = phi double [ %.049, %21 ], [ %.04045, %16 ]
  %27 = tail call double @llvm.fabs.f64(double %.pre-phi)
  %28 = load double, ptr %4, align 8, !tbaa !5
  %29 = fcmp ogt double %27, %28
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %26, %5
  %.042.lcssa = phi double [ %2, %5 ], [ %.143, %26 ]
  %.0.lcssa = phi double [ %1, %5 ], [ %.1, %26 ]
  %30 = fadd double %.042.lcssa, %.0.lcssa
  %31 = fmul double %30, 5.000000e-01
  store double %31, ptr %3, align 8, !tbaa !5
  ret i16 1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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" }

!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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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