; 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"

%struct.CubicSpline = type { double, double, double, double, double }

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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 void @CubicSpline_From3Points(ptr dead_on_unwind noalias writable sret(%struct.CubicSpline) align 8 %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, double noundef %6, double noundef %7, ptr noundef %8) #3 {
  %10 = alloca double, 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
  %16 = alloca double, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca i32, align 4
  %22 = alloca double, align 8
  %23 = alloca double, align 8
  %24 = alloca double, align 8
  %25 = alloca double, align 8
  %26 = alloca double, align 8
  %27 = alloca double, align 8
  %28 = alloca double, align 8
  store double %1, ptr %10, align 8, !tbaa !5
  store double %2, ptr %11, align 8, !tbaa !5
  store double %3, ptr %12, align 8, !tbaa !5
  store double %4, ptr %13, align 8, !tbaa !5
  store double %5, ptr %14, align 8, !tbaa !5
  store double %6, ptr %15, align 8, !tbaa !5
  store double %7, ptr %16, align 8, !tbaa !5
  store ptr %8, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %29 = load ptr, ptr %17, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %9
  store ptr %18, ptr %17, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %31, %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %33 = load double, ptr %13, align 8, !tbaa !5
  %34 = load double, ptr %10, align 8, !tbaa !5
  %35 = fsub double %33, %34
  store double %35, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %36 = load double, ptr %15, align 8, !tbaa !5
  %37 = load double, ptr %10, align 8, !tbaa !5
  %38 = fsub double %36, %37
  store double %38, ptr %20, align 8, !tbaa !5
  %39 = load double, ptr %19, align 8, !tbaa !5
  %40 = call double @llvm.fabs.f64(double %39)
  %41 = fcmp olt double %40, 0x3EB0C6F7A0B5ED8D
  br i1 %41, label %46, label %42

42:                                               ; preds = %32
  %43 = load double, ptr %20, align 8, !tbaa !5
  %44 = call double @llvm.fabs.f64(double %43)
  %45 = fcmp olt double %44, 0x3EB0C6F7A0B5ED8D
  br i1 %45, label %46, label %53

46:                                               ; preds = %42, %32
  %47 = load ptr, ptr %17, align 8, !tbaa !9
  store i32 9, ptr %47, align 4, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 8 %0, i8 0, i64 40, i1 false)
  %48 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 0
  store double 0x7FF8000000000000, ptr %48, align 8
  %49 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 1
  store double 0x7FF8000000000000, ptr %49, align 8
  %50 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 2
  store double 0x7FF8000000000000, ptr %50, align 8
  %51 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 3
  store double 0x7FF8000000000000, ptr %51, align 8
  %52 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 4
  store double 0x7FF8000000000000, ptr %52, align 8
  store i32 1, ptr %21, align 4
  br label %110

53:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %54 = load double, ptr %14, align 8, !tbaa !5
  %55 = load double, ptr %11, align 8, !tbaa !5
  %56 = fsub double %54, %55
  %57 = load double, ptr %19, align 8, !tbaa !5
  %58 = load double, ptr %19, align 8, !tbaa !5
  %59 = fmul double %57, %58
  %60 = fdiv double %56, %59
  %61 = load double, ptr %12, align 8, !tbaa !5
  %62 = load double, ptr %19, align 8, !tbaa !5
  %63 = fdiv double %61, %62
  %64 = fsub double %60, %63
  store double %64, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %65 = load double, ptr %16, align 8, !tbaa !5
  %66 = load double, ptr %11, align 8, !tbaa !5
  %67 = fsub double %65, %66
  %68 = load double, ptr %20, align 8, !tbaa !5
  %69 = load double, ptr %20, align 8, !tbaa !5
  %70 = fmul double %68, %69
  %71 = fdiv double %67, %70
  %72 = load double, ptr %12, align 8, !tbaa !5
  %73 = load double, ptr %20, align 8, !tbaa !5
  %74 = fdiv double %72, %73
  %75 = fsub double %71, %74
  store double %75, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #4
  %76 = load double, ptr %20, align 8, !tbaa !5
  %77 = load double, ptr %19, align 8, !tbaa !5
  %78 = fsub double %76, %77
  %79 = fdiv double 1.000000e+00, %78
  store double %79, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #4
  %80 = load double, ptr %11, align 8, !tbaa !5
  store double %80, ptr %25, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #4
  %81 = load double, ptr %12, align 8, !tbaa !5
  store double %81, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #4
  %82 = load double, ptr %22, align 8, !tbaa !5
  %83 = load double, ptr %19, align 8, !tbaa !5
  %84 = load double, ptr %24, align 8, !tbaa !5
  %85 = call double @llvm.fmuladd.f64(double %83, double %84, double 1.000000e+00)
  %86 = load double, ptr %23, align 8, !tbaa !5
  %87 = load double, ptr %19, align 8, !tbaa !5
  %88 = fmul double %86, %87
  %89 = load double, ptr %24, align 8, !tbaa !5
  %90 = fmul double %88, %89
  %91 = fneg double %90
  %92 = call double @llvm.fmuladd.f64(double %82, double %85, double %91)
  store double %92, ptr %27, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #4
  %93 = load double, ptr %22, align 8, !tbaa !5
  %94 = fneg double %93
  %95 = load double, ptr %24, align 8, !tbaa !5
  %96 = load double, ptr %23, align 8, !tbaa !5
  %97 = load double, ptr %24, align 8, !tbaa !5
  %98 = fmul double %96, %97
  %99 = call double @llvm.fmuladd.f64(double %94, double %95, double %98)
  store double %99, ptr %28, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 0
  %101 = load double, ptr %10, align 8, !tbaa !5
  store double %101, ptr %100, align 8, !tbaa !13
  %102 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 1
  %103 = load double, ptr %25, align 8, !tbaa !5
  store double %103, ptr %102, align 8, !tbaa !15
  %104 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 2
  %105 = load double, ptr %26, align 8, !tbaa !5
  store double %105, ptr %104, align 8, !tbaa !16
  %106 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 3
  %107 = load double, ptr %27, align 8, !tbaa !5
  store double %107, ptr %106, align 8, !tbaa !17
  %108 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 4
  %109 = load double, ptr %28, align 8, !tbaa !5
  store double %109, ptr %108, align 8, !tbaa !18
  store i32 1, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  br label %110

