; 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.VkMemoryRequirements = type { i64, i64, i32 }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.347 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.vmaAllocateMemoryForBuffer = external hidden unnamed_addr constant [177 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 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) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK14VmaAllocator_T27GetBufferMemoryRequirementsEP10VkBuffer_TR20VkMemoryRequirementsRbS4_(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN14VmaAllocator_T14AllocateMemoryERK20VkMemoryRequirementsbbP10VkBuffer_TP9VkImage_TjRK23VmaAllocationCreateInfo20VmaSuballocationTypemPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef nonnull align 8 dereferenceable(24), i1 noundef zeroext, i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef, ptr noundef nonnull align 8 dereferenceable(48), i32 noundef, i64 noundef, ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14VmaAllocator_T17GetAllocationInfoEP15VmaAllocation_TP17VmaAllocationInfo(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef, ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local i32 @vmaAllocateMemoryForBuffer(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.VkMemoryRequirements, align 8
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %26

17:                                               ; preds = %5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %26

20:                                               ; preds = %17
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br label %26

26:                                               ; preds = %23, %20, %17, %5
  %27 = phi i1 [ false, %20 ], [ false, %17 ], [ false, %5 ], [ %25, %23 ]
  br i1 %27, label %28, label %29

28:                                               ; preds = %26
  br label %31

29:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.347, ptr noundef @.str.2, i32 noundef 16727, ptr noundef @__PRETTY_FUNCTION__.vmaAllocateMemoryForBuffer) #4
  unreachable

30:                                               ; No predecessors!
  br label %31

31:                                               ; preds = %30, %28
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #5
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #5
  store i8 0, ptr %12, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  store i8 0, ptr %13, align 1, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZNK14VmaAllocator_T27GetBufferMemoryRequirementsEP10VkBuffer_TR20VkMemoryRequirementsRbS4_(ptr noundef nonnull align 8 dereferenceable(5916) %32, ptr noundef %33, ptr noundef nonnull align 8 dereferenceable(24) %11, ptr noundef nonnull align 1 dereferenceable(1) %12, ptr noundef nonnull align 1 dereferenceable(1) %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i8, ptr %12, align 1, !tbaa !9, !range !11, !noundef !12
  %36 = trunc i8 %35 to i1
  %37 = load i8, ptr %13, align 1, !tbaa !9, !range !11, !noundef !12
  %38 = trunc i8 %37 to i1
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = call noundef i32 @_ZN14VmaAllocator_T14AllocateMemoryERK20VkMemoryRequirementsbbP10VkBuffer_TP9VkImage_TjRK23VmaAllocationCreateInfo20VmaSuballocationTypemPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(5916) %34, ptr noundef nonnull align 8 dereferenceable(24) %11, i1 noundef zeroext %36, i1 noundef zeroext %38, ptr noundef %39, ptr noundef null, i32 noundef -1, ptr noundef nonnull align 8 dereferenceable(48) %40, i32 noundef 2, i64 noundef 1, ptr noundef %41)
  store i32 %42, ptr %14, align 4, !tbaa !13
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %53

45:                                               ; preds = %31
  %46 = load i32, ptr %14, align 4, !tbaa !13
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %53

48:                                               ; preds = %45
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN14VmaAllocator_T17GetAllocationInfoEP15VmaAllocation_TP17VmaAllocationInfo(ptr noundef nonnull align 8 dereferenceable(5916) %49, ptr noundef %51, ptr noundef %52)
  br label %53

53:                                               ; preds = %48, %45, %31
  %54 = load i32, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #5
  ret i32 %54
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS8VkResult", !7, 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.VkMemoryRequirements = type { i64, i64, i32 }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.347 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.vmaAllocateMemoryForBuffer = external hidden unnamed_addr constant [177 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK14VmaAllocator_T27GetBufferMemoryRequirementsEP10VkBuffer_TR20VkMemoryRequirementsRbS4_(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN14VmaAllocator_T14AllocateMemoryERK20VkMemoryRequirementsbbP10VkBuffer_TP9VkImage_TjRK23VmaAllocationCreateInfo20VmaSuballocationTypemPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef nonnull align 8 dereferenceable(24), i1 noundef zeroext, i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef, ptr noundef nonnull align 8 dereferenceable(48), i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14VmaAllocator_T17GetAllocationInfoEP15VmaAllocation_TP17VmaAllocationInfo(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef, ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @vmaAllocateMemoryForBuffer(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca %struct.VkMemoryRequirements, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %10 = insertelement <4 x ptr> %9, ptr %1, i64 1
  %11 = insertelement <4 x ptr> %10, ptr %2, i64 2
  %12 = insertelement <4 x ptr> %11, ptr %3, i64 3
  %13 = icmp eq <4 x ptr> %12, zeroinitializer
  %14 = bitcast <4 x i1> %13 to i4
  %15 = icmp eq i4 %14, 0
  br i1 %15, label %16, label %.critedge

.critedge:                                        ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.347, ptr noundef nonnull @.str.2, i32 noundef 16727, ptr noundef nonnull @__PRETTY_FUNCTION__.vmaAllocateMemoryForBuffer) #4
  unreachable

16:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %7) #5
  store i8 0, ptr %7, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %8) #5
  store i8 0, ptr %8, align 1, !tbaa !5
  call void @_ZNK14VmaAllocator_T27GetBufferMemoryRequirementsEP10VkBuffer_TR20VkMemoryRequirementsRbS4_(ptr noundef nonnull align 8 dereferenceable(5916) %0, ptr noundef nonnull %1, ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 1 dereferenceable(1) %7, ptr noundef nonnull align 1 dereferenceable(1) %8)
  %17 = load i8, ptr %7, align 1, !tbaa !5, !range !9, !noundef !10
  %18 = trunc nuw i8 %17 to i1
  %19 = load i8, ptr %8, align 1, !tbaa !5, !range !9, !noundef !10
  %20 = trunc nuw i8 %19 to i1
  %21 = call noundef i32 @_ZN14VmaAllocator_T14AllocateMemoryERK20VkMemoryRequirementsbbP10VkBuffer_TP9VkImage_TjRK23VmaAllocationCreateInfo20VmaSuballocationTypemPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(5916) %0, ptr noundef nonnull align 8 dereferenceable(24) %6, i1 noundef zeroext %18, i1 noundef zeroext %20, ptr noundef nonnull %1, ptr noundef null, i32 noundef -1, ptr noundef nonnull align 8 dereferenceable(48) %2, i32 noundef 2, i64 noundef 1, ptr noundef nonnull %3)
  %22 = icmp ne ptr %4, null
  %23 = icmp eq i32 %21, 0
  %or.cond5 = and i1 %22, %23
  br i1 %or.cond5, label %24, label %26

24:                                               ; preds = %16
  %25 = load ptr, ptr %3, align 8, !tbaa !11
  call void @_ZN14VmaAllocator_T17GetAllocationInfoEP15VmaAllocation_TP17VmaAllocationInfo(ptr noundef nonnull align 8 dereferenceable(5916) %0, ptr noundef %25, ptr noundef nonnull %4)
  br label %26

26:                                               ; preds = %24, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #5
  ret i32 %21
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass