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

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.294 = external hidden unnamed_addr constant [26 x i8], align 1
@__PRETTY_FUNCTION__.vmaCreateAllocator = external hidden unnamed_addr constant [94 x i8], align 1
@.str.295 = external hidden unnamed_addr constant [164 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: mustprogress uwtable
declare dso_local noundef i32 @_ZN14VmaAllocator_T4InitEPK22VmaAllocatorCreateInfo(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local i32 @vmaCreateAllocator(ptr noundef %0, ptr noundef %1) #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, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br label %11

11:                                               ; preds = %8, %2
  %12 = phi i1 [ false, %2 ], [ %10, %8 ]
  br i1 %12, label %13, label %14

13:                                               ; preds = %11
  br label %16

14:                                               ; preds = %11
  call void @__assert_fail(ptr noundef @.str.294, ptr noundef @.str.2, i32 noundef 16142, ptr noundef @__PRETTY_FUNCTION__.vmaCreateAllocator) #3
  unreachable

15:                                               ; No predecessors!
  br label %16

16:                                               ; preds = %15, %13
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.VmaAllocatorCreateInfo, ptr %17, i32 0, i32 9
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %36, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.VmaAllocatorCreateInfo, ptr %22, i32 0, i32 9
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = lshr i32 %24, 22
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %34

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.VmaAllocatorCreateInfo, ptr %28, i32 0, i32 9
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = lshr i32 %30, 12
  %32 = and i32 %31, 1023
  %33 = icmp ule i32 %32, 3
  br label %34

34:                                               ; preds = %27, %21
  %35 = phi i1 [ false, %21 ], [ %33, %27 ]
  br label %36

36:                                               ; preds = %34, %16
  %37 = phi i1 [ true, %16 ], [ %35, %34 ]
  br i1 %37, label %38, label %39

38:                                               ; preds = %36
  br label %41

39:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.295, ptr noundef @.str.2, i32 noundef 16144, ptr noundef @__PRETTY_FUNCTION__.vmaCreateAllocator) #3
  unreachable

40:                                               ; No predecessors!
  br label %41

41:                                               ; preds = %40, %38
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.VmaAllocatorCreateInfo, ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = call noundef ptr @_ZL11VmaAllocateI14VmaAllocator_TEPT_PK21VkAllocationCallbacks(ptr noundef %44)
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN14VmaAllocator_TC1EPK22VmaAllocatorCreateInfo(ptr noundef nonnull align 8 dereferenceable(5916) %45, ptr noundef %46)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %45, ptr %47, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = call noundef i32 @_ZN14VmaAllocator_T4InitEPK22VmaAllocatorCreateInfo(ptr noundef nonnull align 8 dereferenceable(5916) %49, ptr noundef %50)
  store i32 %51, ptr %5, align 4, !tbaa !14
  %52 = load i32, ptr %5, align 4, !tbaa !14
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %61

54:                                               ; preds = %41
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.VmaAllocatorCreateInfo, ptr %55, i32 0, i32 4
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  call void @_ZL10vma_deleteI14VmaAllocator_TEvPK21VkAllocationCallbacksPT_(ptr noundef %57, ptr noundef %59)
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %60, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %54, %41
  %62 = load i32, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %62
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL11VmaAllocateI14VmaAllocator_TEPT_PK21VkAllocationCallbacks(ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL10vma_deleteI14VmaAllocator_TEvPK21VkAllocationCallbacksPT_(ptr noundef, ptr noundef) #2

declare void @_ZN14VmaAllocator_TC1EPK22VmaAllocatorCreateInfo(ptr, ptr)

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 = { 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 = { noreturn nounwind }
attributes #4 = { 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 72}
!10 = !{!"_ZTS22VmaAllocatorCreateInfo", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !6, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 32}
!14 = !{!15, !15, i64 0}
!15 = !{!"_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"

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.294 = external hidden unnamed_addr constant [26 x i8], align 1
@__PRETTY_FUNCTION__.vmaCreateAllocator = external hidden unnamed_addr constant [94 x i8], align 1
@.str.295 = external hidden unnamed_addr constant [164 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN14VmaAllocator_T4InitEPK22VmaAllocatorCreateInfo(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @vmaCreateAllocator(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %5 = and i1 %3, %4
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.294, ptr noundef nonnull @.str.2, i32 noundef 16142, ptr noundef nonnull @__PRETTY_FUNCTION__.vmaCreateAllocator) #2
  unreachable

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp eq i32 %9, 0
  %11 = and i32 %9, -16384
  %or.cond = icmp eq i32 %11, 4194304
  %or.cond19 = or i1 %10, %or.cond
  br i1 %or.cond19, label %.critedge, label %.critedge2

.critedge2:                                       ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.295, ptr noundef nonnull @.str.2, i32 noundef 16144, ptr noundef nonnull @__PRETTY_FUNCTION__.vmaCreateAllocator) #2
  unreachable

.critedge:                                        ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = tail call noundef ptr @_ZL11VmaAllocateI14VmaAllocator_TEPT_PK21VkAllocationCallbacks(ptr noundef %13)
  tail call void @_ZN14VmaAllocator_TC1EPK22VmaAllocatorCreateInfo(ptr noundef nonnull align 8 dereferenceable(5916) %14, ptr noundef nonnull %0)
  store ptr %14, ptr %1, align 8, !tbaa !13
  %15 = tail call noundef i32 @_ZN14VmaAllocator_T4InitEPK22VmaAllocatorCreateInfo(ptr noundef nonnull align 8 dereferenceable(5916) %14, ptr noundef nonnull %0)
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %.critedge
  %18 = load ptr, ptr %12, align 8, !tbaa !12
  %19 = load ptr, ptr %1, align 8, !tbaa !13
  tail call void @_ZL10vma_deleteI14VmaAllocator_TEvPK21VkAllocationCallbacksPT_(ptr noundef %18, ptr noundef %19)
  store ptr null, ptr %1, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %17, %.critedge
  ret i32 %15
}

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

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

declare void @_ZN14VmaAllocator_TC1EPK22VmaAllocatorCreateInfo(ptr, ptr) local_unnamed_addr

attributes #0 = { 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 #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 = { 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, !7, i64 72}
!6 = !{!"_ZTS22VmaAllocatorCreateInfo", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !7, i64 72, !10, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 32}
!13 = !{!10, !10, i64 0}


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