; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes (R3CatmullRomSpline)

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

%class.R3CatmullRomSpline = type { %class.R3Polyline, double }
%class.R3Polyline = type { %class.R3Curve, ptr, ptr, ptr, i32, %class.R3Box }
%class.R3Curve = type { %class.R3Shape }
%class.R3Shape = type { ptr }
%class.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Point = type { [3 x 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZNK18R3CatmullRomSpline24BlendingWeightDerivativeEdi(ptr noundef nonnull align 8 dereferenceable(104) %0, double noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = load double, ptr %6, align 8, !tbaa !9
  %12 = load double, ptr %6, align 8, !tbaa !9
  %13 = fmul double %11, %12
  store double %13, ptr %8, align 8, !tbaa !9
  %14 = load i32, ptr %7, align 4, !tbaa !11
  switch i32 %14, label %69 [
    i32 -1, label %15
    i32 0, label %30
    i32 1, label %43
    i32 2, label %58
  ]

15:                                               ; preds = %3
  %16 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = fneg double %17
  %19 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %20 = load double, ptr %19, align 8, !tbaa !13
  %21 = fmul double 4.000000e+00, %20
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = call double @llvm.fmuladd.f64(double %21, double %22, double %18)
  %24 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = fmul double 3.000000e+00, %25
  %27 = load double, ptr %8, align 8, !tbaa !9
  %28 = fneg double %26
  %29 = call double @llvm.fmuladd.f64(double %28, double %27, double %23)
  store double %29, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %70

30:                                               ; preds = %3
  %31 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %32 = load double, ptr %31, align 8, !tbaa !13
  %33 = fsub double %32, 3.000000e+00
  %34 = fmul double 2.000000e+00, %33
  %35 = load double, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = fsub double 2.000000e+00, %37
  %39 = fmul double 3.000000e+00, %38
  %40 = load double, ptr %8, align 8, !tbaa !9
  %41 = fmul double %39, %40
  %42 = call double @llvm.fmuladd.f64(double %34, double %35, double %41)
  store double %42, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %70

43:                                               ; preds = %3
  %44 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %45 = load double, ptr %44, align 8, !tbaa !13
  %46 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %47 = load double, ptr %46, align 8, !tbaa !13
  %48 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %47, double 3.000000e+00)
  %49 = fmul double 2.000000e+00, %48
  %50 = load double, ptr %6, align 8, !tbaa !9
  %51 = call double @llvm.fmuladd.f64(double %49, double %50, double %45)
  %52 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %53 = load double, ptr %52, align 8, !tbaa !13
  %54 = fsub double %53, 2.000000e+00
  %55 = fmul double 3.000000e+00, %54
  %56 = load double, ptr %8, align 8, !tbaa !9
  %57 = call double @llvm.fmuladd.f64(double %55, double %56, double %51)
  store double %57, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %70

58:                                               ; preds = %3
  %59 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %60 = load double, ptr %59, align 8, !tbaa !13
  %61 = fmul double -2.000000e+00, %60
  %62 = load double, ptr %6, align 8, !tbaa !9
  %63 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %10, i32 0, i32 1
  %64 = load double, ptr %63, align 8, !tbaa !13
  %65 = fmul double 3.000000e+00, %64
  %66 = load double, ptr %8, align 8, !tbaa !9
  %67 = fmul double %65, %66
  %68 = call double @llvm.fmuladd.f64(double %61, double %62, double %67)
  store double %68, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %70

69:                                               ; preds = %3
  store double 0.000000e+00, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %70

70:                                               ; preds = %69, %58, %43, %30, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %71 = load double, ptr %4, align 8
  ret double %71
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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++ 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 96}
!14 = !{!"_ZTS18R3CatmullRomSpline", !15, i64 0, !10, i64 96}
!15 = !{!"_ZTS10R3Polyline", !16, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !18, i64 40}
!16 = !{!"_ZTS7R3Curve", !17, i64 0}
!17 = !{!"_ZTS7R3Shape"}
!18 = !{!"_ZTS5R3Box", !19, i64 0, !20, i64 8, !20, i64 32}
!19 = !{!"_ZTS7R3Solid", !17, i64 0}
!20 = !{!"_ZTS7R3Point", !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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef double @_ZNK18R3CatmullRomSpline24BlendingWeightDerivativeEdi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(104) %0, double noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = fmul double %1, %1
  switch i32 %2, label %38 [
    i32 -1, label %5
    i32 0, label %13
    i32 1, label %22
    i32 2, label %31
  ]

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = fneg double %7
  %9 = fmul double %7, 4.000000e+00
  %10 = tail call double @llvm.fmuladd.f64(double %9, double %1, double %8)
  %11 = fmul double %7, -3.000000e+00
  %12 = tail call double @llvm.fmuladd.f64(double %11, double %4, double %10)
  br label %38

13:                                               ; preds = %3
  %14 = getelementptr inbounds i8, ptr %0, i64 96
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fadd double %15, -3.000000e+00
  %17 = fmul double %16, 2.000000e+00
  %18 = fsub double 2.000000e+00, %15
  %19 = fmul double %18, 3.000000e+00
  %20 = fmul double %4, %19
  %21 = tail call double @llvm.fmuladd.f64(double %17, double %1, double %20)
  br label %38

22:                                               ; preds = %3
  %23 = getelementptr inbounds i8, ptr %0, i64 96
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = tail call double @llvm.fmuladd.f64(double %24, double -2.000000e+00, double 3.000000e+00)
  %26 = fmul double %25, 2.000000e+00
  %27 = tail call double @llvm.fmuladd.f64(double %26, double %1, double %24)
  %28 = fadd double %24, -2.000000e+00
  %29 = fmul double %28, 3.000000e+00
  %30 = tail call double @llvm.fmuladd.f64(double %29, double %4, double %27)
  br label %38

31:                                               ; preds = %3
  %32 = getelementptr inbounds i8, ptr %0, i64 96
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fmul double %33, -2.000000e+00
  %35 = fmul double %33, 3.000000e+00
  %36 = fmul double %4, %35
  %37 = tail call double @llvm.fmuladd.f64(double %34, double %1, double %36)
  br label %38

38:                                               ; preds = %3, %31, %22, %13, %5
  %.0 = phi double [ %37, %31 ], [ %30, %22 ], [ %21, %13 ], [ %12, %5 ], [ 0.000000e+00, %3 ]
  ret double %.0
}

; 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: read) 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, !17, i64 96}
!6 = !{!"_ZTS18R3CatmullRomSpline", !7, i64 0, !17, i64 96}
!7 = !{!"_ZTS10R3Polyline", !8, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !14, i64 40}
!8 = !{!"_ZTS7R3Curve", !9, i64 0}
!9 = !{!"_ZTS7R3Shape"}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"int", !11, i64 0}
!14 = !{!"_ZTS5R3Box", !15, i64 0, !16, i64 8, !16, i64 32}
!15 = !{!"_ZTS7R3Solid", !9, i64 0}
!16 = !{!"_ZTS7R3Point", !11, i64 0}
!17 = !{!"double", !11, i64 0}


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