; LLVM IR from ysyesilyurt/ComputerGraphics :: ForwardRenderingPipeline/Scene.ll (Z23calcViewportTransMatrixP6Camera)

; 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 { [4 x [4 x double]] }
%class.Camera = type { i32, [4 x i8], %class.Vec3, %class.Vec3, %class.Vec3, %class.Vec3, %class.Vec3, double, double, double, double, double, double, i32, i32, %"class.std::__cxx11::basic_string" }
%class.Vec3 = type <{ double, double, double, i32, [4 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@constinit.10 = external hidden constant [4 x double], align 8
@constinit.11 = external hidden constant [4 x double], align 8

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

declare void @_ZN7Matrix4C1EPA4_d(ptr noundef nonnull align 8 dereferenceable(128), ptr noundef) unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z23calcViewportTransMatrixP6Camera(ptr dead_on_unwind noalias writable sret(%class.Matrix4) align 8 %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [4 x [4 x double]], align 16
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr %5) #5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %class.Camera, ptr %6, i32 0, i32 13
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = sitofp i32 %8 to double
  %10 = fdiv double %9, 2.000000e+00
  store double %10, ptr %5, align 8, !tbaa !17
  %11 = getelementptr inbounds double, ptr %5, i64 1
  store double 0.000000e+00, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds double, ptr %5, i64 2
  store double 0.000000e+00, ptr %12, align 8, !tbaa !17
  %13 = getelementptr inbounds double, ptr %5, i64 3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.Camera, ptr %14, i32 0, i32 13
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = sub nsw i32 %16, 1
  %18 = sitofp i32 %17 to double
  %19 = fdiv double %18, 2.000000e+00
  store double %19, ptr %13, align 8, !tbaa !17
  %20 = getelementptr inbounds [4 x double], ptr %5, i64 1
  store double 0.000000e+00, ptr %20, align 8, !tbaa !17
  %21 = getelementptr inbounds double, ptr %20, i64 1
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.Camera, ptr %22, i32 0, i32 14
  %24 = load i32, ptr %23, align 4, !tbaa !18
  %25 = sitofp i32 %24 to double
  %26 = fdiv double %25, 2.000000e+00
  store double %26, ptr %21, align 8, !tbaa !17
  %27 = getelementptr inbounds double, ptr %20, i64 2
  store double 0.000000e+00, ptr %27, align 8, !tbaa !17
  %28 = getelementptr inbounds double, ptr %20, i64 3
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.Camera, ptr %29, i32 0, i32 14
  %31 = load i32, ptr %30, align 4, !tbaa !18
  %32 = sub nsw i32 %31, 1
  %33 = sitofp i32 %32 to double
  %34 = fdiv double %33, 2.000000e+00
  store double %34, ptr %28, align 8, !tbaa !17
  %35 = getelementptr inbounds [4 x double], ptr %5, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %35, ptr align 8 @constinit.10, i64 32, i1 false), !tbaa.struct !19
  %36 = getelementptr inbounds [4 x double], ptr %5, i64 3
  call void @llvm.memset.p0.i64(ptr align 16 %36, i8 0, i64 32, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %36, ptr align 8 @constinit.11, i64 32, i1 false), !tbaa.struct !19
  %37 = getelementptr inbounds [4 x [4 x double]], ptr %5, i64 0, i64 0
  call void @_ZN7Matrix4C1EPA4_d(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef %37)
  call void @llvm.lifetime.end.p0(i64 128, ptr %5) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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"="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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 216}
!10 = !{!"_ZTS6Camera", !11, i64 0, !12, i64 8, !12, i64 40, !12, i64 72, !12, i64 104, !12, i64 136, !13, i64 168, !13, i64 176, !13, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !11, i64 216, !11, i64 220, !14, i64 224}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS4Vec3", !13, i64 0, !13, i64 8, !13, i64 16, !11, i64 24}
!13 = !{!"double", !7, i64 0}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !7, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !11, i64 220}
!19 = !{i64 0, i64 32, !20}
!20 = !{!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"

%class.Matrix4 = type { [4 x [4 x double]] }

@constinit.10 = external hidden local_unnamed_addr constant [4 x double], align 8
@constinit.11 = external hidden local_unnamed_addr constant [4 x double], align 8

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

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

; Function Attrs: mustprogress 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) #2

declare void @_ZN7Matrix4C1EPA4_d(ptr noundef nonnull align 8 dereferenceable(128), ptr noundef) unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z23calcViewportTransMatrixP6Camera(ptr dead_on_unwind noalias nonnull writable sret(%class.Matrix4) align 8 %0, ptr nocapture noundef readonly %1) local_unnamed_addr #4 {
  %3 = alloca [4 x [4 x double]], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #5
  %4 = getelementptr inbounds i8, ptr %1, i64 216
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = sitofp i32 %5 to double
  %7 = fmul double %6, 5.000000e-01
  store double %7, ptr %3, align 16, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  %9 = getelementptr inbounds i8, ptr %3, i64 24
  %10 = add nsw i32 %5, -1
  %11 = sitofp i32 %10 to double
  %12 = fmul double %11, 5.000000e-01
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  store double %12, ptr %9, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %3, i64 32
  store double 0.000000e+00, ptr %13, align 16, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %3, i64 40
  %15 = getelementptr inbounds i8, ptr %1, i64 220
  %16 = load i32, ptr %15, align 4, !tbaa !17
  %17 = sitofp i32 %16 to double
  %18 = fmul double %17, 5.000000e-01
  store double %18, ptr %14, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %3, i64 48
  store double 0.000000e+00, ptr %19, align 16, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %3, i64 56
  %21 = add nsw i32 %16, -1
  %22 = sitofp i32 %21 to double
  %23 = fmul double %22, 5.000000e-01
  store double %23, ptr %20, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %3, i64 64
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %24, ptr noundef nonnull align 8 dereferenceable(32) @constinit.10, i64 32, i1 false), !tbaa.struct !18
  %25 = getelementptr inbounds i8, ptr %3, i64 96
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %25, ptr noundef nonnull align 8 dereferenceable(32) @constinit.11, i64 32, i1 false), !tbaa.struct !18
  call void @_ZN7Matrix4C1EPA4_d(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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"="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 #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, !7, i64 216}
!6 = !{!"_ZTS6Camera", !7, i64 0, !10, i64 8, !10, i64 40, !10, i64 72, !10, i64 104, !10, i64 136, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !7, i64 216, !7, i64 220, !12, i64 224}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS4Vec3", !11, i64 0, !11, i64 8, !11, i64 16, !7, i64 24}
!11 = !{!"double", !8, i64 0}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !13, i64 0, !15, i64 8, !8, i64 16}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !14, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!6, !7, i64 220}
!18 = !{i64 0, i64 32, !19}
!19 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass