; LLVM IR from merpheus-dev/LavaEngine :: src/Platforms/OpenGL/GLShaderBank.ll (ZN4Lava6OpenGL12GLShaderBankD2Ev)

; 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::ShaderBank" = type { ptr, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::shared_ptr<Lava::Shader>, std::allocator<std::shared_ptr<Lava::Shader>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::shared_ptr<Lava::Shader>, std::allocator<std::shared_ptr<Lava::Shader>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::shared_ptr<Lava::Shader>, std::allocator<std::shared_ptr<Lava::Shader>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::shared_ptr<Lava::Shader>, std::allocator<std::shared_ptr<Lava::Shader>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.Lava::Shader" = type <{ ptr, i32, [4 x i8], ptr, ptr, i32, [4 x i8] }>

@_ZTVN4Lava6OpenGL12GLShaderBankE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8
@__glewDetachShader = external global ptr, align 8
@__glewDeleteShader = external global ptr, align 8
@__glewDeleteProgram = external global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Lava6OpenGL12GLShaderBankD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  store ptr getelementptr inbounds inrange(-16, 56) ({ [9 x ptr] }, ptr @_ZTVN4Lava6OpenGL12GLShaderBankE, i32 0, i32 0, i32 2), ptr %4, align 8, !tbaa !9
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds ptr, ptr %5, i64 4
  %7 = load ptr, ptr %6, align 8
  invoke void %7(ptr noundef nonnull align 8 dereferenceable(40) %4)
          to label %8 unwind label %46

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %37, %8
  %10 = load i32, ptr %3, align 4, !tbaa !11
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 2
  %13 = call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #3
  %14 = icmp ult i64 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %40

16:                                               ; preds = %9
  %17 = load ptr, ptr @__glewDetachShader, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 2
  %21 = load i32, ptr %3, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %22) #3
  %24 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN4Lava6ShaderELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %23) #3
  %25 = getelementptr inbounds %"class.Lava::Shader", ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !19
  invoke void %17(i32 noundef %19, i32 noundef %26)
          to label %27 unwind label %46

27:                                               ; preds = %16
  %28 = load ptr, ptr @__glewDeleteShader, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 2
  %30 = load i32, ptr %3, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %29, i64 noundef %31) #3
  %33 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN4Lava6ShaderELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %32) #3
  %34 = getelementptr inbounds %"class.Lava::Shader", ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !19
  invoke void %28(i32 noundef %35)
          to label %36 unwind label %46

36:                                               ; preds = %27
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %3, align 4, !tbaa !11
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !11
  br label %9, !llvm.loop !22

40:                                               ; preds = %15
  %41 = load ptr, ptr @__glewDeleteProgram, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !13
  invoke void %41(i32 noundef %43)
          to label %44 unwind label %46

44:                                               ; preds = %40
  %45 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 1
  store i32 -1, ptr %45, align 8, !tbaa !13
  call void @_ZN4Lava10ShaderBankD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %4) #3
  ret void

46:                                               ; preds = %40, %27, %16, %1
  %47 = landingpad { ptr, i32 }
          catch ptr null
  %48 = extractvalue { ptr, i32 } %47, 0
  call void @__clang_call_terminate(ptr %48) #4
  unreachable
}

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN4Lava6ShaderELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Lava10ShaderBankD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { noinline noreturn nounwind uwtable "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTSN4Lava10ShaderBankE", !12, i64 8, !15, i64 16}
!15 = !{!"_ZTSSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!20, !12, i64 8}
!20 = !{!"_ZTSN4Lava6ShaderE", !12, i64 8, !6, i64 16, !6, i64 24, !21, i64 32}
!21 = !{!"_ZTS10ShaderType", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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

@_ZTVN4Lava6OpenGL12GLShaderBankE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8
@__glewDetachShader = external local_unnamed_addr global ptr, align 8
@__glewDeleteShader = external local_unnamed_addr global ptr, align 8
@__glewDeleteProgram = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Lava6OpenGL12GLShaderBankD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  store ptr getelementptr inbounds inrange(-16, 56) (i8, ptr @_ZTVN4Lava6OpenGL12GLShaderBankE, i64 16), ptr %0, align 8, !tbaa !5
  %2 = load ptr, ptr getelementptr inbounds inrange(-48, 24) (i8, ptr @_ZTVN4Lava6OpenGL12GLShaderBankE, i64 48), align 8
  invoke void %2(ptr noundef nonnull align 8 dereferenceable(40) %0)
          to label %.preheader unwind label %.loopexit.split-lp

.preheader:                                       ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = tail call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #2
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  br label %9

._crit_edge:                                      ; preds = %22, %.preheader
  %6 = load ptr, ptr @__glewDeleteProgram, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !11
  invoke void %6(i32 noundef %8)
          to label %25 unwind label %.loopexit.split-lp

9:                                                ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %10 = load ptr, ptr @__glewDetachShader, align 8, !tbaa !8
  %11 = load i32, ptr %5, align 8, !tbaa !11
  %12 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #2
  %13 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN4Lava6ShaderELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %12) #2
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !18
  invoke void %10(i32 noundef %11, i32 noundef %15)
          to label %16 unwind label %.loopexit

16:                                               ; preds = %9
  %17 = load ptr, ptr @__glewDeleteShader, align 8, !tbaa !8
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #2
  %19 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN4Lava6ShaderELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %18) #2
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !18
  invoke void %17(i32 noundef %21)
          to label %22 unwind label %.loopexit

22:                                               ; preds = %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = tail call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #2
  %24 = icmp ugt i64 %23, %indvars.iv.next
  br i1 %24, label %9, label %._crit_edge, !llvm.loop !21

25:                                               ; preds = %._crit_edge
  store i32 -1, ptr %7, align 8, !tbaa !11
  tail call void @_ZN4Lava10ShaderBankD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #2
  ret void

.loopexit:                                        ; preds = %9, %16
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %26

.loopexit.split-lp:                               ; preds = %1, %._crit_edge
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %26

26:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %27 = extractvalue { ptr, i32 } %lpad.phi, 0
  tail call void @__clang_call_terminate(ptr %27) #3
  unreachable
}

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Lava10ShaderBankD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { noinline noreturn nounwind uwtable "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 = { nounwind }
attributes #3 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTSN4Lava10ShaderBankE", !13, i64 8, !14, i64 16}
!13 = !{!"int", !10, i64 0}
!14 = !{!"_ZTSSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE17_Vector_impl_dataE", !9, i64 0, !9, i64 8, !9, i64 16}
!18 = !{!19, !13, i64 8}
!19 = !{!"_ZTSN4Lava6ShaderE", !13, i64 8, !9, i64 16, !9, i64 24, !20, i64 32}
!20 = !{!"_ZTS10ShaderType", !10, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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