; LLVM IR from PyCee/NUS_library :: src/math (NUS_quaternion)

; 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.NUS_quaternion = type { double, double, double, double }

; Function Attrs: nounwind uwtable
declare dso_local void @nus_quaternion_build(ptr dead_on_unwind noalias writable sret(%struct.NUS_quaternion) align 8, double noundef, double noundef, double noundef, double noundef) #0

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @nus_quaternion_lerp(ptr dead_on_unwind noalias writable sret(%struct.NUS_quaternion) align 8 %0, ptr noundef byval(%struct.NUS_quaternion) align 8 %1, ptr noundef byval(%struct.NUS_quaternion) align 8 %2, double noundef %3) #0 {
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca %struct.NUS_quaternion, align 8
  store double %3, ptr %5, align 8, !tbaa !5
  %8 = load double, ptr %5, align 8, !tbaa !5
  %9 = fcmp ogt double %8, 1.000000e+00
  br i1 %9, label %10, label %11

10:                                               ; preds = %4
  br label %13

11:                                               ; preds = %4
  %12 = load double, ptr %5, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11, %10
  %14 = phi double [ 1.000000e+00, %10 ], [ %12, %11 ]
  store double %14, ptr %5, align 8, !tbaa !5
  %15 = load double, ptr %5, align 8, !tbaa !5
  %16 = fcmp olt double %15, 0.000000e+00
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  br label %20

18:                                               ; preds = %13
  %19 = load double, ptr %5, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %17
  %21 = phi double [ 0.000000e+00, %17 ], [ %19, %18 ]
  store double %21, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %22 = load double, ptr %5, align 8, !tbaa !5
  %23 = fsub double 1.000000e+00, %22
  store double %23, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 0
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = load double, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = load double, ptr %5, align 8, !tbaa !5
  %30 = fmul double %28, %29
  %31 = call double @llvm.fmuladd.f64(double %25, double %26, double %30)
  %32 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 1
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = load double, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 1
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = load double, ptr %5, align 8, !tbaa !5
  %38 = fmul double %36, %37
  %39 = call double @llvm.fmuladd.f64(double %33, double %34, double %38)
  %40 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 2
  %41 = load double, ptr %40, align 8, !tbaa !12
  %42 = load double, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 2
  %44 = load double, ptr %43, align 8, !tbaa !12
  %45 = load double, ptr %5, align 8, !tbaa !5
  %46 = fmul double %44, %45
  %47 = call double @llvm.fmuladd.f64(double %41, double %42, double %46)
  %48 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 3
  %49 = load double, ptr %48, align 8, !tbaa !13
  %50 = load double, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 3
  %52 = load double, ptr %51, align 8, !tbaa !13
  %53 = load double, ptr %5, align 8, !tbaa !5
  %54 = fmul double %52, %53
  %55 = call double @llvm.fmuladd.f64(double %49, double %50, double %54)
  call void @nus_quaternion_build(ptr dead_on_unwind writable sret(%struct.NUS_quaternion) align 8 %7, double noundef %31, double noundef %39, double noundef %47, double noundef %55)
  call void @nus_quaternion_normalize(ptr dead_on_unwind writable sret(%struct.NUS_quaternion) align 8 %0, ptr noundef byval(%struct.NUS_quaternion) align 8 %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @nus_quaternion_normalize(ptr dead_on_unwind noalias writable sret(%struct.NUS_quaternion) align 8, ptr noundef byval(%struct.NUS_quaternion) align 8) #0

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 = { 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, !6, i64 0}
!10 = !{!"NUS_quaternion", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 24}


; 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.NUS_quaternion = type { double, double, double, double }

; Function Attrs: nounwind uwtable
declare dso_local void @nus_quaternion_build(ptr dead_on_unwind noalias writable sret(%struct.NUS_quaternion) align 8, double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @nus_quaternion_lerp(ptr dead_on_unwind noalias writable sret(%struct.NUS_quaternion) align 8 %0, ptr nocapture noundef readonly byval(%struct.NUS_quaternion) align 8 %1, ptr nocapture noundef readonly byval(%struct.NUS_quaternion) align 8 %2, double noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.NUS_quaternion, align 8
  %6 = fcmp ogt double %3, 1.000000e+00
  %7 = select i1 %6, double 1.000000e+00, double %3
  %8 = fcmp olt double %7, 0.000000e+00
  %9 = select i1 %8, double 0.000000e+00, double %7
  %10 = fsub double 1.000000e+00, %9
  %11 = load double, ptr %1, align 8, !tbaa !5
  %12 = load double, ptr %2, align 8, !tbaa !5
  %13 = fmul double %9, %12
  %14 = tail call double @llvm.fmuladd.f64(double %11, double %10, double %13)
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = load double, ptr %15, align 8, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %2, i64 8
  %18 = load double, ptr %17, align 8, !tbaa !10
  %19 = fmul double %9, %18
  %20 = tail call double @llvm.fmuladd.f64(double %16, double %10, double %19)
  %21 = getelementptr inbounds i8, ptr %1, i64 16
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %2, i64 16
  %24 = load double, ptr %23, align 8, !tbaa !11
  %25 = fmul double %9, %24
  %26 = tail call double @llvm.fmuladd.f64(double %22, double %10, double %25)
  %27 = getelementptr inbounds i8, ptr %1, i64 24
  %28 = load double, ptr %27, align 8, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %2, i64 24
  %30 = load double, ptr %29, align 8, !tbaa !12
  %31 = fmul double %9, %30
  %32 = tail call double @llvm.fmuladd.f64(double %28, double %10, double %31)
  call void @nus_quaternion_build(ptr dead_on_unwind nonnull writable sret(%struct.NUS_quaternion) align 8 %5, double noundef %14, double noundef %20, double noundef %26, double noundef %32)
  call void @nus_quaternion_normalize(ptr dead_on_unwind writable sret(%struct.NUS_quaternion) align 8 %0, ptr noundef nonnull byval(%struct.NUS_quaternion) align 8 %5)
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @nus_quaternion_normalize(ptr dead_on_unwind noalias writable sret(%struct.NUS_quaternion) align 8, ptr noundef byval(%struct.NUS_quaternion) align 8) local_unnamed_addr #0

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 = { 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, !7, i64 0}
!6 = !{!"NUS_quaternion", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 24}


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