; 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: nounwind uwtable
define dso_local void @CubicSpline_From2Points(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, ptr noundef %7) #0 {
  %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 double, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca double, align 8
  %18 = alloca i32, align 4
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca double, align 8
  %22 = alloca double, align 8
  store double %1, ptr %9, align 8, !tbaa !5
  store double %2, ptr %10, align 8, !tbaa !5
  store double %3, ptr %11, align 8, !tbaa !5
  store double %4, ptr %12, align 8, !tbaa !5
  store double %5, ptr %13, align 8, !tbaa !5
  store double %6, ptr %14, align 8, !tbaa !5
  store ptr %7, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %23 = load ptr, ptr %15, align 8, !tbaa !9
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %8
  store ptr %16, ptr %15, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %25, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %27 = load double, ptr %12, align 8, !tbaa !5
  %28 = load double, ptr %9, align 8, !tbaa !5
  %29 = fsub double %27, %28
  store double %29, ptr %17, align 8, !tbaa !5
  %30 = load double, ptr %17, align 8, !tbaa !5
  %31 = call double @llvm.fabs.f64(double %30)
  %32 = fcmp olt double %31, 0x3EB0C6F7A0B5ED8D
  br i1 %32, label %33, label %40

33:                                               ; preds = %26
  %34 = load ptr, ptr %15, align 8, !tbaa !9
  store i32 9, ptr %34, align 4, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 8 %0, i8 0, i64 40, i1 false)
  %35 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 0
  store double 0x7FF8000000000000, ptr %35, align 8
  %36 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 1
  store double 0x7FF8000000000000, ptr %36, align 8
  %37 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 2
  store double 0x7FF8000000000000, ptr %37, align 8
  %38 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 3
  store double 0x7FF8000000000000, ptr %38, align 8
  %39 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 4
  store double 0x7FF8000000000000, ptr %39, align 8
  store i32 1, ptr %18, align 4
  br label %86

40:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %41 = load double, ptr %10, align 8, !tbaa !5
  store double %41, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %42 = load double, ptr %11, align 8, !tbaa !5
  store double %42, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %43 = load double, ptr %13, align 8, !tbaa !5
  %44 = load double, ptr %10, align 8, !tbaa !5
  %45 = fsub double %43, %44
  %46 = fmul double 3.000000e+00, %45
  %47 = load double, ptr %17, align 8, !tbaa !5
  %48 = load double, ptr %17, align 8, !tbaa !5
  %49 = fmul double %47, %48
  %50 = fdiv double %46, %49
  %51 = load double, ptr %14, align 8, !tbaa !5
  %52 = load double, ptr %11, align 8, !tbaa !5
  %53 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %52, double %51)
  %54 = load double, ptr %17, align 8, !tbaa !5
  %55 = fdiv double %53, %54
  %56 = fsub double %50, %55
  store double %56, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %57 = load double, ptr %14, align 8, !tbaa !5
  %58 = load double, ptr %11, align 8, !tbaa !5
  %59 = fadd double %57, %58
  %60 = load double, ptr %17, align 8, !tbaa !5
  %61 = load double, ptr %17, align 8, !tbaa !5
  %62 = fmul double %60, %61
  %63 = fdiv double %59, %62
  %64 = load double, ptr %13, align 8, !tbaa !5
  %65 = load double, ptr %10, align 8, !tbaa !5
  %66 = fsub double %64, %65
  %67 = fmul double 2.000000e+00, %66
  %68 = load double, ptr %17, align 8, !tbaa !5
  %69 = load double, ptr %17, align 8, !tbaa !5
  %70 = fmul double %68, %69
  %71 = load double, ptr %17, align 8, !tbaa !5
  %72 = fmul double %70, %71
  %73 = fdiv double %67, %72
  %74 = fsub double %63, %73
  store double %74, ptr %22, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 0
  %76 = load double, ptr %9, align 8, !tbaa !5
  store double %76, ptr %75, align 8, !tbaa !13
  %77 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 1
  %78 = load double, ptr %19, align 8, !tbaa !5
  store double %78, ptr %77, align 8, !tbaa !15
  %79 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 2
  %80 = load double, ptr %20, align 8, !tbaa !5
  store double %80, ptr %79, align 8, !tbaa !16
  %81 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 3
  %82 = load double, ptr %21, align 8, !tbaa !5
  store double %82, ptr %81, align 8, !tbaa !17
  %83 = getelementptr inbounds %struct.CubicSpline, ptr %0, i32 0, i32 4
  %84 = load double, ptr %22, align 8, !tbaa !5
  store double %84, ptr %83, align 8, !tbaa !18
  %85 = load ptr, ptr %15, align 8, !tbaa !9
  store i32 0, ptr %85, align 4, !tbaa !11
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  br label %86

86:                                               ; preds = %40, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  ret void
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @CubicSpline_From2Points(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, ptr noundef writeonly %7) local_unnamed_addr #0 {
  %.not = icmp eq ptr %7, null
  %9 = fsub double %4, %1
  %10 = tail call double @llvm.fabs.f64(double %9)
  %11 = fcmp olt double %10, 0x3EB0C6F7A0B5ED8D
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  br i1 %.not, label %.cont29, label %.else31

.else31:                                          ; preds = %12
  store i32 9, ptr %7, align 4, !tbaa !5
  br label %.cont29

.cont29:                                          ; preds = %12, %.else31
  store <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>, ptr %0, align 8
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>, ptr %13, align 8
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  store double 0x7FF8000000000000, ptr %14, align 8
  br label %.cont

15:                                               ; preds = %8
  %16 = fsub double %5, %2
  %17 = fmul double %16, 3.000000e+00
  %18 = fmul double %9, %9
  %19 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double %6)
  %20 = fadd double %3, %6
  %21 = fmul double %16, 2.000000e+00
  %22 = fmul double %9, %18
  store double %1, ptr %0, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  store double %2, ptr %23, align 8, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  store double %3, ptr %24, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  %26 = insertelement <2 x double> poison, double %17, i64 0
  %27 = insertelement <2 x double> %26, double %20, i64 1
  %28 = insertelement <2 x double> poison, double %18, i64 0
  %29 = shufflevector <2 x double> %28, <2 x double> poison, <2 x i32> zeroinitializer
  %30 = fdiv <2 x double> %27, %29
  %31 = insertelement <2 x double> poison, double %19, i64 0
  %32 = insertelement <2 x double> %31, double %21, i64 1
  %33 = insertelement <2 x double> poison, double %9, i64 0
  %34 = insertelement <2 x double> %33, double %22, i64 1
  %35 = fdiv <2 x double> %32, %34
  %36 = fsub <2 x double> %30, %35
  store <2 x double> %36, ptr %25, align 8, !tbaa !14
  br i1 %.not, label %.cont, label %.else

.else:                                            ; preds = %15
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %.cont

.cont:                                            ; preds = %.else, %15, %.cont29
  ret void
}

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

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

attributes #0 = { 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 #1 = { mustprogress 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"}
!9 = !{!10, !11, i64 0}
!10 = !{!"CubicSpline", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!11, !11, i64 0}


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