110:                                              ; preds = %53, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"CubicSpline", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !6, i64 16}
!17 = !{!14, !6, i64 24}
!18 = !{!14, !6, i64 32}


; 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"

%struct.CubicSpline = type { double, double, double, double, double }

; 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 norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @CubicSpline_From3Points(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.CubicSpline) align 8 %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, double noundef %6, double noundef %7, ptr noundef writeonly %8) local_unnamed_addr #1 {
  %10 = fsub double %4, %1
  %11 = fsub double %6, %1
  %12 = tail call double @llvm.fabs.f64(double %10)
  %13 = fcmp olt double %12, 0x3EB0C6F7A0B5ED8D
  %14 = tail call double @llvm.fabs.f64(double %11)
  %15 = fcmp olt double %14, 0x3EB0C6F7A0B5ED8D
  %or.cond = or i1 %13, %15
  br i1 %or.cond, label %16, label %17

16:                                               ; preds = %9
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %.cont, label %.else

.else:                                            ; preds = %16
  store i32 9, ptr %8, align 4, !tbaa !5
  br label %.cont

17:                                               ; preds = %9
  %18 = fsub double %5, %2
  %19 = fmul double %10, %10
  %20 = insertelement <2 x double> poison, double %3, i64 1
  %21 = insertelement <2 x double> %20, double %18, i64 0
  %22 = insertelement <2 x double> poison, double %19, i64 0
  %23 = insertelement <2 x double> %22, double %10, i64 1
  %24 = fdiv <2 x double> %21, %23
  %shift = shufflevector <2 x double> %24, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %25 = fsub <2 x double> %24, %shift
  %26 = extractelement <2 x double> %25, i64 0
  %27 = fsub double %7, %2
  %28 = fmul double %11, %11
  %29 = insertelement <2 x double> %20, double %27, i64 0
  %30 = insertelement <2 x double> poison, double %28, i64 0
  %31 = insertelement <2 x double> %30, double %11, i64 1
  %32 = fdiv <2 x double> %29, %31
  %shift48 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %33 = fsub <2 x double> %32, %shift48
  %34 = extractelement <2 x double> %33, i64 0
  %35 = fsub double %11, %10
  %36 = fdiv double 1.000000e+00, %35
  %37 = tail call double @llvm.fmuladd.f64(double %10, double %36, double 1.000000e+00)
  %38 = fneg double %34
  %39 = fmul double %10, %38
  %40 = fneg double %26
  %41 = insertelement <2 x double> poison, double %36, i64 0
  %42 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> zeroinitializer
  %43 = insertelement <2 x double> poison, double %39, i64 0
  %44 = shufflevector <2 x double> %43, <2 x double> %33, <2 x i32> <i32 0, i32 2>
  %45 = fmul <2 x double> %42, %44
  %46 = insertelement <2 x double> %25, double %36, i64 1
  %47 = insertelement <2 x double> poison, double %37, i64 0
  %48 = insertelement <2 x double> %47, double %40, i64 1
  %49 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %46, <2 x double> %48, <2 x double> %45)
  br label %.cont

.cont:                                            ; preds = %.else, %16, %17
  %.sink47 = phi double [ %1, %17 ], [ 0x7FF8000000000000, %16 ], [ 0x7FF8000000000000, %.else ]
  %.sink45 = phi double [ %2, %17 ], [ 0x7FF8000000000000, %16 ], [ 0x7FF8000000000000, %.else ]
  %.sink43 = phi double [ %3, %17 ], [ 0x7FF8000000000000, %16 ], [ 0x7FF8000000000000, %.else ]
  %50 = phi <2 x double> [ %49, %17 ], [ <double 0x7FF8000000000000, double 0x7FF8000000000000>, %16 ], [ <double 0x7FF8000000000000, double 0x7FF8000000000000>, %.else ]
  store double %.sink47, ptr %0, align 8
  %51 = getelementptr inbounds i8, ptr %0, i64 8
  store double %.sink45, ptr %51, align 8
  %52 = getelementptr inbounds i8, ptr %0, i64 16
  store double %.sink43, ptr %52, align 8
  %53 = getelementptr inbounds i8, ptr %0, i64 24
  store <2 x double> %50, ptr %53, align 8
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass