; LLVM IR from heroseh/cgm :: cgm (CgmMat4x4_perspective)

; 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.CgmMat4x4 = type { [4 x %union.CgmVec4] }
%union.CgmVec4 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float, float, float }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @CgmMat4x4_perspective(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) #2 {
  %6 = alloca ptr, align 8
  %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.CgmMat4x4, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store float %1, ptr %7, align 4, !tbaa !9
  store float %2, ptr %8, align 4, !tbaa !9
  store float %3, ptr %9, align 4, !tbaa !9
  store float %4, ptr %10, align 4, !tbaa !9
  %14 = load float, ptr %8, align 4, !tbaa !9
  %15 = fpext float %14 to double
  %16 = fcmp une double %15, 0.000000e+00
  br i1 %16, label %20, label %17

17:                                               ; preds = %5
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str) #6
  call void @abort() #7
  unreachable

20:                                               ; preds = %5
  %21 = load float, ptr %10, align 4, !tbaa !9
  %22 = load float, ptr %9, align 4, !tbaa !9
  %23 = fcmp une float %21, %22
  br i1 %23, label %27, label %24

24:                                               ; preds = %20
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.1) #6
  call void @abort() #7
  unreachable

27:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %28 = load float, ptr %7, align 4, !tbaa !9
  %29 = fpext float %28 to double
  %30 = fdiv double %29, 2.000000e+00
  %31 = fptrunc double %30 to float
  %32 = call float @tanf(float noundef %31) #6
  store float %32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %33 = load float, ptr %11, align 4, !tbaa !9
  %34 = fpext float %33 to double
  %35 = fdiv double 1.000000e+00, %34
  %36 = fptrunc double %35 to float
  store float %36, ptr %12, align 4, !tbaa !9
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 %13, i8 0, i64 64, i1 false)
  %38 = getelementptr inbounds %struct.anon.1, ptr %13, i32 0, i32 0
  %39 = getelementptr inbounds %struct.anon.1, ptr %13, i32 0, i32 1
  %40 = getelementptr inbounds %struct.anon.1, ptr %13, i32 0, i32 2
  %41 = getelementptr inbounds %struct.anon.1, ptr %13, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %37, ptr align 4 %13, i64 64, i1 false), !tbaa.struct !11
  %42 = load float, ptr %12, align 4, !tbaa !9
  %43 = load float, ptr %8, align 4, !tbaa !9
  %44 = fdiv float %42, %43
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds [4 x %union.CgmVec4], ptr %45, i64 0, i64 0
  %47 = getelementptr inbounds %struct.anon.1, ptr %46, i32 0, i32 0
  store float %44, ptr %47, align 4, !tbaa !12
  %48 = load float, ptr %12, align 4, !tbaa !9
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds [4 x %union.CgmVec4], ptr %49, i64 0, i64 1
  %51 = getelementptr inbounds %struct.anon.1, ptr %50, i32 0, i32 1
  store float %48, ptr %51, align 4, !tbaa !12
  %52 = load float, ptr %10, align 4, !tbaa !9
  %53 = load float, ptr %9, align 4, !tbaa !9
  %54 = fadd float %52, %53
  %55 = load float, ptr %10, align 4, !tbaa !9
  %56 = load float, ptr %9, align 4, !tbaa !9
  %57 = fsub float %55, %56
  %58 = fdiv float %54, %57
  %59 = fneg float %58
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds [4 x %union.CgmVec4], ptr %60, i64 0, i64 2
  %62 = getelementptr inbounds %struct.anon.1, ptr %61, i32 0, i32 2
  store float %59, ptr %62, align 4, !tbaa !12
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds [4 x %union.CgmVec4], ptr %63, i64 0, i64 2
  %65 = getelementptr inbounds %struct.anon.1, ptr %64, i32 0, i32 3
  store float -1.000000e+00, ptr %65, align 4, !tbaa !12
  %66 = load float, ptr %10, align 4, !tbaa !9
  %67 = fpext float %66 to double
  %68 = fmul double 2.000000e+00, %67
  %69 = load float, ptr %9, align 4, !tbaa !9
  %70 = fpext float %69 to double
  %71 = fmul double %68, %70
  %72 = load float, ptr %10, align 4, !tbaa !9
  %73 = load float, ptr %9, align 4, !tbaa !9
  %74 = fsub float %72, %73
  %75 = fpext float %74 to double
  %76 = fdiv double %71, %75
  %77 = fneg double %76
  %78 = fptrunc double %77 to float
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds [4 x %union.CgmVec4], ptr %79, i64 0, i64 3
  %81 = getelementptr inbounds %struct.anon.1, ptr %80, i32 0, i32 2
  store float %78, ptr %81, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  ret void
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @abort() #4

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { noreturn 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{i64 0, i64 64, !12}
!12 = !{!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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @CgmMat4x4_perspective(ptr nocapture noundef writeonly %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) local_unnamed_addr #0 {
  %6 = fcmp une float %2, 0.000000e+00
  br i1 %6, label %10, label %7

7:                                                ; preds = %5
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str) #5
  tail call void @abort() #6
  unreachable

10:                                               ; preds = %5
  %11 = fcmp une float %4, %3
  br i1 %11, label %15, label %12

12:                                               ; preds = %10
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.1) #5
  tail call void @abort() #6
  unreachable

15:                                               ; preds = %10
  %16 = fmul float %1, 5.000000e-01
  %17 = tail call float @tanf(float noundef %16) #7
  %18 = fdiv float 1.000000e+00, %17
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(60) %19, i8 0, i64 60, i1 false)
  %20 = fdiv float %18, %2
  store float %20, ptr %0, align 4, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %0, i64 20
  store float %18, ptr %21, align 4, !tbaa !9
  %22 = fadd float %3, %4
  %23 = fsub float %4, %3
  %24 = fneg float %22
  %25 = fdiv float %24, %23
  %26 = getelementptr inbounds i8, ptr %0, i64 40
  store float %25, ptr %26, align 4, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %0, i64 44
  store float -1.000000e+00, ptr %27, align 4, !tbaa !9
  %28 = fpext float %4 to double
  %29 = fpext float %3 to double
  %30 = fpext float %23 to double
  %31 = fmul double %28, -2.000000e+00
  %32 = fmul double %31, %29
  %33 = fdiv double %32, %30
  %34 = fptrunc double %33 to float
  %35 = getelementptr inbounds i8, ptr %0, i64 56
  store float %34, ptr %35, align 4, !tbaa !9
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { nofree 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 #2 = { noreturn 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 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { cold nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


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