; LLVM IR from PyCee/NUS_library :: src (NUS_vulkan)

; 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"

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@vulkan_library = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1
@vkGetInstanceProcAddr = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@vkCreateInstance = external dso_local global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@vkEnumerateInstanceExtensionProperties = external dso_local global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [35 x i8], align 1
@vkEnumerateInstanceLayerProperties = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_load_global_vulkan_library() #0 {
  %1 = alloca i32, align 4
  %2 = call ptr @dlopen(ptr noundef @.str, i32 noundef 2) #3
  store ptr %2, ptr @vulkan_library, align 8, !tbaa !5
  %3 = load ptr, ptr @vulkan_library, align 8, !tbaa !5
  %4 = icmp eq ptr null, %3
  br i1 %4, label %5, label %7

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

7:                                                ; preds = %0
  br label %8

8:                                                ; preds = %7
  %9 = load ptr, ptr @vulkan_library, align 8, !tbaa !5
  %10 = call ptr @dlsym(ptr noundef %9, ptr noundef @.str.2) #3
  store ptr %10, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %14, label %12

12:                                               ; preds = %8
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef @.str.2)
  br label %14

14:                                               ; preds = %12, %8
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  %18 = call ptr %17(ptr noundef null, ptr noundef @.str.4)
  store ptr %18, ptr @vkCreateInstance, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %22, label %20

20:                                               ; preds = %16
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef @.str.4)
  br label %22

22:                                               ; preds = %20, %16
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  %26 = call ptr %25(ptr noundef null, ptr noundef @.str.5)
  store ptr %26, ptr @vkEnumerateInstanceExtensionProperties, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %30, label %28

28:                                               ; preds = %24
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef @.str.5)
  br label %30

30:                                               ; preds = %28, %24
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  %34 = call ptr %33(ptr noundef null, ptr noundef @.str.6)
  store ptr %34, ptr @vkEnumerateInstanceLayerProperties, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %38, label %36

36:                                               ; preds = %32
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef @.str.6)
  br label %38

38:                                               ; preds = %36, %32
  br label %39

39:                                               ; preds = %38
  store i32 1, ptr %1, align 4
  br label %40

40:                                               ; preds = %39, %5
  %41 = load i32, ptr %1, align 4
  ret i32 %41
}

; Function Attrs: nounwind
declare ptr @dlopen(ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind
declare ptr @dlsym(ptr noundef, ptr noundef) #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 = { 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 = { "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 = { 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"}


; 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 = external hidden unnamed_addr constant [15 x i8], align 1
@vulkan_library = external hidden local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1
@vkGetInstanceProcAddr = external dso_local local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@vkCreateInstance = external dso_local local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@vkEnumerateInstanceExtensionProperties = external dso_local local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [35 x i8], align 1
@vkEnumerateInstanceLayerProperties = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_load_global_vulkan_library() local_unnamed_addr #0 {
  %1 = tail call ptr @dlopen(ptr noundef nonnull @.str, i32 noundef 2) #3
  store ptr %1, ptr @vulkan_library, align 8, !tbaa !5
  %2 = icmp eq ptr %1, null
  br i1 %2, label %3, label %5

3:                                                ; preds = %0
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %24

5:                                                ; preds = %0
  %6 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.2) #3
  store ptr %6, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %9

7:                                                ; preds = %5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull @.str.2)
  %.pre = load ptr, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %7, %5
  %10 = phi ptr [ %.pre, %7 ], [ %6, %5 ]
  %11 = tail call ptr %10(ptr noundef null, ptr noundef nonnull @.str.4) #3
  store ptr %11, ptr @vkCreateInstance, align 8, !tbaa !5
  %.not2 = icmp eq ptr %11, null
  br i1 %.not2, label %12, label %14

12:                                               ; preds = %9
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull @.str.4)
  br label %14

14:                                               ; preds = %12, %9
  %15 = load ptr, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  %16 = tail call ptr %15(ptr noundef null, ptr noundef nonnull @.str.5) #3
  store ptr %16, ptr @vkEnumerateInstanceExtensionProperties, align 8, !tbaa !5
  %.not3 = icmp eq ptr %16, null
  br i1 %.not3, label %17, label %19

17:                                               ; preds = %14
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull @.str.5)
  br label %19

19:                                               ; preds = %17, %14
  %20 = load ptr, ptr @vkGetInstanceProcAddr, align 8, !tbaa !5
  %21 = tail call ptr %20(ptr noundef null, ptr noundef nonnull @.str.6) #3
  store ptr %21, ptr @vkEnumerateInstanceLayerProperties, align 8, !tbaa !5
  %.not4 = icmp eq ptr %21, null
  br i1 %.not4, label %22, label %24

22:                                               ; preds = %19
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull @.str.6)
  br label %24

24:                                               ; preds = %22, %19, %3
  %.0 = phi i32 [ 0, %3 ], [ 1, %19 ], [ 1, %22 ]
  ret i32 %.0
}

; Function Attrs: nounwind
declare ptr @dlopen(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind
declare ptr @dlsym(ptr noundef, ptr noundef) local_unnamed_addr #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 = { 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 = { 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 #3 = { 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"}


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