; 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 @_ZNK18R3CatmullRomSpline14BlendingWeightEdi(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 double, align 8
  %10 = 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
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %12 = load double, ptr %6, align 8, !tbaa !9
  %13 = load double, ptr %6, align 8, !tbaa !9
  %14 = fmul double %12, %13
  store double %14, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %15 = load double, ptr %6, align 8, !tbaa !9
  %16 = load double, ptr %8, align 8, !tbaa !9
  %17 = fmul double %15, %16
  store double %17, ptr %9, align 8, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !11
  switch i32 %18, label %71 [
    i32 -1, label %19
    i32 0, label %35
    i32 1, label %46
    i32 2, label %61
  ]

19:                                               ; preds = %3
  %20 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %11, i32 0, i32 1
  %21 = load double, ptr %20, align 8, !tbaa !13
  %22 = fneg double %21
  %23 = load double, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %11, i32 0, i32 1
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = fmul double 2.000000e+00, %25
  %27 = load double, ptr %8, align 8, !tbaa !9
  %28 = fmul double %26, %27
  %29 = call double @llvm.fmuladd.f64(double %22, double %23, double %28)
  %30 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %11, i32 0, i32 1
  %31 = load double, ptr %30, align 8, !tbaa !13
  %32 = load double, ptr %9, align 8, !tbaa !9
  %33 = fneg double %31
  %34 = call double @llvm.fmuladd.f64(double %33, double %32, double %29)
  store double %34, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %72

35:                                               ; preds = %3
  %36 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %11, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = fsub double %37, 3.000000e+00
  %39 = load double, ptr %8, align 8, !tbaa !9
  %40 = call double @llvm.fmuladd.f64(double %38, double %39, double 1.000000e+00)
  %41 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %11, i32 0, i32 1
  %42 = load double, ptr %41, align 8, !tbaa !13
  %43 = fsub double 2.000000e+00, %42
  %44 = load double, ptr %9, align 8, !tbaa !9
  %45 = call double @llvm.fmuladd.f64(double %43, double %44, double %40)
  store double %45, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %72

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

61:                                               ; preds = %3
  %62 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %11, i32 0, i32 1
  %63 = load double, ptr %62, align 8, !tbaa !13
  %64 = fneg double %63
  %65 = load double, ptr %8, align 8, !tbaa !9
  %66 = getelementptr inbounds %class.R3CatmullRomSpline, ptr %11, i32 0, i32 1
  %67 = load double, ptr %66, align 8, !tbaa !13
  %68 = load double, ptr %9, align 8, !tbaa !9
  %69 = fmul double %67, %68
  %70 = call double @llvm.fmuladd.f64(double %64, double %65, double %69)
  store double %70, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %72

71:                                               ; preds = %3
  store double 0.000000e+00, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %72

72:                                               ; preds = %71, %61, %46, %35, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %73 = load double, ptr %4, align 8
  ret double %73
}

; 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 @_ZNK18R3CatmullRomSpline14BlendingWeightEdi(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
  %5 = fmul double %4, %1
  switch i32 %2, label %35 [
    i32 -1, label %6
    i32 0, label %14
    i32 1, label %21
    i32 2, label %29
  ]

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

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

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

29:                                               ; preds = %3
  %30 = getelementptr inbounds i8, ptr %0, i64 96
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fneg double %31
  %33 = fmul double %5, %31
  %34 = tail call double @llvm.fmuladd.f64(double %32, double %4, double %33)
  br label %35

35:                                               ; preds = %3, %29, %21, %14, %6
  %.0 = phi double [ %34, %29 ], [ %28, %21 ], [ %20, %14 ], [ %13, %6 ], [ 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