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

; 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] }>

@__glewCreateProgram = external global ptr, align 8
@__glewAttachShader = external global ptr, align 8
@__glewLinkProgram = external global ptr, align 8
@__glewValidateProgram = 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 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) #1 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)) #1 align 2

; 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 void @_ZN4Lava6OpenGL12GLShaderBank12CheckLinkingEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Lava6OpenGL12GLShaderBank8ActivateEv(ptr noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #2 align 2 {
  %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
  %5 = load ptr, ptr @__glewCreateProgram, align 8, !tbaa !5
  %6 = call i32 %5()
  %7 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 1
  store i32 %6, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !16
  br label %8

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

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

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

26:                                               ; preds = %15
  %27 = load i32, ptr %3, align 4, !tbaa !16
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %3, align 4, !tbaa !16
  br label %8, !llvm.loop !20

29:                                               ; preds = %14
  %30 = load ptr, ptr @__glewLinkProgram, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !9
  call void %30(i32 noundef %32)
  %33 = load ptr, ptr @__glewValidateProgram, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.Lava::ShaderBank", ptr %4, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !9
  call void %33(i32 noundef %35)
  call void @_ZN4Lava6OpenGL12GLShaderBank12CheckLinkingEv(ptr noundef nonnull align 8 dereferenceable(40) %4)
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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, !11, i64 8}
!10 = !{!"_ZTSN4Lava10ShaderBankE", !11, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !11, i64 8}
!18 = !{!"_ZTSN4Lava6ShaderE", !11, i64 8, !6, i64 16, !6, i64 24, !19, i64 32}
!19 = !{!"_ZTS10ShaderType", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@__glewCreateProgram = external local_unnamed_addr global ptr, align 8
@__glewAttachShader = external local_unnamed_addr global ptr, align 8
@__glewLinkProgram = external local_unnamed_addr global ptr, align 8
@__glewValidateProgram = external local_unnamed_addr global ptr, align 8

; 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 uwtable
declare dso_local void @_ZN4Lava6OpenGL12GLShaderBank12CheckLinkingEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Lava6OpenGL12GLShaderBank8ActivateEv(ptr noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #1 align 2 {
  %2 = load ptr, ptr @__glewCreateProgram, align 8, !tbaa !5
  %3 = tail call i32 %2()
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %3, ptr %4, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = tail call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  %7 = load ptr, ptr @__glewLinkProgram, align 8, !tbaa !5
  %8 = load i32, ptr %4, align 8, !tbaa !9
  tail call void %7(i32 noundef %8)
  %9 = load ptr, ptr @__glewValidateProgram, align 8, !tbaa !5
  %10 = load i32, ptr %4, align 8, !tbaa !9
  tail call void %9(i32 noundef %10)
  tail call void @_ZN4Lava6OpenGL12GLShaderBank12CheckLinkingEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %11 = load ptr, ptr @__glewAttachShader, align 8, !tbaa !5
  %12 = load i32, ptr %4, align 8, !tbaa !9
  %13 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #2
  %14 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN4Lava6ShaderELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %13) #2
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !16
  tail call void %11(i32 noundef %12, i32 noundef %16)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = tail call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %18 = icmp ugt i64 %17, %indvars.iv.next
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !19
}

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 = { 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 = { 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 = !{!"_ZTSN4Lava10ShaderBankE", !11, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt6vectorISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN4Lava6ShaderEESaIS3_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!17, !11, i64 8}
!17 = !{!"_ZTSN4Lava6ShaderE", !11, i64 8, !6, i64 16, !6, i64 24, !18, i64 32}
!18 = !{!"_ZTS10ShaderType", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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