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

; 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_matrix = type { [4 x [4 x float]] }
%struct.NUS_quaternion = type { double, double, double, double }

; Function Attrs: nounwind uwtable
declare dso_local void @nus_matrix_build(ptr dead_on_unwind noalias writable sret(%struct.NUS_matrix) align 4, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @nus_matrix_build_rotation_qua(ptr dead_on_unwind noalias writable sret(%struct.NUS_matrix) align 4 %0, ptr noundef byval(%struct.NUS_quaternion) align 8 %1) #0 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 0
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = fptrunc double %8 to float
  store float %9, ptr %3, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %10 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 1
  %11 = load double, ptr %10, align 8, !tbaa !12
  %12 = fptrunc double %11 to float
  store float %12, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %13 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 2
  %14 = load double, ptr %13, align 8, !tbaa !13
  %15 = fptrunc double %14 to float
  store float %15, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %16 = getelementptr inbounds %struct.NUS_quaternion, ptr %1, i32 0, i32 3
  %17 = load double, ptr %16, align 8, !tbaa !14
  %18 = fptrunc double %17 to float
  store float %18, ptr %6, align 4, !tbaa !10
  %19 = load float, ptr %5, align 4, !tbaa !10
  %20 = load float, ptr %5, align 4, !tbaa !10
  %21 = load float, ptr %6, align 4, !tbaa !10
  %22 = load float, ptr %6, align 4, !tbaa !10
  %23 = fmul float %21, %22
  %24 = call float @llvm.fmuladd.f32(float %19, float %20, float %23)
  %25 = fpext float %24 to double
  %26 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %25, double 1.000000e+00)
  %27 = fptrunc double %26 to float
  %28 = load float, ptr %4, align 4, !tbaa !10
  %29 = load float, ptr %5, align 4, !tbaa !10
  %30 = load float, ptr %6, align 4, !tbaa !10
  %31 = load float, ptr %3, align 4, !tbaa !10
  %32 = fmul float %30, %31
  %33 = fneg float %32
  %34 = call float @llvm.fmuladd.f32(float %28, float %29, float %33)
  %35 = fpext float %34 to double
  %36 = fmul double 2.000000e+00, %35
  %37 = fptrunc double %36 to float
  %38 = load float, ptr %4, align 4, !tbaa !10
  %39 = load float, ptr %6, align 4, !tbaa !10
  %40 = load float, ptr %5, align 4, !tbaa !10
  %41 = load float, ptr %3, align 4, !tbaa !10
  %42 = fmul float %40, %41
  %43 = call float @llvm.fmuladd.f32(float %38, float %39, float %42)
  %44 = fpext float %43 to double
  %45 = fmul double 2.000000e+00, %44
  %46 = fptrunc double %45 to float
  %47 = load float, ptr %4, align 4, !tbaa !10
  %48 = load float, ptr %5, align 4, !tbaa !10
  %49 = load float, ptr %6, align 4, !tbaa !10
  %50 = load float, ptr %3, align 4, !tbaa !10
  %51 = fmul float %49, %50
  %52 = call float @llvm.fmuladd.f32(float %47, float %48, float %51)
  %53 = fpext float %52 to double
  %54 = fmul double 2.000000e+00, %53
  %55 = fptrunc double %54 to float
  %56 = load float, ptr %4, align 4, !tbaa !10
  %57 = load float, ptr %4, align 4, !tbaa !10
  %58 = load float, ptr %6, align 4, !tbaa !10
  %59 = load float, ptr %6, align 4, !tbaa !10
  %60 = fmul float %58, %59
  %61 = call float @llvm.fmuladd.f32(float %56, float %57, float %60)
  %62 = fpext float %61 to double
  %63 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %62, double 1.000000e+00)
  %64 = fptrunc double %63 to float
  %65 = load float, ptr %5, align 4, !tbaa !10
  %66 = load float, ptr %6, align 4, !tbaa !10
  %67 = load float, ptr %4, align 4, !tbaa !10
  %68 = load float, ptr %3, align 4, !tbaa !10
  %69 = fmul float %67, %68
  %70 = fneg float %69
  %71 = call float @llvm.fmuladd.f32(float %65, float %66, float %70)
  %72 = fpext float %71 to double
  %73 = fmul double 2.000000e+00, %72
  %74 = fptrunc double %73 to float
  %75 = load float, ptr %4, align 4, !tbaa !10
  %76 = load float, ptr %6, align 4, !tbaa !10
  %77 = load float, ptr %5, align 4, !tbaa !10
  %78 = load float, ptr %3, align 4, !tbaa !10
  %79 = fmul float %77, %78
  %80 = fneg float %79
  %81 = call float @llvm.fmuladd.f32(float %75, float %76, float %80)
  %82 = fpext float %81 to double
  %83 = fmul double 2.000000e+00, %82
  %84 = fptrunc double %83 to float
  %85 = load float, ptr %5, align 4, !tbaa !10
  %86 = load float, ptr %6, align 4, !tbaa !10
  %87 = load float, ptr %4, align 4, !tbaa !10
  %88 = load float, ptr %3, align 4, !tbaa !10
  %89 = fmul float %87, %88
  %90 = call float @llvm.fmuladd.f32(float %85, float %86, float %89)
  %91 = fpext float %90 to double
  %92 = fmul double 2.000000e+00, %91
  %93 = fptrunc double %92 to float
  %94 = load float, ptr %4, align 4, !tbaa !10
  %95 = load float, ptr %4, align 4, !tbaa !10
  %96 = load float, ptr %5, align 4, !tbaa !10
  %97 = load float, ptr %5, align 4, !tbaa !10
  %98 = fmul float %96, %97
  %99 = call float @llvm.fmuladd.f32(float %94, float %95, float %98)
  %100 = fpext float %99 to double
  %101 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %100, double 1.000000e+00)
  %102 = fptrunc double %101 to float
  call void @nus_matrix_build(ptr dead_on_unwind writable sret(%struct.NUS_matrix) align 4 %0, float noundef %27, float noundef %37, float noundef %46, float noundef 0.000000e+00, float noundef %55, float noundef %64, float noundef %74, float noundef 0.000000e+00, float noundef %84, float noundef %93, float noundef %102, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 1.000000e+00)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; 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) #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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!11, !11, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, 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_matrix = type { [4 x [4 x float]] }
%struct.NUS_quaternion = type { double, double, double, double }

; Function Attrs: nounwind uwtable
declare dso_local void @nus_matrix_build(ptr dead_on_unwind noalias writable sret(%struct.NUS_matrix) align 4, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef, float noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @nus_matrix_build_rotation_qua(ptr dead_on_unwind noalias writable sret(%struct.NUS_matrix) align 4 %0, ptr nocapture noundef readonly byval(%struct.NUS_quaternion) align 8 %1) local_unnamed_addr #0 {
  %3 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %4 = fptrunc <2 x double> %3 to <2 x float>
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load double, ptr %5, align 8, !tbaa !9
  %7 = fptrunc double %6 to float
  %8 = getelementptr inbounds i8, ptr %1, i64 24
  %9 = load double, ptr %8, align 8, !tbaa !11
  %10 = fptrunc double %9 to float
  %11 = fmul float %10, %10
  %12 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %11)
  %13 = fpext float %12 to double
  %14 = tail call double @llvm.fmuladd.f64(double %13, double -2.000000e+00, double 1.000000e+00)
  %15 = fptrunc double %14 to float
  %16 = extractelement <2 x float> %4, i64 0
  %17 = fmul float %16, %10
  %18 = fneg float %17
  %19 = extractelement <2 x float> %4, i64 1
  %20 = tail call float @llvm.fmuladd.f32(float %19, float %7, float %18)
  %21 = fmul float %20, 2.000000e+00
  %22 = fmul float %16, %7
  %23 = tail call float @llvm.fmuladd.f32(float %19, float %10, float %22)
  %24 = fmul float %23, 2.000000e+00
  %25 = tail call float @llvm.fmuladd.f32(float %19, float %7, float %17)
  %26 = fmul float %25, 2.000000e+00
  %27 = tail call float @llvm.fmuladd.f32(float %19, float %19, float %11)
  %28 = fpext float %27 to double
  %29 = tail call double @llvm.fmuladd.f64(double %28, double -2.000000e+00, double 1.000000e+00)
  %30 = fptrunc double %29 to float
  %31 = fmul float %16, %19
  %32 = fneg float %31
  %33 = tail call float @llvm.fmuladd.f32(float %7, float %10, float %32)
  %34 = fmul float %33, 2.000000e+00
  %35 = fneg float %22
  %36 = tail call float @llvm.fmuladd.f32(float %19, float %10, float %35)
  %37 = fmul float %36, 2.000000e+00
  %38 = tail call float @llvm.fmuladd.f32(float %7, float %10, float %31)
  %39 = fmul float %38, 2.000000e+00
  %40 = fmul float %7, %7
  %41 = tail call float @llvm.fmuladd.f32(float %19, float %19, float %40)
  %42 = fpext float %41 to double
  %43 = tail call double @llvm.fmuladd.f64(double %42, double -2.000000e+00, double 1.000000e+00)
  %44 = fptrunc double %43 to float
  tail call void @nus_matrix_build(ptr dead_on_unwind writable sret(%struct.NUS_matrix) align 4 %0, float noundef %15, float noundef %21, float noundef %24, float noundef 0.000000e+00, float noundef %26, float noundef %30, float noundef %34, float noundef 0.000000e+00, float noundef %37, float noundef %39, float noundef %44, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 1.000000e+00)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"NUS_quaternion", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!10, !6, i64 24}


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