; LLVM IR from merpheus-dev/LavaEngine :: src/Platforms/OpenGL (GLStandardRenderer)

; 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.Lava::Entity" = type { %"class.Lava::SceneObject", ptr, ptr, ptr, ptr }
%"class.Lava::SceneObject" = type { ptr }
%"struct.Lava::Mesh" = type { ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32 }
%"struct.Lava::OpenGL::GLRenderObject" = type { %"struct.Lava::RenderObject", %"class.std::shared_ptr.41", %"class.std::shared_ptr.41", %"class.std::shared_ptr.44", %"class.std::shared_ptr.41", %"class.std::shared_ptr.41", ptr, ptr }
%"struct.Lava::RenderObject" = type { %"struct.Lava::Mesh", %"struct.Lava::Material" }
%"struct.Lava::Material" = type <{ ptr, ptr, ptr, %"struct.glm::vec.28", [4 x i8], ptr, i32, i8, i8, [2 x i8], [3 x float], float, float, [4 x i8] }>
%"struct.glm::vec.28" = type { %union.anon.29, %union.anon.30, %union.anon.31 }
%union.anon.29 = type { float }
%union.anon.30 = type { float }
%union.anon.31 = type { float }
%"class.std::shared_ptr.44" = type { %"class.std::__shared_ptr.45" }
%"class.std::__shared_ptr.45" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.std::shared_ptr.41" = type { %"class.std::__shared_ptr.42" }
%"class.std::__shared_ptr.42" = type { ptr, %"class.std::__shared_count" }

@__glewDisableVertexAttribArray = 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
declare dso_local noundef ptr @_ZN4Lava6Entity15GetMeshRendererENS_8PlatformE(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4Lava12MeshRenderer15GetRenderObjectEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Lava6OpenGL18GLStandardRenderer13UnBindObjectsEPNS_6EntityE(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %20, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %"class.Lava::Entity", ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %"struct.Lava::Mesh", ptr %12, i32 0, i32 11
  %14 = load i32, ptr %13, align 8, !tbaa !14
  %15 = icmp slt i32 %9, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %23

17:                                               ; preds = %8
  %18 = load ptr, ptr @__glewDisableVertexAttribArray, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  call void %18(i32 noundef %19)
  br label %20

20:                                               ; preds = %17
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !16

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call noundef ptr @_ZN4Lava6Entity15GetMeshRendererENS_8PlatformE(ptr noundef nonnull align 8 dereferenceable(40) %24, i32 noundef 0)
  %26 = call noundef ptr @_ZN4Lava12MeshRenderer15GetRenderObjectEv(ptr noundef nonnull align 8 dereferenceable(24) %25)
  store ptr %26, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.Lava::OpenGL::GLRenderObject", ptr %27, i32 0, i32 6
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  %30 = load ptr, ptr %29, align 8, !tbaa !30
  %31 = getelementptr inbounds ptr, ptr %30, i64 3
  %32 = load ptr, ptr %31, align 8
  call void %32(ptr noundef nonnull align 8 dereferenceable(56) %29)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTSN4Lava6EntityE", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!"_ZTSN4Lava11SceneObjectE"}
!14 = !{!15, !10, i64 88}
!15 = !{!"_ZTSN4Lava4MeshE", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !10, i64 56, !6, i64 64, !10, i64 72, !6, i64 80, !10, i64 88}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 256}
!19 = !{!"_ZTSN4Lava6OpenGL14GLRenderObjectE", !20, i64 0, !25, i64 176, !25, i64 192, !28, i64 208, !25, i64 224, !25, i64 240, !6, i64 256, !6, i64 264}
!20 = !{!"_ZTSN4Lava12RenderObjectE", !15, i64 0, !21, i64 96}
!21 = !{!"_ZTSN4Lava8MaterialE", !6, i64 0, !6, i64 8, !6, i64 16, !22, i64 24, !6, i64 40, !10, i64 48, !23, i64 52, !23, i64 53, !7, i64 56, !24, i64 68, !24, i64 72}
!22 = !{!"_ZTSN3glm3vecILi3EfLNS_9qualifierE0EEE", !7, i64 0, !7, i64 4, !7, i64 8}
!23 = !{!"bool", !7, i64 0}
!24 = !{!"float", !7, i64 0}
!25 = !{!"_ZTSSt10shared_ptrIN4Lava6OpenGL14GLVertexBufferEE", !26, i64 0}
!26 = !{!"_ZTSSt12__shared_ptrIN4Lava6OpenGL14GLVertexBufferELN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !27, i64 8}
!27 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0}
!28 = !{!"_ZTSSt10shared_ptrIN4Lava6OpenGL13GLIndexBufferEE", !29, i64 0}
!29 = !{!"_ZTSSt12__shared_ptrIN4Lava6OpenGL13GLIndexBufferELN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !27, i64 8}
!30 = !{!31, !31, i64 0}
!31 = !{!"vtable pointer", !8, 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"

@__glewDisableVertexAttribArray = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4Lava6Entity15GetMeshRendererENS_8PlatformE(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4Lava12MeshRenderer15GetRenderObjectEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Lava6OpenGL18GLStandardRenderer13UnBindObjectsEPNS_6EntityE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(96) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 88
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  %8 = tail call noundef ptr @_ZN4Lava6Entity15GetMeshRendererENS_8PlatformE(ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef 0)
  %9 = tail call noundef ptr @_ZN4Lava12MeshRenderer15GetRenderObjectEv(ptr noundef nonnull align 8 dereferenceable(24) %8)
  %10 = getelementptr inbounds i8, ptr %9, i64 256
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %11, align 8, !tbaa !26
  %13 = getelementptr inbounds i8, ptr %12, i64 24
  %14 = load ptr, ptr %13, align 8
  tail call void %14(ptr noundef nonnull align 8 dereferenceable(56) %11)
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.06 = phi i32 [ %16, %.lr.ph ], [ 0, %2 ]
  %15 = load ptr, ptr @__glewDisableVertexAttribArray, align 8, !tbaa !28
  tail call void %15(i32 noundef %.06)
  %16 = add nuw nsw i32 %.06, 1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 88
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp slt i32 %16, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !29
}

attributes #0 = { 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 #1 = { 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" }

!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, !8, i64 24}
!6 = !{!"_ZTSN4Lava6EntityE", !7, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32}
!7 = !{!"_ZTSN4Lava11SceneObjectE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !13, i64 88}
!12 = !{!"_ZTSN4Lava4MeshE", !8, i64 0, !13, i64 8, !8, i64 16, !13, i64 24, !8, i64 32, !13, i64 40, !8, i64 48, !13, i64 56, !8, i64 64, !13, i64 72, !8, i64 80, !13, i64 88}
!13 = !{!"int", !9, i64 0}
!14 = !{!15, !8, i64 256}
!15 = !{!"_ZTSN4Lava6OpenGL14GLRenderObjectE", !16, i64 0, !21, i64 176, !21, i64 192, !24, i64 208, !21, i64 224, !21, i64 240, !8, i64 256, !8, i64 264}
!16 = !{!"_ZTSN4Lava12RenderObjectE", !12, i64 0, !17, i64 96}
!17 = !{!"_ZTSN4Lava8MaterialE", !8, i64 0, !8, i64 8, !8, i64 16, !18, i64 24, !8, i64 40, !13, i64 48, !19, i64 52, !19, i64 53, !9, i64 56, !20, i64 68, !20, i64 72}
!18 = !{!"_ZTSN3glm3vecILi3EfLNS_9qualifierE0EEE", !9, i64 0, !9, i64 4, !9, i64 8}
!19 = !{!"bool", !9, i64 0}
!20 = !{!"float", !9, i64 0}
!21 = !{!"_ZTSSt10shared_ptrIN4Lava6OpenGL14GLVertexBufferEE", !22, i64 0}
!22 = !{!"_ZTSSt12__shared_ptrIN4Lava6OpenGL14GLVertexBufferELN9__gnu_cxx12_Lock_policyE2EE", !8, i64 0, !23, i64 8}
!23 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !8, i64 0}
!24 = !{!"_ZTSSt10shared_ptrIN4Lava6OpenGL13GLIndexBufferEE", !25, i64 0}
!25 = !{!"_ZTSSt12__shared_ptrIN4Lava6OpenGL13GLIndexBufferELN9__gnu_cxx12_Lock_policyE2EE", !8, i64 0, !23, i64 8}
!26 = !{!27, !27, i64 0}
!27 = !{!"vtable pointer", !10, i64 0}
!28 = !{!8, !8, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass