; LLVM IR from achilles288/robot-monitor-graphics :: src/base/internal (object2d_shader)

; 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::Mat3" = type { %union.anon }
%union.anon = type { [3 x [3 x float]] }
%"struct.rmg::ColorRGBA" = type { float, float, float, float }
%"class.rmg::internal::Shader" = type <{ ptr, i32, [4 x i8] }>
%"class.rmg::internal::SpriteShader" = type { %"class.rmg::internal::Shader.base", i32, i32, i32, i32, i32 }
%"class.rmg::internal::Shader.base" = type <{ ptr, i32 }>

@_ZN3rmg8internal17glBindVertexArrayE = external global ptr, align 8
@_ZN3rmg8internalL10prevShaderE = external hidden global i32, align 4
@_ZN3rmg8internal12glUseProgramE = external global ptr, align 8
@_ZN3rmg8internal11glUniform1iE = external global ptr, align 8
@_ZN3rmg8internal18glUniformMatrix3fvE = external global ptr, align 8
@_ZN3rmg8internal12glUniform4fvE = external global ptr, 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 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 @_ZN3rmg8internal12SpriteShader6renderEPNS_8Sprite2DERKNS_4Mat3E(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(36) %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %"struct.rmg::Mat3", align 4
  %8 = alloca %"struct.rmg::ColorRGBA", align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds %"class.rmg::internal::Shader", ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %17, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call noundef ptr @_ZNK3rmg8Sprite2D10getTextureEv(ptr noundef nonnull align 8 dereferenceable(144) %14)
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %13, %3
  br label %54

18:                                               ; preds = %13
  %19 = load i32, ptr @_ZN3rmg8internalL10prevShaderE, align 4, !tbaa !12
  %20 = getelementptr inbounds %"class.rmg::internal::Shader", ptr %9, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp ne i32 %19, %21
  br i1 %22, label %23, label %33

23:                                               ; preds = %18
  %24 = load ptr, ptr @_ZN3rmg8internal12glUseProgramE, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.rmg::internal::Shader", ptr %9, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !9
  call void %24(i32 noundef %26)
  %27 = load ptr, ptr @_ZN3rmg8internal17glBindVertexArrayE, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.rmg::internal::SpriteShader", ptr %9, i32 0, i32 4
  %29 = load i32, ptr %28, align 8, !tbaa !13
  call void %27(i32 noundef %29)
  %30 = load ptr, ptr @_ZN3rmg8internal11glUniform1iE, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.rmg::internal::SpriteShader", ptr %9, i32 0, i32 3
  %32 = load i32, ptr %31, align 4, !tbaa !15
  call void %30(i32 noundef %32, i32 noundef 0)
  br label %33

33:                                               ; preds = %23, %18
  call void @llvm.lifetime.start.p0(i64 36, ptr %7) #4
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZNK3rmg8Object2D14getModelMatrixEv(ptr noundef nonnull align 8 dereferenceable(108) %35)
  call void @_ZNK3rmg4Mat3mlERKS0_(ptr dead_on_unwind writable sret(%"struct.rmg::Mat3") align 4 %7, ptr noundef nonnull align 4 dereferenceable(36) %34, ptr noundef nonnull align 4 dereferenceable(36) %36)
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call { <2 x float>, <2 x float> } @_ZNK3rmg6Object8getColorEv(ptr noundef nonnull align 8 dereferenceable(48) %37)
  %39 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 0
  %40 = extractvalue { <2 x float>, <2 x float> } %38, 0
  store <2 x float> %40, ptr %39, align 4
  %41 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 1
  %42 = extractvalue { <2 x float>, <2 x float> } %38, 1
  store <2 x float> %42, ptr %41, align 4
  %43 = load ptr, ptr @_ZN3rmg8internal18glUniformMatrix3fvE, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.rmg::internal::SpriteShader", ptr %9, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !16
  %46 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3rmg4Mat3ixEh(ptr noundef nonnull align 4 dereferenceable(36) %7, i8 noundef zeroext 0)
  %47 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat3RowixEh(ptr noundef nonnull align 4 dereferenceable(12) %46, i8 noundef zeroext 0)
  call void %43(i32 noundef %45, i32 noundef 1, i8 noundef zeroext 1, ptr noundef %47)
  %48 = load ptr, ptr @_ZN3rmg8internal12glUniform4fvE, align 8, !tbaa !5
  %49 = getelementptr inbounds %"class.rmg::internal::SpriteShader", ptr %9, i32 0, i32 2
  %50 = load i32, ptr %49, align 8, !tbaa !17
  %51 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg9ColorRGBAixEh(ptr noundef nonnull align 4 dereferenceable(16) %8, i8 noundef zeroext 0)
  call void %48(i32 noundef %50, i32 noundef 1, ptr noundef %51)
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = call noundef ptr @_ZNK3rmg8Sprite2D10getTextureEv(ptr noundef nonnull align 8 dereferenceable(144) %52)
  call void @_ZNK3rmg8internal13SpriteTexture4bindEv(ptr noundef nonnull align 8 dereferenceable(12) %53)
  call void @glDrawArrays(i32 noundef 4, i32 noundef 0, i32 noundef 6)
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr %7) #4
  br label %54

