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

; 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

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

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

; 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 @_ZN8numerary8Numerary11root_secantEPFddEddPdRKd(ptr noundef %0, double noundef %1, double noundef %2, ptr noundef %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #3 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 = load double, ptr %15, align 8, !tbaa !9
  %32 = fcmp oeq double %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %5
  store i16 0, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %144

34:                                               ; preds = %5
  br label %35

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

43:                                               ; preds = %35
  %44 = load double, ptr %9, align 8, !tbaa !9
  %45 = load double, ptr %8, align 8, !tbaa !9
  %46 = fsub double %44, %45
  %47 = call double @llvm.fabs.f64(double %46)
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load double, ptr %48, align 8, !tbaa !9
  %50 = load double, ptr %8, align 8, !tbaa !9
  %51 = call double @llvm.fabs.f64(double %50)
  %52 = fmul double %49, %51
  %53 = fcmp ogt double %47, %52
  br label %54

54:                                               ; preds = %43, %35
  %55 = phi i1 [ false, %35 ], [ %53, %43 ]
  br i1 %55, label %56, label %143

56:                                               ; preds = %54
  %57 = load double, ptr %12, align 8, !tbaa !9
  %58 = call double @llvm.fabs.f64(double %57)
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = fcmp olt double %58, %60
  br i1 %61, label %62, label %65

62:                                               ; preds = %56
  %63 = load double, ptr %8, align 8, !tbaa !9
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  store double %63, ptr %64, align 8, !tbaa !9
  store i16 1, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %144

65:                                               ; preds = %56
  %66 = load double, ptr %13, align 8, !tbaa !9
  %67 = call double @llvm.fabs.f64(double %66)
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load double, ptr %68, align 8, !tbaa !9
  %70 = fcmp olt double %67, %69
  br i1 %70, label %71, label %74

71:                                               ; preds = %65
  %72 = load double, ptr %9, align 8, !tbaa !9
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  store double %72, ptr %73, align 8, !tbaa !9
  store i16 1, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %144

74:                                               ; preds = %65
  br label %75

75:                                               ; preds = %74
  %76 = load double, ptr %9, align 8, !tbaa !9
  %77 = load double, ptr %13, align 8, !tbaa !9
  %78 = load double, ptr %9, align 8, !tbaa !9
  %79 = load double, ptr %8, align 8, !tbaa !9
  %80 = fsub double %78, %79
  %81 = fmul double %77, %80
  %82 = load double, ptr %13, align 8, !tbaa !9
  %83 = load double, ptr %12, align 8, !tbaa !9
  %84 = fsub double %82, %83
  %85 = fdiv double %81, %84
  %86 = fsub double %76, %85
  store double %86, ptr %16, align 8, !tbaa !9
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = load double, ptr %16, align 8, !tbaa !9
  %89 = call noundef double %87(double noundef %88)
  store double %89, ptr %17, align 8, !tbaa !9
  %90 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %17)
  %91 = sitofp i16 %90 to double
  store double %91, ptr %18, align 8, !tbaa !9
  %92 = load double, ptr %12, align 8, !tbaa !9
  %93 = load double, ptr %13, align 8, !tbaa !9
  %94 = fcmp ogt double %92, %93
  br i1 %94, label %95, label %116

95:                                               ; preds = %75
  %96 = load double, ptr %18, align 8, !tbaa !9
  %97 = fcmp ogt double %96, 0.000000e+00
  br i1 %97, label %98, label %101

98:                                               ; preds = %95
  %99 = load double, ptr %16, align 8, !tbaa !9
  store double %99, ptr %8, align 8, !tbaa !9
  %100 = load double, ptr %17, align 8, !tbaa !9
  store double %100, ptr %12, align 8, !tbaa !9
  br label %115

101:                                              ; preds = %95
  %102 = load double, ptr %18, align 8, !tbaa !9
  %103 = fcmp olt double %102, 0.000000e+00
  br i1 %103, label %104, label %107

104:                                              ; preds = %101
  %105 = load double, ptr %16, align 8, !tbaa !9
  store double %105, ptr %9, align 8, !tbaa !9
  %106 = load double, ptr %17, align 8, !tbaa !9
  store double %106, ptr %13, align 8, !tbaa !9
  br label %114

107:                                              ; preds = %101
  %108 = load double, ptr %18, align 8, !tbaa !9
  %109 = fcmp oeq double %108, 0.000000e+00
  br i1 %109, label %110, label %113

110:                                              ; preds = %107
  %111 = load double, ptr %16, align 8, !tbaa !9
  %112 = load ptr, ptr %10, align 8, !tbaa !5
  store double %111, ptr %112, align 8, !tbaa !9
  store i16 1, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %144

113:                                              ; preds = %107
  br label %114

114:                                              ; preds = %113, %104
  br label %115

115:                                              ; preds = %114, %98
  br label %142

116:                                              ; preds = %75
  %117 = load double, ptr %12, align 8, !tbaa !9
  %118 = load double, ptr %13, align 8, !tbaa !9
  %119 = fcmp olt double %117, %118
  br i1 %119, label %120, label %141

120:                                              ; preds = %116
  %121 = load double, ptr %18, align 8, !tbaa !9
  %122 = fcmp ogt double %121, 0.000000e+00
  br i1 %122, label %123, label %126

123:                                              ; preds = %120
  %124 = load double, ptr %16, align 8, !tbaa !9
  store double %124, ptr %9, align 8, !tbaa !9
  %125 = load double, ptr %17, align 8, !tbaa !9
  store double %125, ptr %13, align 8, !tbaa !9
  br label %140

126:                                              ; preds = %120
  %127 = load double, ptr %18, align 8, !tbaa !9
  %128 = fcmp olt double %127, 0.000000e+00
  br i1 %128, label %129, label %132

129:                                              ; preds = %126
  %130 = load double, ptr %16, align 8, !tbaa !9
  store double %130, ptr %8, align 8, !tbaa !9
  %131 = load double, ptr %17, align 8, !tbaa !9
  store double %131, ptr %12, align 8, !tbaa !9
  br label %139

132:                                              ; preds = %126
  %133 = load double, ptr %18, align 8, !tbaa !9
  %134 = fcmp oeq double %133, 0.000000e+00
  br i1 %134, label %135, label %138

135:                                              ; preds = %132
  %136 = load double, ptr %16, align 8, !tbaa !9
  %137 = load ptr, ptr %10, align 8, !tbaa !5
  store double %136, ptr %137, align 8, !tbaa !9
  store i16 1, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %144

138:                                              ; preds = %132
  br label %139

139:                                              ; preds = %138, %129
  br label %140

140:                                              ; preds = %139, %123
  br label %141

141:                                              ; preds = %140, %116
  br label %142

142:                                              ; preds = %141, %115
  br label %35, !llvm.loop !11

143:                                              ; preds = %54
  store i16 0, ptr %6, align 2
  store i32 1, ptr %19, align 4
  br label %144

