; LLVM IR from achilles288/robot-monitor-graphics :: src/base/context_world.ll (ZNK3rmg7Context13worldToScreenERKNS_4Vec3E)

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

%"struct.rmg::Rect" = type { i16, i16 }
%"struct.rmg::Vec4" = type { %union.anon.6 }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = type { float, float, float, float }
%"class.rmg::Context" = type { ptr, i32, i16, i16, %"struct.rmg::ColorRGBA", %"class.rmg::Camera", %"struct.rmg::Vec3", %"struct.rmg::Vec3", %"struct.rmg::ColorRGBA", %"class.rmg::ObjectList", %"class.rmg::ObjectList", %"class.rmg::ObjectList", %"class.rmg::ObjectList", %"class.rmg::ObjectList", %"class.rmg::MaterialList", %"class.rmg::FontList", %"class.rmg::internal::GeneralShader", %"class.rmg::internal::ShadowMapShader", %"class.rmg::internal::Object2DShader", %"class.rmg::internal::ParticleShader", %"class.rmg::internal::Line3DShader", %"class.rmg::internal::ContextLoader", %"class.rmg::internal::GLContext", i8, float, i8, i32 }
%"class.rmg::Camera" = type { %"struct.rmg::Vec3", %"struct.rmg::Mat3", %"struct.rmg::Mat4", %"struct.rmg::Mat4", %"struct.rmg::Mat4", float, float, float, float, float, i32 }
%"struct.rmg::Mat3" = type { %union.anon.0 }
%union.anon.0 = type { [3 x [3 x float]] }
%"struct.rmg::Mat4" = type { %union.anon.1 }
%union.anon.1 = type { [4 x [4 x float]] }
%"struct.rmg::Vec3" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.rmg::ColorRGBA" = type { float, float, float, float }
%"class.rmg::ObjectList" = type { %"class.rmg::LinkedList.base", [4 x i8] }
%"class.rmg::LinkedList.base" = type <{ ptr, ptr, i32 }>
%"class.rmg::MaterialList" = type { %"class.rmg::LinkedList.base.3", [4 x i8] }
%"class.rmg::LinkedList.base.3" = type <{ ptr, ptr, i32 }>
%"class.rmg::FontList" = type { %"class.rmg::LinkedList.base.5", [4 x i8] }
%"class.rmg::LinkedList.base.5" = type <{ ptr, ptr, i32 }>
%"class.rmg::internal::GeneralShader" = type { %"class.rmg::internal::Shader.base", i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [4 x i8] }
%"class.rmg::internal::Shader.base" = type <{ ptr, i32 }>
%"class.rmg::internal::ShadowMapShader" = type { %"class.rmg::internal::Shader.base", %"class.rmg::Camera", %"struct.rmg::Vec3", %"struct.rmg::Vec3", %"struct.rmg::Vec3", float, float, float, i32, i32, i32 }
%"class.rmg::internal::Object2DShader" = type { %"class.rmg::internal::SpriteShader", %"class.rmg::internal::Text2DShader", %"struct.rmg::Mat3", i16, i16 }
%"class.rmg::internal::SpriteShader" = type { %"class.rmg::internal::Shader.base", i32, i32, i32, i32, i32 }
%"class.rmg::internal::Text2DShader" = type { %"class.rmg::internal::Shader.base", i32, i32, i32, i32, i32, i32, i32 }
%"class.rmg::internal::ParticleShader" = type { %"class.rmg::internal::Shader.base", i32, i32, i32, i32, i32, i32, i32 }
%"class.rmg::internal::Line3DShader" = type { %"class.rmg::internal::Shader.base", i32, i32, i32, i32, i32 }
%"class.rmg::internal::ContextLoader" = type { %"class.rmg::internal::PendingStack" }
%"class.rmg::internal::PendingStack" = type <{ ptr, %"class.rmg::internal::Pending", i32, [4 x i8] }>
%"class.rmg::internal::Pending" = type { ptr, ptr }
%"class.rmg::internal::GLContext" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

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

declare { <2 x float>, <2 x float> } @_ZNK3rmg4Mat4mlERKNS_4Vec4E(ptr noundef nonnull align 4 dereferenceable(64), ptr noundef nonnull align 4 dereferenceable(16)) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg4Vec4C2ERKNS_4Vec3Ef(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(12), float noundef) unnamed_addr #2 align 2

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

declare noundef nonnull align 4 dereferenceable(64) ptr @_ZNK3rmg6Camera11getVPMatrixEv(ptr noundef nonnull align 4 dereferenceable(264)) #1

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

; Function Attrs: mustprogress uwtable
define dso_local i32 @_ZNK3rmg7Context13worldToScreenERKNS_4Vec3E(ptr noundef nonnull align 8 dereferenceable(1440) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #3 align 2 {
  %3 = alloca %"struct.rmg::Rect", align 2
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"struct.rmg::Vec4", align 4
  %7 = alloca %"struct.rmg::Vec4", align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %9 = getelementptr inbounds %"class.rmg::Context", ptr %8, i32 0, i32 5
  %10 = call noundef nonnull align 4 dereferenceable(64) ptr @_ZNK3rmg6Camera11getVPMatrixEv(ptr noundef nonnull align 4 dereferenceable(264) %9)
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN3rmg4Vec4C2ERKNS_4Vec3Ef(ptr noundef nonnull align 4 dereferenceable(16) %7, ptr noundef nonnull align 4 dereferenceable(12) %11, float noundef 1.000000e+00)
  %12 = call { <2 x float>, <2 x float> } @_ZNK3rmg4Mat4mlERKNS_4Vec4E(ptr noundef nonnull align 4 dereferenceable(64) %10, ptr noundef nonnull align 4 dereferenceable(16) %7)
  %13 = getelementptr inbounds %"struct.rmg::Vec4", ptr %6, i32 0, i32 0
  %14 = getelementptr inbounds %union.anon.6, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %14, i32 0, i32 0
  %16 = extractvalue { <2 x float>, <2 x float> } %12, 0
  store <2 x float> %16, ptr %15, align 4
  %17 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %14, i32 0, i32 1
  %18 = extractvalue { <2 x float>, <2 x float> } %12, 1
  store <2 x float> %18, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @_ZN3rmg4RectC2Ev(ptr noundef nonnull align 2 dereferenceable(4) %3)
  %19 = getelementptr inbounds %"struct.rmg::Vec4", ptr %6, i32 0, i32 0
  %20 = getelementptr inbounds %struct.anon.7, ptr %19, i32 0, i32 0
  %21 = load float, ptr %20, align 4, !tbaa !9
  %22 = getelementptr inbounds %"struct.rmg::Vec4", ptr %6, i32 0, i32 0
  %23 = getelementptr inbounds %struct.anon.7, ptr %22, i32 0, i32 3
  %24 = load float, ptr %23, align 4, !tbaa !9
  %25 = fdiv float %21, %24
  %26 = fadd float %25, 1.000000e+00
  %27 = getelementptr inbounds %"class.rmg::Context", ptr %8, i32 0, i32 2
  %28 = load i16, ptr %27, align 4, !tbaa !10
  %29 = zext i16 %28 to i32
  %30 = sitofp i32 %29 to float
  %31 = fmul float %26, %30
  %32 = fdiv float %31, 2.000000e+00
  %33 = fptoui float %32 to i16
  %34 = getelementptr inbounds %"struct.rmg::Rect", ptr %3, i32 0, i32 0
  store i16 %33, ptr %34, align 2, !tbaa !40
  %35 = getelementptr inbounds %"struct.rmg::Vec4", ptr %6, i32 0, i32 0
  %36 = getelementptr inbounds %struct.anon.7, ptr %35, i32 0, i32 1
  %37 = load float, ptr %36, align 4, !tbaa !9
  %38 = getelementptr inbounds %"struct.rmg::Vec4", ptr %6, i32 0, i32 0
  %39 = getelementptr inbounds %struct.anon.7, ptr %38, i32 0, i32 3
  %40 = load float, ptr %39, align 4, !tbaa !9
  %41 = fdiv float %37, %40
  %42 = fsub float 1.000000e+00, %41
  %43 = getelementptr inbounds %"class.rmg::Context", ptr %8, i32 0, i32 3
  %44 = load i16, ptr %43, align 2, !tbaa !42
  %45 = zext i16 %44 to i32
  %46 = sitofp i32 %45 to float
  %47 = fmul float %42, %46
  %48 = fdiv float %47, 2.000000e+00
  %49 = fptoui float %48 to i16
  %50 = getelementptr inbounds %"struct.rmg::Rect", ptr %3, i32 0, i32 1
  store i16 %49, ptr %50, align 2, !tbaa !43
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  %51 = load i32, ptr %3, align 2
  ret i32 %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !13, i64 12}
!11 = !{!"_ZTSN3rmg7ContextE", !12, i64 8, !13, i64 12, !13, i64 14, !14, i64 16, !16, i64 32, !17, i64 296, !17, i64 308, !14, i64 320, !21, i64 336, !21, i64 360, !21, i64 384, !21, i64 408, !21, i64 432, !23, i64 456, !25, i64 480, !27, i64 504, !29, i64 568, !30, i64 904, !33, i64 1016, !34, i64 1056, !35, i64 1088, !38, i64 1120, !39, i64 1424, !15, i64 1428, !39, i64 1432, !12, i64 1436}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTSN3rmg9ColorRGBAE", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTSN3rmg6CameraE", !17, i64 0, !18, i64 12, !19, i64 48, !19, i64 112, !19, i64 176, !15, i64 240, !15, i64 244, !15, i64 248, !15, i64 252, !15, i64 256, !20, i64 260}
!17 = !{!"_ZTSN3rmg4Vec3E", !7, i64 0}
!18 = !{!"_ZTSN3rmg4Mat3E", !7, i64 0}
!19 = !{!"_ZTSN3rmg4Mat4E", !7, i64 0}
!20 = !{!"_ZTSN3rmg14ProjectionModeE", !7, i64 0}
!21 = !{!"_ZTSN3rmg10ObjectListE", !22, i64 0}
!22 = !{!"_ZTSN3rmg10LinkedListINS_6ObjectEEE", !6, i64 0, !6, i64 8, !12, i64 16}
!23 = !{!"_ZTSN3rmg12MaterialListE", !24, i64 0}
!24 = !{!"_ZTSN3rmg10LinkedListINS_8MaterialEEE", !6, i64 0, !6, i64 8, !12, i64 16}
!25 = !{!"_ZTSN3rmg8FontListE", !26, i64 0}
!26 = !{!"_ZTSN3rmg10LinkedListINS_4FontEEE", !6, i64 0, !6, i64 8, !12, i64 16}
!27 = !{!"_ZTSN3rmg8internal13GeneralShaderE", !28, i64 0, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56}
!28 = !{!"_ZTSN3rmg8internal6ShaderE", !12, i64 8}
!29 = !{!"_ZTSN3rmg8internal15ShadowMapShaderE", !28, i64 0, !16, i64 12, !17, i64 276, !17, i64 288, !17, i64 300, !15, i64 312, !15, i64 316, !15, i64 320, !12, i64 324, !12, i64 328, !12, i64 332}
!30 = !{!"_ZTSN3rmg8internal14Object2DShaderE", !31, i64 0, !32, i64 32, !18, i64 72, !13, i64 108, !13, i64 110}
!31 = !{!"_ZTSN3rmg8internal12SpriteShaderE", !28, i64 0, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!32 = !{!"_ZTSN3rmg8internal12Text2DShaderE", !28, i64 0, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36}
!33 = !{!"_ZTSN3rmg8internal14ParticleShaderE", !28, i64 0, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36}
!34 = !{!"_ZTSN3rmg8internal12Line3DShaderE", !28, i64 0, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!35 = !{!"_ZTSN3rmg8internal13ContextLoaderE", !36, i64 0}
!36 = !{!"_ZTSN3rmg8internal12PendingStackE", !6, i64 0, !37, i64 8, !12, i64 24}
!37 = !{!"_ZTSN3rmg8internal7PendingE", !6, i64 0, !6, i64 8}
!38 = !{!"_ZTSN3rmg8internal9GLContextE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296}
!39 = !{!"bool", !7, i64 0}
!40 = !{!41, !13, i64 0}
!41 = !{!"_ZTSN3rmg4RectE", !13, i64 0, !13, i64 2}
!42 = !{!11, !13, i64 14}
!43 = !{!41, !13, i64 2}


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

%"struct.rmg::Rect" = type { i16, i16 }
%"struct.rmg::Vec4" = type { %union.anon.6 }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = type { float, float, float, float }

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

declare { <2 x float>, <2 x float> } @_ZNK3rmg4Mat4mlERKNS_4Vec4E(ptr noundef nonnull align 4 dereferenceable(64), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg4Vec4C2ERKNS_4Vec3Ef(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(12), float noundef) unnamed_addr #2 align 2

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

declare noundef nonnull align 4 dereferenceable(64) ptr @_ZNK3rmg6Camera11getVPMatrixEv(ptr noundef nonnull align 4 dereferenceable(264)) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local i32 @_ZNK3rmg7Context13worldToScreenERKNS_4Vec3E(ptr noundef nonnull align 8 dereferenceable(1440) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) local_unnamed_addr #3 align 2 {
  %3 = alloca %"struct.rmg::Rect", align 4
  %4 = alloca %"struct.rmg::Vec4", align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = tail call noundef nonnull align 4 dereferenceable(64) ptr @_ZNK3rmg6Camera11getVPMatrixEv(ptr noundef nonnull align 4 dereferenceable(264) %5)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @_ZN3rmg4Vec4C2ERKNS_4Vec3Ef(ptr noundef nonnull align 4 dereferenceable(16) %4, ptr noundef nonnull align 4 dereferenceable(12) %1, float noundef 1.000000e+00)
  %7 = call { <2 x float>, <2 x float> } @_ZNK3rmg4Mat4mlERKNS_4Vec4E(ptr noundef nonnull align 4 dereferenceable(64) %6, ptr noundef nonnull align 4 dereferenceable(16) %4)
  %8 = extractvalue { <2 x float>, <2 x float> } %7, 0
  %9 = extractvalue { <2 x float>, <2 x float> } %7, 1
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  call void @_ZN3rmg4RectC2Ev(ptr noundef nonnull align 2 dereferenceable(4) %3)
  %10 = getelementptr inbounds i8, ptr %0, i64 12
  %11 = shufflevector <2 x float> %9, <2 x float> poison, <2 x i32> <i32 1, i32 1>
  %12 = fdiv <2 x float> %8, %11
  %13 = fadd <2 x float> %12, <float 1.000000e+00, float poison>
  %14 = fsub <2 x float> <float poison, float 1.000000e+00>, %12
  %15 = shufflevector <2 x float> %13, <2 x float> %14, <2 x i32> <i32 0, i32 3>
  %16 = load <2 x i16>, ptr %10, align 4, !tbaa !5
  %17 = uitofp <2 x i16> %16 to <2 x float>
  %18 = fmul <2 x float> %15, %17
  %19 = fmul <2 x float> %18, <float 5.000000e-01, float 5.000000e-01>
  %20 = fptoui <2 x float> %19 to <2 x i16>
  store <2 x i16> %20, ptr %3, align 4, !tbaa !5
  %.cast = bitcast <2 x i16> %20 to i32
  ret i32 %.cast
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,TailCallElimPass