; LLVM IR from tivole/Numerary :: src/root.ll (ZN8numerary8Numerary14root_bisectionEPFddEddPdRKd)

; 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 uwtable
define dso_local noundef signext i16 @_ZN8numerary8Numerary14root_bisectionEPFddEddPdRKd(ptr noundef %0, double noundef %1, double noundef %2, ptr noundef %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #0 align 2 {
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store double %1, ptr %8, align 8, !tbaa !9
  store double %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load double, ptr %8, align 8, !tbaa !9
  %22 = call noundef double %20(double noundef %21)
  store double %22, ptr %12, align 8, !tbaa !9
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load double, ptr %9, align 8, !tbaa !9
  %25 = call noundef double %23(double noundef %24)
  store double %25, ptr %13, align 8, !tbaa !9
  %26 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %27 = sitofp i16 %26 to double
  store double %27, ptr %14, align 8, !tbaa !9
  %28 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %13)
  %29 = sitofp i16 %28 to double
  store double %29, ptr %15, align 8, !tbaa !9
  %30 = load double, ptr %14, align 8, !tbaa !9
  %31 = fcmp oeq double %30, 0.000000e+00
  br i1 %31, label %32, label %35

32:                                               ; preds = %5
  %33 = load double, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  store double %33, ptr %34, align 8, !tbaa !9
  store i16 1, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %97

35:                                               ; preds = %5
  %36 = load double, ptr %15, align 8, !tbaa !9
  %37 = fcmp oeq double %36, 0.000000e+00
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load double, ptr %9, align 8, !tbaa !9
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  store double %39, ptr %40, align 8, !tbaa !9
  store i16 1, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %97

41:                                               ; preds = %35
  %42 = load double, ptr %14, align 8, !tbaa !9
  %43 = load double, ptr %15, align 8, !tbaa !9
  %44 = fcmp oeq double %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i16 0, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %97

46:                                               ; preds = %41
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %93, %48
  %50 = load double, ptr %9, align 8, !tbaa !9
  %51 = load double, ptr %8, align 8, !tbaa !9
  %52 = fsub double %50, %51
  %53 = call double @llvm.fabs.f64(double %52)
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fcmp ogt double %53, %55
  br i1 %56, label %57, label %68

57:                                               ; preds = %49
  %58 = load double, ptr %9, align 8, !tbaa !9
  %59 = load double, ptr %8, align 8, !tbaa !9
  %60 = fsub double %58, %59
  %61 = call double @llvm.fabs.f64(double %60)
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = load double, ptr %8, align 8, !tbaa !9
  %65 = call double @llvm.fabs.f64(double %64)
  %66 = fmul double %63, %65
  %67 = fcmp ogt double %61, %66
  br label %68

68:                                               ; preds = %57, %49
  %69 = phi i1 [ false, %49 ], [ %67, %57 ]
  br i1 %69, label %70, label %94

70:                                               ; preds = %68
  %71 = load double, ptr %8, align 8, !tbaa !9
  %72 = load double, ptr %9, align 8, !tbaa !9
  %73 = fadd double %71, %72
  %74 = fdiv double %73, 2.000000e+00
  store double %74, ptr %16, align 8, !tbaa !9
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load double, ptr %16, align 8, !tbaa !9
  %77 = call noundef double %75(double noundef %76)
  store double %77, ptr %17, align 8, !tbaa !9
  %78 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %17)
  %79 = sitofp i16 %78 to double
  store double %79, ptr %18, align 8, !tbaa !9
  %80 = load double, ptr %14, align 8, !tbaa !9
  %81 = load double, ptr %18, align 8, !tbaa !9
  %82 = fcmp oeq double %80, %81
  br i1 %82, label %83, label %85

83:                                               ; preds = %70
  %84 = load double, ptr %16, align 8, !tbaa !9
  store double %84, ptr %8, align 8, !tbaa !9
  br label %93

85:                                               ; preds = %70
  %86 = load double, ptr %15, align 8, !tbaa !9
  %87 = load double, ptr %18, align 8, !tbaa !9
  %88 = fcmp oeq double %86, %87
  br i1 %88, label %89, label %91

89:                                               ; preds = %85
  %90 = load double, ptr %16, align 8, !tbaa !9
  store double %90, ptr %9, align 8, !tbaa !9
  br label %92

91:                                               ; preds = %85
  br label %94

92:                                               ; preds = %89
  br label %93

93:                                               ; preds = %92, %83
  br label %49, !llvm.loop !11

94:                                               ; preds = %91, %68
  %95 = load double, ptr %16, align 8, !tbaa !9
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  store double %95, ptr %96, align 8, !tbaa !9
  store i16 1, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %97

97:                                               ; preds = %94, %45, %38, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %98 = load i16, ptr %6, align 2
  ret i16 %98
}

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

declare noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8)) #2

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 uwtable
define dso_local noundef signext range(i16 0, 2) i16 @_ZN8numerary8Numerary14root_bisectionEPFddEddPdRKd(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 #0 align 2 {
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  %9 = tail call noundef double %0(double noundef %1)
  store double %9, ptr %6, align 8, !tbaa !5
  %10 = tail call noundef double %0(double noundef %2)
  store double %10, ptr %7, align 8, !tbaa !5
  %11 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %12 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %7)
  %13 = icmp eq i16 %11, 0
  br i1 %13, label %.sink.split, label %14

14:                                               ; preds = %5
  %15 = icmp eq i16 %12, 0
  br i1 %15, label %.sink.split, label %16

16:                                               ; preds = %14
  %17 = icmp eq i16 %11, %12
  br i1 %17, label %40, label %.preheader

.preheader:                                       ; preds = %16
  %18 = fsub double %2, %1
  %19 = call double @llvm.fabs.f64(double %18)
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = fcmp ogt double %19, %20
  br i1 %21, label %.lr.ph.preheader, label %.sink.split

.lr.ph.preheader:                                 ; preds = %.preheader
  %22 = call double @llvm.fabs.f64(double %1)
  %23 = fmul double %22, %20
  %24 = fcmp ogt double %19, %23
  br i1 %24, label %.lr.ph50, label %.sink.split

.lr.ph:                                           ; preds = %35
  %25 = call double @llvm.fabs.f64(double %.133)
  %26 = fmul double %25, %38
  %27 = fcmp ogt double %37, %26
  br i1 %27, label %.lr.ph50, label %.sink.split, !llvm.loop !9

.lr.ph50:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0344149 = phi double [ %.135, %.lr.ph ], [ %2, %.lr.ph.preheader ]
  %.0324248 = phi double [ %.133, %.lr.ph ], [ %1, %.lr.ph.preheader ]
  %28 = fadd double %.0344149, %.0324248
  %29 = fmul double %28, 5.000000e-01
  %30 = call noundef double %0(double noundef %29)
  store double %30, ptr %8, align 8, !tbaa !5
  %31 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %32 = icmp eq i16 %11, %31
  br i1 %32, label %35, label %33

33:                                               ; preds = %.lr.ph50
  %34 = icmp eq i16 %12, %31
  br i1 %34, label %35, label %.sink.split

35:                                               ; preds = %33, %.lr.ph50
  %.135 = phi double [ %.0344149, %.lr.ph50 ], [ %29, %33 ]
  %.133 = phi double [ %29, %.lr.ph50 ], [ %.0324248, %33 ]
  %36 = fsub double %.135, %.133
  %37 = call double @llvm.fabs.f64(double %36)
  %38 = load double, ptr %4, align 8, !tbaa !5
  %39 = fcmp ogt double %37, %38
  br i1 %39, label %.lr.ph, label %.sink.split, !llvm.loop !9

.sink.split:                                      ; preds = %.lr.ph, %33, %35, %.lr.ph.preheader, %.preheader, %14, %5
  %.1.sink = phi double [ %1, %5 ], [ %2, %14 ], [ undef, %.preheader ], [ undef, %.lr.ph.preheader ], [ %29, %35 ], [ %29, %33 ], [ %29, %.lr.ph ]
  store double %.1.sink, ptr %3, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %.sink.split, %16
  %.0 = phi i16 [ 0, %16 ], [ 1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret i16 %.0
}

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

declare noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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