; LLVM IR from PyCee/NUS_library :: src/gpu (NUS_gpu)

; 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.NUS_gpu = type { ptr, ptr, ptr, %struct.NUS_vk_device_functions, ptr, ptr, %struct.VkPhysicalDeviceMemoryProperties, i32, i32 }
%struct.NUS_vk_device_functions = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.VkPhysicalDeviceMemoryProperties = type { i32, [32 x %struct.VkMemoryType], i32, [16 x %struct.VkMemoryHeap] }
%struct.VkMemoryType = type { i32, i32 }
%struct.VkMemoryHeap = type { i64, i32 }
%struct.VkFormatProperties = type { i32, i32, i32 }

@vkGetPhysicalDeviceFormatProperties = external dso_local 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_gpu_qwery_format_support(ptr noundef byval(%struct.NUS_gpu) align 8 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.VkFormatProperties, align 4
  %10 = alloca i32, align 4
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %9) #2
  %11 = load ptr, ptr @vkGetPhysicalDeviceFormatProperties, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.NUS_gpu, ptr %0, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load i32, ptr %6, align 4, !tbaa !5
  call void %11(ptr noundef %13, i32 noundef %14, ptr noundef %9)
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %24

17:                                               ; preds = %4
  %18 = getelementptr inbounds %struct.VkFormatProperties, ptr %9, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = and i32 %19, %20
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %34, label %24

24:                                               ; preds = %17, %4
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %35

27:                                               ; preds = %24
  %28 = getelementptr inbounds %struct.VkFormatProperties, ptr %9, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !17
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = and i32 %29, %30
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = icmp eq i32 %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %27, %17
  store i32 1, ptr %5, align 4
  store i32 1, ptr %10, align 4
  br label %36

35:                                               ; preds = %27, %24
  store i32 0, ptr %5, align 4
  store i32 1, ptr %10, align 4
  br label %36

36:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #2
  %37 = load i32, ptr %5, align 4
  ret i32 %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 600}
!12 = !{!"NUS_gpu", !10, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !10, i64 600, !10, i64 608, !14, i64 616, !6, i64 1136, !6, i64 1140}
!13 = !{!"NUS_vk_device_functions", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !10, i64 392, !10, i64 400, !10, i64 408, !10, i64 416, !10, i64 424, !10, i64 432, !10, i64 440, !10, i64 448, !10, i64 456, !10, i64 464, !10, i64 472, !10, i64 480, !10, i64 488, !10, i64 496, !10, i64 504, !10, i64 512, !10, i64 520, !10, i64 528, !10, i64 536, !10, i64 544, !10, i64 552, !10, i64 560, !10, i64 568}
!14 = !{!"VkPhysicalDeviceMemoryProperties", !6, i64 0, !7, i64 4, !6, i64 260, !7, i64 264}
!15 = !{!16, !6, i64 0}
!16 = !{!"VkFormatProperties", !6, i64 0, !6, i64 4, !6, i64 8}
!17 = !{!16, !6, i64 4}


; 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.NUS_gpu = type { ptr, ptr, ptr, %struct.NUS_vk_device_functions, ptr, ptr, %struct.VkPhysicalDeviceMemoryProperties, i32, i32 }
%struct.NUS_vk_device_functions = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.VkPhysicalDeviceMemoryProperties = type { i32, [32 x %struct.VkMemoryType], i32, [16 x %struct.VkMemoryHeap] }
%struct.VkMemoryType = type { i32, i32 }
%struct.VkMemoryHeap = type { i64, i32 }
%struct.VkFormatProperties = type { i32, i32, i32 }

@vkGetPhysicalDeviceFormatProperties = external dso_local local_unnamed_addr global ptr, align 8

; 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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_gpu_qwery_format_support(ptr nocapture noundef readonly byval(%struct.NUS_gpu) align 8 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca %struct.VkFormatProperties, align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #2
  %6 = load ptr, ptr @vkGetPhysicalDeviceFormatProperties, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 600
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  call void %6(ptr noundef %8, i32 noundef %1, ptr noundef nonnull %5) #2
  switch i32 %2, label %18 [
    i32 1, label %9
    i32 0, label %13
  ]

9:                                                ; preds = %4
  %10 = load i32, ptr %5, align 4, !tbaa !14
  %11 = and i32 %10, %3
  %12 = icmp eq i32 %11, %3
  br i1 %12, label %19, label %18

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %5, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !16
  %16 = and i32 %15, %3
  %17 = icmp eq i32 %16, %3
  br i1 %17, label %19, label %18

18:                                               ; preds = %9, %4, %13
  br label %19

19:                                               ; preds = %9, %13, %18
  %.0 = phi i32 [ 0, %18 ], [ 1, %13 ], [ 1, %9 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #2
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 600}
!10 = !{!"NUS_gpu", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !6, i64 600, !6, i64 608, !12, i64 616, !13, i64 1136, !13, i64 1140}
!11 = !{!"NUS_vk_device_functions", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !6, i64 416, !6, i64 424, !6, i64 432, !6, i64 440, !6, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !6, i64 480, !6, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !6, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568}
!12 = !{!"VkPhysicalDeviceMemoryProperties", !13, i64 0, !7, i64 4, !13, i64 260, !7, i64 264}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"VkFormatProperties", !13, i64 0, !13, i64 4, !13, i64 8}
!16 = !{!15, !13, i64 4}


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