144:                                              ; preds = %143, %135, %110, %71, %62, %33
  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
  %145 = load i16, ptr %6, align 2
  ret i16 %145
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress 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 range(i16 0, 2) i16 @_ZN8numerary8Numerary11root_secantEPFddEddPdRKd(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 #3 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, %12
  br i1 %13, label %.critedge, label %.preheader

.preheader:                                       ; preds = %5
  %14 = fsub double %2, %1
  %15 = call double @llvm.fabs.f64(double %14)
  %16 = load double, ptr %4, align 8, !tbaa !5
  %17 = fcmp ogt double %15, %16
  br i1 %17, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader, %60
  %18 = phi double [ %63, %60 ], [ %16, %.preheader ]
  %19 = phi double [ %62, %60 ], [ %15, %.preheader ]
  %20 = phi double [ %61, %60 ], [ %14, %.preheader ]
  %.03856 = phi double [ %.1, %60 ], [ %1, %.preheader ]
  %.03955 = phi double [ %.140, %60 ], [ %2, %.preheader ]
  %21 = call double @llvm.fabs.f64(double %.03856)
  %22 = fmul double %18, %21
  %23 = fcmp ogt double %19, %22
  br i1 %23, label %24, label %.critedge

24:                                               ; preds = %.lr.ph
  %25 = load double, ptr %6, align 8, !tbaa !5
  %26 = call double @llvm.fabs.f64(double %25)
  %27 = fcmp olt double %26, %18
  br i1 %27, label %.critedge.sink.split, label %28

28:                                               ; preds = %24
  %29 = load double, ptr %7, align 8, !tbaa !5
  %30 = call double @llvm.fabs.f64(double %29)
  %31 = fcmp olt double %30, %18
  br i1 %31, label %.critedge.sink.split, label %32

32:                                               ; preds = %28
  %33 = fmul double %20, %29
  %34 = fsub double %29, %25
  %35 = fdiv double %33, %34
  %36 = fsub double %.03955, %35
  %37 = call noundef double %0(double noundef %36)
  store double %37, ptr %8, align 8, !tbaa !5
  %38 = call noundef signext i16 @_ZN8numerary8Numerary3sgnERKd(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %39 = load double, ptr %6, align 8, !tbaa !5
  %40 = load double, ptr %7, align 8, !tbaa !5
  %41 = fcmp ogt double %39, %40
  br i1 %41, label %42, label %50

42:                                               ; preds = %32
  %43 = icmp sgt i16 %38, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %42
  %45 = load double, ptr %8, align 8, !tbaa !5
  store double %45, ptr %6, align 8, !tbaa !5
  br label %60

46:                                               ; preds = %42
  %47 = icmp slt i16 %38, 0
  br i1 %47, label %48, label %.critedge.sink.split

48:                                               ; preds = %46
  %49 = load double, ptr %8, align 8, !tbaa !5
  store double %49, ptr %7, align 8, !tbaa !5
  br label %60

50:                                               ; preds = %32
  %51 = fcmp olt double %39, %40
  br i1 %51, label %52, label %60

52:                                               ; preds = %50
  %53 = icmp sgt i16 %38, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %52
  %55 = load double, ptr %8, align 8, !tbaa !5
  store double %55, ptr %7, align 8, !tbaa !5
  br label %60

56:                                               ; preds = %52
  %57 = icmp slt i16 %38, 0
  br i1 %57, label %58, label %.critedge.sink.split

58:                                               ; preds = %56
  %59 = load double, ptr %8, align 8, !tbaa !5
  store double %59, ptr %6, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %50, %58, %54, %44, %48
  %.140 = phi double [ %.03955, %44 ], [ %36, %48 ], [ %36, %54 ], [ %.03955, %58 ], [ %.03955, %50 ]
  %.1 = phi double [ %36, %44 ], [ %.03856, %48 ], [ %.03856, %54 ], [ %36, %58 ], [ %.03856, %50 ]
  %61 = fsub double %.140, %.1
  %62 = call double @llvm.fabs.f64(double %61)
  %63 = load double, ptr %4, align 8, !tbaa !5
  %64 = fcmp ogt double %62, %63
  br i1 %64, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge.sink.split:                             ; preds = %56, %46, %28, %24
  %.lcssa.sink = phi double [ %.03856, %24 ], [ %.03955, %28 ], [ %36, %46 ], [ %36, %56 ]
  store double %.lcssa.sink, ptr %3, align 8, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %60, %.lr.ph, %.critedge.sink.split, %.preheader, %5
  %.0 = phi i16 [ 0, %5 ], [ 0, %.preheader ], [ 1, %.critedge.sink.split ], [ 0, %.lr.ph ], [ 0, %60 ]
  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
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass