; LLVM IR from Angelo1211/SoftwareRenderer :: src/matrix.ll (ZN7Matrix416projectionMatrixEffff)

; 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.Matrix4 = type { %"struct.std::array" }
%"struct.std::array" = type { [16 x float] }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64), i64 noundef, i64 noundef) #1 align 2

; 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
declare dso_local void @_ZN7Matrix4C2Ev(ptr noundef nonnull align 4 dereferenceable(64)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Matrix416projectionMatrixEffff(ptr dead_on_unwind noalias writable sret(%class.Matrix4) align 4 %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) #2 align 2 {
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  store float %1, ptr %6, align 4, !tbaa !5
  store float %2, ptr %7, align 4, !tbaa !5
  store float %3, ptr %8, align 4, !tbaa !5
  store float %4, ptr %9, align 4, !tbaa !5
  call void @_ZN7Matrix4C2Ev(ptr noundef nonnull align 4 dereferenceable(64) %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %11 = load float, ptr %6, align 4, !tbaa !5
  %12 = fdiv float %11, 2.000000e+00
  %13 = fpext float %12 to double
  %14 = fmul double %13, 0x3F91DF46A2529D39
  %15 = call double @tan(double noundef %14) #4
  %16 = fdiv double 1.000000e+00, %15
  %17 = fptrunc double %16 to float
  store float %17, ptr %10, align 4, !tbaa !5
  %18 = load float, ptr %10, align 4, !tbaa !5
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 0, i64 noundef 0)
  store float %18, ptr %19, align 4, !tbaa !5
  %20 = load float, ptr %7, align 4, !tbaa !5
  %21 = load float, ptr %10, align 4, !tbaa !5
  %22 = fmul float %20, %21
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 1, i64 noundef 1)
  store float %22, ptr %23, align 4, !tbaa !5
  %24 = load float, ptr %8, align 4, !tbaa !5
  %25 = load float, ptr %9, align 4, !tbaa !5
  %26 = load float, ptr %8, align 4, !tbaa !5
  %27 = fsub float %25, %26
  %28 = fdiv float %24, %27
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 2, i64 noundef 2)
  store float %28, ptr %29, align 4, !tbaa !5
  %30 = load float, ptr %9, align 4, !tbaa !5
  %31 = load float, ptr %8, align 4, !tbaa !5
  %32 = fmul float %30, %31
  %33 = load float, ptr %9, align 4, !tbaa !5
  %34 = load float, ptr %8, align 4, !tbaa !5
  %35 = fsub float %33, %34
  %36 = fdiv float %32, %35
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 2, i64 noundef 3)
  store float %36, ptr %37, align 4, !tbaa !5
  %38 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 3, i64 noundef 2)
  store float -1.000000e+00, ptr %38, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  ret void
}

; Function Attrs: nounwind
declare double @tan(double noundef) #3

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 = { mustprogress 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 #3 = { 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

%class.Matrix4 = type { %"struct.std::array" }
%"struct.std::array" = type { [16 x float] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7Matrix4C2Ev(ptr noundef nonnull align 4 dereferenceable(64)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7Matrix416projectionMatrixEffff(ptr dead_on_unwind noalias nonnull writable sret(%class.Matrix4) align 4 %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) local_unnamed_addr #0 align 2 {
  tail call void @_ZN7Matrix4C2Ev(ptr noundef nonnull align 4 dereferenceable(64) %0)
  %6 = fmul float %1, 5.000000e-01
  %7 = fpext float %6 to double
  %8 = fmul double %7, 0x3F91DF46A2529D39
  %9 = tail call double @tan(double noundef %8) #2
  %10 = fdiv double 1.000000e+00, %9
  %11 = fptrunc double %10 to float
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 0, i64 noundef 0)
  store float %11, ptr %12, align 4, !tbaa !5
  %13 = fmul float %11, %2
  %14 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 1, i64 noundef 1)
  store float %13, ptr %14, align 4, !tbaa !5
  %15 = fsub float %4, %3
  %16 = fdiv float %3, %15
  %17 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 2, i64 noundef 2)
  store float %16, ptr %17, align 4, !tbaa !5
  %18 = fmul float %3, %4
  %19 = fdiv float %18, %15
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 2, i64 noundef 3)
  store float %19, ptr %20, align 4, !tbaa !5
  %21 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Matrix4clEmm(ptr noundef nonnull align 4 dereferenceable(64) %0, i64 noundef 3, i64 noundef 2)
  store float -1.000000e+00, ptr %21, align 4, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @tan(double noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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