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

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

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

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 = { 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 #4 = { 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 #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 nounwind uwtable
define dso_local void @_Z19mat4_perspective_glffff(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 #1 {
  %6 = fmul float %1, 5.000000e-01
  %7 = tail call float @tanf(float noundef %6) #3
  %8 = fdiv float 1.000000e+00, %7
  %9 = fadd float %3, %4
  %10 = fsub float %4, %3
  %11 = fdiv float %8, %2
  %12 = tail call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef %11, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %13 = extractvalue { <2 x float>, <2 x float> } %12, 0
  %14 = extractvalue { <2 x float>, <2 x float> } %12, 1
  store <2 x float> %13, ptr %0, align 4
  %.sroa.46.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  store <2 x float> %14, ptr %.sroa.46.0..sroa_idx, align 4, !tbaa !5
  %15 = 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)
  %16 = extractvalue { <2 x float>, <2 x float> } %15, 0
  %17 = extractvalue { <2 x float>, <2 x float> } %15, 1
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x float> %16, ptr %18, align 4
  %.sroa.44.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 24
  store <2 x float> %17, ptr %.sroa.44.0..sroa_idx, align 4, !tbaa !5
  %19 = fneg float %9
  %20 = fdiv float %19, %10
  %21 = fmul float %4, -2.000000e+00
  %22 = fmul float %21, %3
  %23 = fdiv float %22, %10
  %24 = tail call { <2 x float>, <2 x float> } @_Z4vec4ffff(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef %20, float noundef %23)
  %25 = extractvalue { <2 x float>, <2 x float> } %24, 0
  %26 = extractvalue { <2 x float>, <2 x float> } %24, 1
  %27 = getelementptr inbounds i8, ptr %0, i64 32
  store <2 x float> %25, ptr %27, align 4
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 40
  store <2 x float> %26, ptr %.sroa.42.0..sroa_idx, align 4, !tbaa !5
  %28 = 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)
  %29 = extractvalue { <2 x float>, <2 x float> } %28, 0
  %30 = extractvalue { <2 x float>, <2 x float> } %28, 1
  %31 = getelementptr inbounds i8, ptr %0, i64 48
  store <2 x float> %29, ptr %31, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 56
  store <2 x float> %30, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  ret void
}

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

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 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 #2 = { 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 #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