54:                                               ; preds = %33, %17
  ret void
}

declare noundef ptr @_ZNK3rmg8Sprite2D10getTextureEv(ptr noundef nonnull align 8 dereferenceable(144)) #2

declare void @_ZNK3rmg4Mat3mlERKS0_(ptr dead_on_unwind writable sret(%"struct.rmg::Mat3") align 4, ptr noundef nonnull align 4 dereferenceable(36), ptr noundef nonnull align 4 dereferenceable(36)) #2

declare noundef nonnull align 4 dereferenceable(36) ptr @_ZNK3rmg8Object2D14getModelMatrixEv(ptr noundef nonnull align 8 dereferenceable(108)) #2

declare { <2 x float>, <2 x float> } @_ZNK3rmg6Object8getColorEv(ptr noundef nonnull align 8 dereferenceable(48)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN3rmg4Mat3ixEh(ptr noundef nonnull align 4 dereferenceable(36), i8 noundef zeroext) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat3RowixEh(ptr noundef nonnull align 4 dereferenceable(12), i8 noundef zeroext) #3 align 2

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg9ColorRGBAixEh(ptr noundef nonnull align 4 dereferenceable(16), i8 noundef zeroext) #2

declare void @_ZNK3rmg8internal13SpriteTexture4bindEv(ptr noundef nonnull align 8 dereferenceable(12)) #2

declare void @glDrawArrays(i32 noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { inlinehint 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 #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 = !{!10, !11, i64 8}
!10 = !{!"_ZTSN3rmg8internal6ShaderE", !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 24}
!14 = !{!"_ZTSN3rmg8internal12SpriteShaderE", !10, i64 0, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!15 = !{!14, !11, i64 20}
!16 = !{!14, !11, i64 12}
!17 = !{!14, !11, i64 16}


; 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::Mat3" = type { %union.anon }
%union.anon = type { [3 x [3 x float]] }
%"struct.rmg::ColorRGBA" = type { float, float, float, float }

@_ZN3rmg8internal17glBindVertexArrayE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internalL10prevShaderE = external hidden local_unnamed_addr global i32, align 4
@_ZN3rmg8internal12glUseProgramE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal11glUniform1iE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal18glUniformMatrix3fvE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal12glUniform4fvE = external local_unnamed_addr global ptr, 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 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 @_ZN3rmg8internal12SpriteShader6renderEPNS_8Sprite2DERKNS_4Mat3E(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(36) %2) local_unnamed_addr #1 align 2 {
  %4 = alloca %"struct.rmg::Mat3", align 4
  %5 = alloca %"struct.rmg::ColorRGBA", align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %39, label %9

9:                                                ; preds = %3
  %10 = tail call noundef ptr @_ZNK3rmg8Sprite2D10getTextureEv(ptr noundef nonnull align 8 dereferenceable(144) %1)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %39, label %12

12:                                               ; preds = %9
  %13 = load i32, ptr @_ZN3rmg8internalL10prevShaderE, align 4, !tbaa !10
  %14 = load i32, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i32 %13, %14
  br i1 %.not, label %23, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr @_ZN3rmg8internal12glUseProgramE, align 8, !tbaa !11
  tail call void %16(i32 noundef %14)
  %17 = load ptr, ptr @_ZN3rmg8internal17glBindVertexArrayE, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !13
  tail call void %17(i32 noundef %19)
  %20 = load ptr, ptr @_ZN3rmg8internal11glUniform1iE, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %0, i64 20
  %22 = load i32, ptr %21, align 4, !tbaa !15
  tail call void %20(i32 noundef %22, i32 noundef 0)
  br label %23

23:                                               ; preds = %15, %12
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %4) #4
  %24 = tail call noundef nonnull align 4 dereferenceable(36) ptr @_ZNK3rmg8Object2D14getModelMatrixEv(ptr noundef nonnull align 8 dereferenceable(108) %1)
  call void @_ZNK3rmg4Mat3mlERKS0_(ptr dead_on_unwind nonnull writable sret(%"struct.rmg::Mat3") align 4 %4, ptr noundef nonnull align 4 dereferenceable(36) %2, ptr noundef nonnull align 4 dereferenceable(36) %24)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %25 = call { <2 x float>, <2 x float> } @_ZNK3rmg6Object8getColorEv(ptr noundef nonnull align 8 dereferenceable(48) %1)
  %26 = extractvalue { <2 x float>, <2 x float> } %25, 0
  store <2 x float> %26, ptr %5, align 8
  %27 = getelementptr inbounds i8, ptr %5, i64 8
  %28 = extractvalue { <2 x float>, <2 x float> } %25, 1
  store <2 x float> %28, ptr %27, align 8
  %29 = load ptr, ptr @_ZN3rmg8internal18glUniformMatrix3fvE, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %0, i64 12
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3rmg4Mat3ixEh(ptr noundef nonnull align 4 dereferenceable(36) %4, i8 noundef zeroext 0)
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat3RowixEh(ptr noundef nonnull align 4 dereferenceable(12) %32, i8 noundef zeroext 0)
  call void %29(i32 noundef %31, i32 noundef 1, i8 noundef zeroext 1, ptr noundef nonnull %33)
  %34 = load ptr, ptr @_ZN3rmg8internal12glUniform4fvE, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %0, i64 16
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg9ColorRGBAixEh(ptr noundef nonnull align 4 dereferenceable(16) %5, i8 noundef zeroext 0)
  call void %34(i32 noundef %36, i32 noundef 1, ptr noundef nonnull %37)
  %38 = call noundef ptr @_ZNK3rmg8Sprite2D10getTextureEv(ptr noundef nonnull align 8 dereferenceable(144) %1)
  call void @_ZNK3rmg8internal13SpriteTexture4bindEv(ptr noundef nonnull align 8 dereferenceable(12) %38)
  call void @glDrawArrays(i32 noundef 4, i32 noundef 0, i32 noundef 6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %4) #4
  br label %39

39:                                               ; preds = %3, %9, %23
  ret void
}

declare noundef ptr @_ZNK3rmg8Sprite2D10getTextureEv(ptr noundef nonnull align 8 dereferenceable(144)) local_unnamed_addr #2

declare void @_ZNK3rmg4Mat3mlERKS0_(ptr dead_on_unwind writable sret(%"struct.rmg::Mat3") align 4, ptr noundef nonnull align 4 dereferenceable(36), ptr noundef nonnull align 4 dereferenceable(36)) local_unnamed_addr #2

declare noundef nonnull align 4 dereferenceable(36) ptr @_ZNK3rmg8Object2D14getModelMatrixEv(ptr noundef nonnull align 8 dereferenceable(108)) local_unnamed_addr #2

declare { <2 x float>, <2 x float> } @_ZNK3rmg6Object8getColorEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN3rmg4Mat3ixEh(ptr noundef nonnull align 4 dereferenceable(36), i8 noundef zeroext) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat3RowixEh(ptr noundef nonnull align 4 dereferenceable(12), i8 noundef zeroext) local_unnamed_addr #3 align 2

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg9ColorRGBAixEh(ptr noundef nonnull align 4 dereferenceable(16), i8 noundef zeroext) local_unnamed_addr #2

declare void @_ZNK3rmg8internal13SpriteTexture4bindEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #2

declare void @glDrawArrays(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { inlinehint 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 #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, !7, i64 8}
!6 = !{!"_ZTSN3rmg8internal6ShaderE", !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !7, i64 24}
!14 = !{!"_ZTSN3rmg8internal12SpriteShaderE", !6, i64 0, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!15 = !{!14, !7, i64 20}
!16 = !{!14, !7, i64 12}
!17 = !{!14, !7, i64 16}


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