; LLVM IR from ashishzero/karma :: src/modules/core/lin_maths.ll (Z19mat4_perspective_dxffff)

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

%union.Mat4 = type { [4 x %union.Vec4] }
%union.Vec4 = type { %struct.anon.3 }
%struct.anon.3 = type { float, float, float, float }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef, float noundef, float noundef, float noundef) #1

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

; Function Attrs: nounwind
declare float @tanf(float noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19mat4_perspective_dxffff(ptr dead_on_unwind noalias writable sret(%union.Mat4) align 4 %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) #4 {
  %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
  %11 = alloca float, align 4
  %12 = alloca %union.Vec4, align 4
  %13 = alloca %union.Vec4, align 4
  %14 = alloca %union.Vec4, align 4
  %15 = alloca %union.Vec4, 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 @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %16 = load float, ptr %6, align 4, !tbaa !5
  %17 = fmul float %16, 5.000000e-01
  %18 = call float @tanf(float noundef %17) #5
  %19 = fdiv float 1.000000e+00, %18
  store float %19, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %20 = load float, ptr %9, align 4, !tbaa !5
  %21 = load float, ptr %8, align 4, !tbaa !5
  %22 = fsub float %20, %21
  store float %22, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #5
  %23 = load float, ptr %10, align 4, !tbaa !5
  %24 = load float, ptr %7, align 4, !tbaa !5
  %25 = fdiv float %23, %24
  %26 = call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef %25, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %27 = getelementptr inbounds %union.Vec4, ptr %12, i32 0, i32 0
  %28 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %27, i32 0, i32 0
  %29 = extractvalue { <2 x float>, <2 x float> } %26, 0
  store <2 x float> %29, ptr %28, align 4
  %30 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %27, i32 0, i32 1
  %31 = extractvalue { <2 x float>, <2 x float> } %26, 1
  store <2 x float> %31, ptr %30, align 4
  %32 = getelementptr inbounds [4 x %union.Vec4], ptr %0, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %32, ptr align 4 %12, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #5
  %33 = load float, ptr %10, align 4, !tbaa !5
  %34 = call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef 0.000000e+00, float noundef %33, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %35 = getelementptr inbounds %union.Vec4, ptr %13, i32 0, i32 0
  %36 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %35, i32 0, i32 0
  %37 = extractvalue { <2 x float>, <2 x float> } %34, 0
  store <2 x float> %37, ptr %36, align 4
  %38 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %35, i32 0, i32 1
  %39 = extractvalue { <2 x float>, <2 x float> } %34, 1
  store <2 x float> %39, ptr %38, align 4
  %40 = getelementptr inbounds [4 x %union.Vec4], ptr %0, i64 0, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %40, ptr align 4 %13, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  %41 = load float, ptr %9, align 4, !tbaa !5
  %42 = fneg float %41
  %43 = load float, ptr %11, align 4, !tbaa !5
  %44 = fdiv float %42, %43
  %45 = load float, ptr %9, align 4, !tbaa !5
  %46 = fneg float %45
  %47 = load float, ptr %8, align 4, !tbaa !5
  %48 = fmul float %46, %47
  %49 = load float, ptr %11, align 4, !tbaa !5
  %50 = fdiv float %48, %49
  %51 = call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef %44, float noundef %50)
  %52 = getelementptr inbounds %union.Vec4, ptr %14, i32 0, i32 0
  %53 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %52, i32 0, i32 0
  %54 = extractvalue { <2 x float>, <2 x float> } %51, 0
  store <2 x float> %54, ptr %53, align 4
  %55 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %52, i32 0, i32 1
  %56 = extractvalue { <2 x float>, <2 x float> } %51, 1
  store <2 x float> %56, ptr %55, align 4
  %57 = getelementptr inbounds [4 x %union.Vec4], ptr %0, i64 0, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %57, ptr align 4 %14, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %58 = call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef -1.000000e+00, float noundef 0.000000e+00)
  %59 = getelementptr inbounds %union.Vec4, ptr %15, i32 0, i32 0
  %60 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %59, i32 0, i32 0
  %61 = extractvalue { <2 x float>, <2 x float> } %58, 0
  store <2 x float> %61, ptr %60, align 4
  %62 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %59, i32 0, i32 1
  %63 = extractvalue { <2 x float>, <2 x float> } %58, 1
  store <2 x float> %63, ptr %62, align 4
  %64 = getelementptr inbounds [4 x %union.Vec4], ptr %0, i64 0, i64 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %64, ptr align 4 %15, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 willreturn memory(argmem: readwrite) }
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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 #5 = { 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"}
!9 = !{i64 0, i64 16, !10}
!10 = !{!7, !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"

%union.Mat4 = type { [4 x %union.Vec4] }
%union.Vec4 = type { %struct.anon.3 }
%struct.anon.3 = type { float, float, float, float }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef, float noundef, float noundef, float noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z19mat4_perspective_dxffff(ptr dead_on_unwind noalias nocapture writable writeonly sret(%union.Mat4) align 4 %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) local_unnamed_addr #2 {
  %6 = fmul float %1, 5.000000e-01
  %7 = tail call float @tanf(float noundef %6) #3
  %8 = fdiv float 1.000000e+00, %7
  %9 = fsub float %4, %3
  %10 = fdiv float %8, %2
  %11 = tail call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef %10, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %12 = extractvalue { <2 x float>, <2 x float> } %11, 0
  %13 = extractvalue { <2 x float>, <2 x float> } %11, 1
  store <2 x float> %12, ptr %0, align 4
  %.sroa.46.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  store <2 x float> %13, ptr %.sroa.46.0..sroa_idx, align 4, !tbaa !5
  %14 = tail call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef 0.000000e+00, float noundef %8, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %15 = extractvalue { <2 x float>, <2 x float> } %14, 0
  %16 = extractvalue { <2 x float>, <2 x float> } %14, 1
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x float> %15, ptr %17, align 4
  %.sroa.44.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 24
  store <2 x float> %16, ptr %.sroa.44.0..sroa_idx, align 4, !tbaa !5
  %18 = fneg float %4
  %19 = fdiv float %18, %9
  %20 = fmul float %18, %3
  %21 = fdiv float %20, %9
  %22 = tail call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef %19, float noundef %21)
  %23 = extractvalue { <2 x float>, <2 x float> } %22, 0
  %24 = extractvalue { <2 x float>, <2 x float> } %22, 1
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  store <2 x float> %23, ptr %25, align 4
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 40
  store <2 x float> %24, ptr %.sroa.42.0..sroa_idx, align 4, !tbaa !5
  %26 = tail call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef -1.000000e+00, float noundef 0.000000e+00)
  %27 = extractvalue { <2 x float>, <2 x float> } %26, 0
  %28 = extractvalue { <2 x float>, <2 x float> } %26, 1
  %29 = getelementptr inbounds i8, ptr %0, i64 48
  store <2 x float> %27, ptr %29, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 56
  store <2 x float> %28, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  ret void
}

attributes #0 = { inlinehint 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 = { mustprogress nounwind uwtable "min-legal-vector-width"="64" "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 }

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


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