; 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: nounwind
declare double @sin(double noundef) #2

; 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) #3

; 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

; Function Attrs: nounwind uwtable
define dso_local void @nus_quaternion_slerp(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 double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca %struct.NUS_quaternion, align 8
  store double %3, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %11 = load double, ptr %5, align 8, !tbaa !5
  %12 = fcmp ogt double %11, 1.000000e+00
  br i1 %12, label %13, label %14

13:                                               ; preds = %4
  br label %16

14:                                               ; preds = %4
  %15 = load double, ptr %5, align 8, !tbaa !5
  br label %16

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

20:                                               ; preds = %16
  br label %23

21:                                               ; preds = %16
  %22 = load double, ptr %5, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %21, %20
  %24 = phi double [ 0.000000e+00, %20 ], [ %22, %21 ]
  store double %24, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 0
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 1
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 1
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = fmul double %30, %32
  %34 = call double @llvm.fmuladd.f64(double %26, double %28, double %33)
  %35 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 2
  %36 = load double, ptr %35, align 8, !tbaa !12
  %37 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 2
  %38 = load double, ptr %37, align 8, !tbaa !12
  %39 = call double @llvm.fmuladd.f64(double %36, double %38, double %34)
  %40 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 3
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 3
  %43 = load double, ptr %42, align 8, !tbaa !13
  %44 = call double @llvm.fmuladd.f64(double %41, double %43, double %39)
  %45 = call double @acos(double noundef %44) #4
  store double %45, ptr %8, align 8, !tbaa !5
  %46 = load double, ptr %8, align 8, !tbaa !5
  %47 = call double @sin(double noundef %46) #4
  store double %47, ptr %9, align 8, !tbaa !5
  %48 = load double, ptr %5, align 8, !tbaa !5
  %49 = fsub double 1.000000e+00, %48
  %50 = load double, ptr %8, align 8, !tbaa !5
  %51 = fmul double %49, %50
  %52 = call double @sin(double noundef %51) #4
  %53 = load double, ptr %9, align 8, !tbaa !5
  %54 = fdiv double %52, %53
  store double %54, ptr %6, align 8, !tbaa !5
  %55 = load double, ptr %5, align 8, !tbaa !5
  %56 = load double, ptr %8, align 8, !tbaa !5
  %57 = fmul double %55, %56
  %58 = call double @sin(double noundef %57) #4
  %59 = load double, ptr %9, align 8, !tbaa !5
  %60 = fdiv double %58, %59
  store double %60, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 0
  %62 = load double, ptr %61, align 8, !tbaa !9
  %63 = load double, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 0
  %65 = load double, ptr %64, align 8, !tbaa !9
  %66 = load double, ptr %7, align 8, !tbaa !5
  %67 = fmul double %65, %66
  %68 = call double @llvm.fmuladd.f64(double %62, double %63, double %67)
  %69 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 1
  %70 = load double, ptr %69, align 8, !tbaa !11
  %71 = load double, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 1
  %73 = load double, ptr %72, align 8, !tbaa !11
  %74 = load double, ptr %7, align 8, !tbaa !5
  %75 = fmul double %73, %74
  %76 = call double @llvm.fmuladd.f64(double %70, double %71, double %75)
  %77 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 2
  %78 = load double, ptr %77, align 8, !tbaa !12
  %79 = load double, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 2
  %81 = load double, ptr %80, align 8, !tbaa !12
  %82 = load double, ptr %7, align 8, !tbaa !5
  %83 = fmul double %81, %82
  %84 = call double @llvm.fmuladd.f64(double %78, double %79, double %83)
  %85 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 3
  %86 = load double, ptr %85, align 8, !tbaa !13
  %87 = load double, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.NUS_quaternion, ptr %2, i32 0, i32 3
  %89 = load double, ptr %88, align 8, !tbaa !13
  %90 = load double, ptr %7, align 8, !tbaa !5
  %91 = fmul double %89, %90
  %92 = call double @llvm.fmuladd.f64(double %86, double %87, double %91)
  call void @nus_quaternion_build(ptr dead_on_unwind writable sret(%struct.NUS_quaternion) align 8 %10, double noundef %68, double noundef %76, double noundef %84, double noundef %92)
  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 %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret void
}

; Function Attrs: nounwind
declare double @acos(double noundef) #2

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 = { nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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 nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

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

; 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

; Function Attrs: nounwind uwtable
define dso_local void @nus_quaternion_slerp(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 = load double, ptr %1, align 8, !tbaa !5
  %11 = load double, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load double, ptr %12, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !10
  %16 = fmul double %13, %15
  %17 = tail call double @llvm.fmuladd.f64(double %10, double %11, double %16)
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  %19 = load double, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = tail call double @llvm.fmuladd.f64(double %19, double %21, double %17)
  %23 = getelementptr inbounds i8, ptr %1, i64 24
  %24 = load double, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %2, i64 24
  %26 = load double, ptr %25, align 8, !tbaa !12
  %27 = tail call double @llvm.fmuladd.f64(double %24, double %26, double %22)
  %28 = tail call double @acos(double noundef %27) #3
  %29 = tail call double @sin(double noundef %28) #3
  %30 = fsub double 1.000000e+00, %9
  %31 = fmul double %30, %28
  %32 = tail call double @sin(double noundef %31) #3
  %33 = fdiv double %32, %29
  %34 = fmul double %9, %28
  %35 = tail call double @sin(double noundef %34) #3
  %36 = fdiv double %35, %29
  %37 = fmul double %11, %36
  %38 = tail call double @llvm.fmuladd.f64(double %10, double %33, double %37)
  %39 = fmul double %15, %36
  %40 = tail call double @llvm.fmuladd.f64(double %13, double %33, double %39)
  %41 = fmul double %21, %36
  %42 = tail call double @llvm.fmuladd.f64(double %19, double %33, double %41)
  %43 = fmul double %26, %36
  %44 = tail call double @llvm.fmuladd.f64(double %24, double %33, double %43)
  call void @nus_quaternion_build(ptr dead_on_unwind nonnull writable sret(%struct.NUS_quaternion) align 8 %5, double noundef %38, double noundef %40, double noundef %42, double noundef %44)
  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: mustprogress nofree nounwind willreturn memory(write)
declare double @acos(double noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { mustprogress 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, !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,SROAPass,SimplifyCFGPass,TailCallElimPass