; 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.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 double @CubicSpline_Eval(ptr noundef %0, double noundef %1, ptr noundef %2) #2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store ptr %8, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %14, %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %20, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 2, ptr %19, align 4, !tbaa !11
  store double 0x7FF8000000000000, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %52

20:                                               ; preds = %15
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.CubicSpline, ptr %23, i32 0, i32 0
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = fsub double %22, %25
  store double %26, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.CubicSpline, ptr %27, i32 0, i32 1
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.CubicSpline, ptr %30, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = load double, ptr %10, align 8, !tbaa !9
  %34 = call double @llvm.fmuladd.f64(double %32, double %33, double %29)
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.CubicSpline, ptr %35, i32 0, i32 3
  %37 = load double, ptr %36, align 8, !tbaa !17
  %38 = load double, ptr %10, align 8, !tbaa !9
  %39 = fmul double %37, %38
  %40 = load double, ptr %10, align 8, !tbaa !9
  %41 = call double @llvm.fmuladd.f64(double %39, double %40, double %34)
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.CubicSpline, ptr %42, i32 0, i32 4
  %44 = load double, ptr %43, align 8, !tbaa !18
  %45 = load double, ptr %10, align 8, !tbaa !9
  %46 = fmul double %44, %45
  %47 = load double, ptr %10, align 8, !tbaa !9
  %48 = fmul double %46, %47
  %49 = load double, ptr %10, align 8, !tbaa !9
  %50 = call double @llvm.fmuladd.f64(double %48, double %49, double %41)
  store double %50, ptr %11, align 8, !tbaa !9
  %51 = load double, ptr %11, align 8, !tbaa !9
  store double %51, ptr %4, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %52

52:                                               ; preds = %20, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %53 = load double, ptr %4, align 8
  ret double %53
}

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 }

!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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"CubicSpline", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !10, i64 24}
!18 = !{!14, !10, 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"

; 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: readwrite) uwtable
define dso_local double @CubicSpline_Eval(ptr noundef readonly %0, double noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %2, null
  %.not19 = icmp eq ptr %0, null
  br i1 %.not19, label %4, label %5

4:                                                ; preds = %3
  br i1 %.not, label %.cont, label %.else

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

5:                                                ; preds = %3
  br i1 %.not, label %.cont20, label %.else22

.else22:                                          ; preds = %5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %.cont20

.cont20:                                          ; preds = %5, %.else22
  %6 = load double, ptr %0, align 8, !tbaa !9
  %7 = fsub double %1, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load double, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !13
  %12 = tail call double @llvm.fmuladd.f64(double %11, double %7, double %9)
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load double, ptr %13, align 8, !tbaa !14
  %15 = fmul double %7, %14
  %16 = tail call double @llvm.fmuladd.f64(double %15, double %7, double %12)
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load double, ptr %17, align 8, !tbaa !15
  %19 = fmul double %7, %18
  %20 = fmul double %7, %19
  %21 = tail call double @llvm.fmuladd.f64(double %20, double %7, double %16)
  br label %.cont

.cont:                                            ; preds = %.else, %4, %.cont20
  %.0 = phi double [ %21, %.cont20 ], [ 0x7FF8000000000000, %4 ], [ 0x7FF8000000000000, %.else ]
  ret double %.0
}

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

!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 = !{!10, !11, i64 24}
!15 = !{!10, !11, i64 32}


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