; LLVM IR from PyCee/NUS_library :: src/gpu (NUS_multi_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_vulkan_instance = type { %struct.NUS_vk_instance_functions, ptr }
%struct.NUS_vk_instance_functions = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NUS_multi_gpu = type { ptr, i32 }
%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 }

@vkEnumeratePhysicalDevices = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [56 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_multi_gpu_build(ptr noundef byval(%struct.NUS_vulkan_instance) align 8 %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %9 = load ptr, ptr @vkEnumeratePhysicalDevices, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.NUS_vulkan_instance, ptr %0, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %12, i32 0, i32 1
  %14 = call i32 %9(ptr noundef %11, ptr noundef %13, ptr noundef null)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %21, label %16

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %20 = icmp eq i32 0, %19
  br i1 %20, label %21, label %26

21:                                               ; preds = %16, %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !12
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %24)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %79

26:                                               ; preds = %16
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !12
  %30 = zext i32 %29 to i64
  %31 = call ptr @llvm.stacksave.p0()
  store ptr %31, ptr %7, align 8
  %32 = alloca ptr, i64 %30, align 16
  store i64 %30, ptr %8, align 8
  %33 = load ptr, ptr @vkEnumeratePhysicalDevices, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.NUS_vulkan_instance, ptr %0, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %36, i32 0, i32 1
  %38 = call i32 %33(ptr noundef %35, ptr noundef %37, ptr noundef %32)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %26
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %77

42:                                               ; preds = %26
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !12
  %46 = zext i32 %45 to i64
  %47 = mul i64 1144, %46
  %48 = call noalias ptr @malloc(i64 noundef %47) #6
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %49, i32 0, i32 0
  store ptr %48, ptr %50, align 8, !tbaa !15
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %51

51:                                               ; preds = %73, %42
  %52 = load i32, ptr %5, align 4, !tbaa !16
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !12
  %56 = icmp ult i32 %52, %55
  br i1 %56, label %57, label %76

57:                                               ; preds = %51
  %58 = load i32, ptr %5, align 4, !tbaa !16
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds ptr, ptr %32, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.NUS_multi_gpu, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load i32, ptr %5, align 4, !tbaa !16
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds %struct.NUS_gpu, ptr %64, i64 %66
  %68 = call i32 @nus_gpu_build(ptr noundef %61, ptr noundef %67)
  %69 = icmp ne i32 %68, 1
  br i1 %69, label %70, label %72

70:                                               ; preds = %57
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %77

72:                                               ; preds = %57
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %5, align 4, !tbaa !16
  %75 = add i32 %74, 1
  store i32 %75, ptr %5, align 4, !tbaa !16
  br label %51, !llvm.loop !17

76:                                               ; preds = %51
  store i32 1, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %77

77:                                               ; preds = %76, %70, %40
  %78 = load ptr, ptr %7, align 8
  call void @llvm.stackrestore.p0(ptr %78)
  br label %79

79:                                               ; preds = %77, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

declare i32 @nus_gpu_build(ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { nounwind allocsize(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 = { nounwind allocsize(0) }

!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 128}
!10 = !{!"NUS_vulkan_instance", !11, i64 0, !6, i64 128}
!11 = !{!"NUS_vk_instance_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}
!12 = !{!13, !14, i64 8}
!13 = !{!"NUS_multi_gpu", !6, i64 0, !14, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !6, i64 0}
!16 = !{!14, !14, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.NUS_vulkan_instance = type { %struct.NUS_vk_instance_functions, ptr }
%struct.NUS_vk_instance_functions = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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 }

@vkEnumeratePhysicalDevices = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [56 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_multi_gpu_build(ptr nocapture noundef readonly byval(%struct.NUS_vulkan_instance) align 8 %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @vkEnumeratePhysicalDevices, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = tail call i32 %3(ptr noundef %5, ptr noundef nonnull %6, ptr noundef null) #5
  %.not = icmp ne i32 %7, 0
  %.pre = load i32, ptr %6, align 8, !tbaa !12
  %8 = icmp eq i32 %.pre, 0
  %or.cond = select i1 %.not, i1 true, i1 %8
  br i1 %or.cond, label %9, label %11

9:                                                ; preds = %2
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.pre)
  br label %32

11:                                               ; preds = %2
  %12 = zext i32 %.pre to i64
  %13 = tail call ptr @llvm.stacksave.p0()
  %14 = alloca ptr, i64 %12, align 16
  %15 = load ptr, ptr @vkEnumeratePhysicalDevices, align 8, !tbaa !5
  %16 = call i32 %15(ptr noundef %5, ptr noundef nonnull %6, ptr noundef nonnull %14) #5
  %.not16 = icmp eq i32 %16, 0
  br i1 %.not16, label %17, label %.loopexit.sink.split

17:                                               ; preds = %11
  %18 = load i32, ptr %6, align 8, !tbaa !12
  %19 = zext i32 %18 to i64
  %20 = mul nuw nsw i64 %19, 1144
  %21 = call noalias ptr @malloc(i64 noundef %20) #6
  store ptr %21, ptr %1, align 8, !tbaa !15
  %.not19 = icmp eq i32 %18, 0
  br i1 %.not19, label %.loopexit, label %.lr.ph

22:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %6, align 8, !tbaa !12
  %24 = zext i32 %23 to i64
  %25 = icmp ult i64 %indvars.iv.next, %24
  br i1 %25, label %.lr.ph, label %.loopexit, !llvm.loop !16

.lr.ph:                                           ; preds = %17, %22
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ 0, %17 ]
  %26 = getelementptr inbounds ptr, ptr %14, i64 %indvars.iv
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load ptr, ptr %1, align 8, !tbaa !15
  %29 = getelementptr inbounds %struct.NUS_gpu, ptr %28, i64 %indvars.iv
  %30 = call i32 @nus_gpu_build(ptr noundef %27, ptr noundef %29) #5
  %.not17 = icmp eq i32 %30, 1
  br i1 %.not17, label %22, label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %.lr.ph, %11
  %.str.2.sink = phi ptr [ @.str.1, %11 ], [ @.str.2, %.lr.ph ]
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  br label %.loopexit

.loopexit:                                        ; preds = %22, %.loopexit.sink.split, %17
  %.0 = phi i32 [ 1, %17 ], [ 0, %.loopexit.sink.split ], [ 1, %22 ]
  call void @llvm.stackrestore.p0(ptr %13)
  br label %32

32:                                               ; preds = %.loopexit, %9
  %.1 = phi i32 [ 0, %9 ], [ %.0, %.loopexit ]
  ret i32 %.1
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

declare i32 @nus_gpu_build(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

attributes #0 = { 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 = { nofree 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 nosync nounwind willreturn }
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { nounwind allocsize(0) }

!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 128}
!10 = !{!"NUS_vulkan_instance", !11, i64 0, !6, i64 128}
!11 = !{!"NUS_vk_instance_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}
!12 = !{!13, !14, i64 8}
!13 = !{!"NUS_multi_gpu", !6, i64 0, !14, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass