; LLVM IR from khushmmehta/Scorch-V :: src/ScorchVkEngine/Abstractions (VulkanMemoryAllocator)

; 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.VkAllocationCallbacks = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.VmaVirtualBlock_T = type { i8, %struct.VkAllocationCallbacks, ptr }
%struct.VmaVirtualBlockCreateInfo = type { i64, i32, ptr }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [2 x i8], align 1
@_ZL27VmaEmptyAllocationCallbacks = external hidden global %struct.VkAllocationCallbacks, align 8
@__PRETTY_FUNCTION__._ZN17VmaVirtualBlock_TC2ERK25VmaVirtualBlockCreateInfo = external hidden unnamed_addr constant [72 x i8], align 1

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17VmaVirtualBlock_TC2ERK25VmaVirtualBlockCreateInfo(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %struct.VmaVirtualBlock_T, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.VmaVirtualBlockCreateInfo, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  %12 = zext i1 %11 to i8
  store i8 %12, ptr %7, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.VmaVirtualBlock_T, ptr %6, i32 0, i32 1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.VmaVirtualBlockCreateInfo, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.VmaVirtualBlockCreateInfo, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  br label %23

22:                                               ; preds = %2
  br label %23

23:                                               ; preds = %22, %18
  %24 = phi ptr [ %21, %18 ], [ @_ZL27VmaEmptyAllocationCallbacks, %22 ]
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %24, i64 48, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.VmaVirtualBlockCreateInfo, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = and i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !19
  %29 = load i32, ptr %5, align 4, !tbaa !19
  switch i32 %29, label %38 [
    i32 0, label %30
    i32 1, label %34
  ]

30:                                               ; preds = %23
  %31 = call noundef ptr @_ZNK17VmaVirtualBlock_T22GetAllocationCallbacksEv(ptr noundef nonnull align 8 dereferenceable(64) %6)
  %32 = call noundef ptr @_ZL11VmaAllocateI21VmaBlockMetadata_TLSFEPT_PK21VkAllocationCallbacks(ptr noundef %31)
  call void @_ZN21VmaBlockMetadata_TLSFC1EPK21VkAllocationCallbacksmb(ptr noundef nonnull align 8 dereferenceable(400) %32, ptr noundef null, i64 noundef 1, i1 noundef zeroext true)
  %33 = getelementptr inbounds %struct.VmaVirtualBlock_T, ptr %6, i32 0, i32 2
  store ptr %32, ptr %33, align 8, !tbaa !20
  br label %39

34:                                               ; preds = %23
  %35 = call noundef ptr @_ZNK17VmaVirtualBlock_T22GetAllocationCallbacksEv(ptr noundef nonnull align 8 dereferenceable(64) %6)
  %36 = call noundef ptr @_ZL11VmaAllocateI23VmaBlockMetadata_LinearEPT_PK21VkAllocationCallbacks(ptr noundef %35)
  call void @_ZN23VmaBlockMetadata_LinearC1EPK21VkAllocationCallbacksmb(ptr noundef nonnull align 8 dereferenceable(144) %36, ptr noundef null, i64 noundef 1, i1 noundef zeroext true)
  %37 = getelementptr inbounds %struct.VmaVirtualBlock_T, ptr %6, i32 0, i32 2
  store ptr %36, ptr %37, align 8, !tbaa !20
  br label %39

38:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.57, ptr noundef @.str.2, i32 noundef 11338, ptr noundef @__PRETTY_FUNCTION__._ZN17VmaVirtualBlock_TC2ERK25VmaVirtualBlockCreateInfo) #6
  unreachable

39:                                               ; preds = %34, %30
  %40 = getelementptr inbounds %struct.VmaVirtualBlock_T, ptr %6, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.VmaVirtualBlockCreateInfo, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !21
  %45 = load ptr, ptr %41, align 8, !tbaa !22
  %46 = getelementptr inbounds ptr, ptr %45, i64 2
  %47 = load ptr, ptr %46, align 8
  call void %47(ptr noundef nonnull align 8 dereferenceable(33) %41, i64 noundef %44)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL11VmaAllocateI21VmaBlockMetadata_TLSFEPT_PK21VkAllocationCallbacks(ptr noundef) #3

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

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL11VmaAllocateI23VmaBlockMetadata_LinearEPT_PK21VkAllocationCallbacks(ptr noundef) #3

declare void @_ZN23VmaBlockMetadata_LinearC1EPK21VkAllocationCallbacksmb(ptr, ptr, i64, i1)

declare void @_ZN21VmaBlockMetadata_TLSFC1EPK21VkAllocationCallbacksmb(ptr, ptr, i64, i1)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn nounwind "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"="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 = { 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 #5 = { nounwind }
attributes #6 = { 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, !6, i64 16}
!10 = !{!"_ZTS25VmaVirtualBlockCreateInfo", !11, i64 0, !12, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS17VmaVirtualBlock_T", !15, i64 0, !16, i64 8, !6, i64 56}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTS21VkAllocationCallbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5, i64 32, i64 8, !5, i64 40, i64 8, !5}
!18 = !{!10, !12, i64 8}
!19 = !{!12, !12, i64 0}
!20 = !{!14, !6, i64 56}
!21 = !{!10, !11, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"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"

%struct.VkAllocationCallbacks = type { ptr, ptr, ptr, ptr, ptr, ptr }

@_ZL27VmaEmptyAllocationCallbacks = external hidden local_unnamed_addr global %struct.VkAllocationCallbacks, align 8

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17VmaVirtualBlock_TC2ERK25VmaVirtualBlockCreateInfo(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  %6 = zext i1 %5 to i8
  store i8 %6, ptr %0, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %.not = icmp eq ptr %4, null
  %spec.select = select i1 %.not, ptr @_ZL27VmaEmptyAllocationCallbacks, ptr %4
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %7, ptr noundef nonnull align 8 dereferenceable(48) %spec.select, i64 48, i1 false), !tbaa.struct !16
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !18
  %trunc = trunc i32 %9 to i1
  %10 = tail call noundef ptr @_ZNK17VmaVirtualBlock_T22GetAllocationCallbacksEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  br i1 %trunc, label %13, label %11

11:                                               ; preds = %2
  %12 = tail call noundef ptr @_ZL11VmaAllocateI21VmaBlockMetadata_TLSFEPT_PK21VkAllocationCallbacks(ptr noundef %10)
  tail call void @_ZN21VmaBlockMetadata_TLSFC1EPK21VkAllocationCallbacksmb(ptr noundef nonnull align 8 dereferenceable(400) %12, ptr noundef null, i64 noundef 1, i1 noundef zeroext true)
  br label %15

13:                                               ; preds = %2
  %14 = tail call noundef ptr @_ZL11VmaAllocateI23VmaBlockMetadata_LinearEPT_PK21VkAllocationCallbacks(ptr noundef %10)
  tail call void @_ZN23VmaBlockMetadata_LinearC1EPK21VkAllocationCallbacksmb(ptr noundef nonnull align 8 dereferenceable(144) %14, ptr noundef null, i64 noundef 1, i1 noundef zeroext true)
  br label %15

15:                                               ; preds = %13, %11
  %.sink = phi ptr [ %14, %13 ], [ %12, %11 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %.sink, ptr %16, align 8
  %17 = load i64, ptr %1, align 8, !tbaa !19
  %18 = load ptr, ptr %.sink, align 8, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load ptr, ptr %19, align 8
  tail call void %20(ptr noundef nonnull align 8 dereferenceable(33) %.sink, i64 noundef %17)
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL11VmaAllocateI21VmaBlockMetadata_TLSFEPT_PK21VkAllocationCallbacks(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL11VmaAllocateI23VmaBlockMetadata_LinearEPT_PK21VkAllocationCallbacks(ptr noundef) local_unnamed_addr #1

declare void @_ZN23VmaBlockMetadata_LinearC1EPK21VkAllocationCallbacksmb(ptr, ptr, i64, i1) local_unnamed_addr

declare void @_ZN21VmaBlockMetadata_TLSFC1EPK21VkAllocationCallbacksmb(ptr, ptr, i64, i1) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree 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" }

!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, !11, i64 16}
!6 = !{!"_ZTS25VmaVirtualBlockCreateInfo", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTS17VmaVirtualBlock_T", !14, i64 0, !15, i64 8, !11, i64 56}
!14 = !{!"bool", !8, i64 0}
!15 = !{!"_ZTS21VkAllocationCallbacks", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!16 = !{i64 0, i64 8, !17, i64 8, i64 8, !17, i64 16, i64 8, !17, i64 24, i64 8, !17, i64 32, i64 8, !17, i64 40, i64 8, !17}
!17 = !{!11, !11, i64 0}
!18 = !{!6, !10, i64 8}
!19 = !{!6, !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass