; LLVM IR from bjack205/altro :: src/linesearch (cubicspline)

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, 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: nounwind uwtable
define dso_local i32 @QuadraticFormula(ptr noundef %0, ptr noundef %1, double noundef %2, double noundef %3, double noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store double %2, ptr %9, align 8, !tbaa !9
  store double %3, ptr %10, align 8, !tbaa !9
  store double %4, ptr %11, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %5
  store i32 2, ptr %6, align 4
  br label %66

18:                                               ; preds = %5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 2, ptr %6, align 4
  br label %66

22:                                               ; preds = %18
  %23 = load double, ptr %9, align 8, !tbaa !9
  %24 = call double @llvm.fabs.f64(double %23)
  %25 = fcmp olt double %24, 0x3EB0C6F7A0B5ED8D
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  store i32 6, ptr %6, align 4
  br label %66

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %28 = load double, ptr %10, align 8, !tbaa !9
  %29 = load double, ptr %10, align 8, !tbaa !9
  %30 = load double, ptr %9, align 8, !tbaa !9
  %31 = fmul double 4.000000e+00, %30
  %32 = load double, ptr %11, align 8, !tbaa !9
  %33 = fmul double %31, %32
  %34 = fneg double %33
  %35 = call double @llvm.fmuladd.f64(double %28, double %29, double %34)
  store double %35, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %36 = load double, ptr %12, align 8, !tbaa !9
  %37 = call double @llvm.fabs.f64(double %36)
  %38 = fcmp olt double %37, 0x3EB0C6F7A0B5ED8D
  br i1 %38, label %39, label %40

39:                                               ; preds = %27
  store double 0.000000e+00, ptr %13, align 8, !tbaa !9
  br label %48

40:                                               ; preds = %27
  %41 = load double, ptr %12, align 8, !tbaa !9
  %42 = fcmp olt double %41, 0.000000e+00
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 4, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %65

44:                                               ; preds = %40
  %45 = load double, ptr %12, align 8, !tbaa !9
  %46 = call double @sqrt(double noundef %45) #4
  store double %46, ptr %13, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %44
  br label %48

48:                                               ; preds = %47, %39
  %49 = load double, ptr %10, align 8, !tbaa !9
  %50 = fneg double %49
  %51 = load double, ptr %13, align 8, !tbaa !9
  %52 = fadd double %50, %51
  %53 = load double, ptr %9, align 8, !tbaa !9
  %54 = fmul double 2.000000e+00, %53
  %55 = fdiv double %52, %54
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store double %55, ptr %56, align 8, !tbaa !9
  %57 = load double, ptr %10, align 8, !tbaa !9
  %58 = fneg double %57
  %59 = load double, ptr %13, align 8, !tbaa !9
  %60 = fsub double %58, %59
  %61 = load double, ptr %9, align 8, !tbaa !9
  %62 = fmul double 2.000000e+00, %61
  %63 = fdiv double %60, %62
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  store double %63, ptr %64, align 8, !tbaa !9
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %65

65:                                               ; preds = %48, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %66

66:                                               ; preds = %65, %26, %21, %17
  %67 = load i32, ptr %6, align 4
  ret i32 %67
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !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"

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write) uwtable
define dso_local range(i32 0, 7) i32 @QuadraticFormula(ptr noundef writeonly %0, ptr noundef writeonly %1, double noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  %.not22 = icmp eq ptr %1, null
  %or.cond = or i1 %.not, %.not22
  br i1 %or.cond, label %26, label %6

6:                                                ; preds = %5
  %7 = tail call double @llvm.fabs.f64(double %2)
  %8 = fcmp olt double %7, 0x3EB0C6F7A0B5ED8D
  br i1 %8, label %26, label %9

9:                                                ; preds = %6
  %10 = fmul double %2, -4.000000e+00
  %11 = fmul double %10, %4
  %12 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %11)
  %13 = tail call double @llvm.fabs.f64(double %12)
  %14 = fcmp olt double %13, 0x3EB0C6F7A0B5ED8D
  br i1 %14, label %19, label %15

15:                                               ; preds = %9
  %16 = fcmp olt double %12, 0.000000e+00
  br i1 %16, label %26, label %17

17:                                               ; preds = %15
  %18 = tail call double @sqrt(double noundef %12) #3
  br label %19

19:                                               ; preds = %9, %17
  %.0 = phi double [ %18, %17 ], [ 0.000000e+00, %9 ]
  %20 = fneg double %3
  %21 = fsub double %.0, %3
  %22 = fmul double %2, 2.000000e+00
  %23 = fdiv double %21, %22
  store double %23, ptr %0, align 8, !tbaa !5
  %24 = fsub double %20, %.0
  %25 = fdiv double %24, %22
  store double %25, ptr %1, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %19, %15, %6, %5
  %.1 = phi i32 [ 2, %5 ], [ 6, %6 ], [ 0, %19 ], [ 4, %15 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) 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 = { mustprogress nofree nounwind willreturn memory(write) "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass