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

; 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_submission_queue = type { ptr, ptr, %struct.VkSubmitInfo, [10 x ptr], [10 x ptr], [10 x i32], [10 x ptr] }
%struct.VkSubmitInfo = type { i32, ptr, i32, ptr, ptr, i32, ptr, i32, ptr }

@vkQueueWaitIdle = external dso_local global ptr, align 8
@vkResetFences = external dso_local global ptr, align 8
@vkQueueSubmit = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [47 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_submission_queue_submit(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.NUS_submission_queue, ptr %6, i32 0, i32 2
  %8 = getelementptr inbounds %struct.VkSubmitInfo, ptr %7, i32 0, i32 5
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp ugt i32 %9, 0
  br i1 %10, label %11, label %37

11:                                               ; preds = %2
  %12 = load ptr, ptr @vkQueueWaitIdle, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.NUS_submission_queue, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = call i32 %12(ptr noundef %15)
  %17 = load ptr, ptr @vkResetFences, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.NUS_submission_queue, ptr %19, i32 0, i32 0
  %21 = call i32 %17(ptr noundef %18, i32 noundef 1, ptr noundef %20)
  %22 = load ptr, ptr @vkQueueSubmit, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.NUS_submission_queue, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NUS_submission_queue, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.NUS_submission_queue, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = call i32 %22(ptr noundef %25, i32 noundef 1, ptr noundef %27, ptr noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %11
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 0, ptr %3, align 4
  br label %38

35:                                               ; preds = %11
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  call void @nus_submission_queue_reset(ptr noundef %36)
  br label %37

37:                                               ; preds = %35, %2
  store i32 1, ptr %3, align 4
  br label %38

38:                                               ; preds = %37, %33
  %39 = load i32, ptr %3, align 4
  ret i32 %39
}

; Function Attrs: nounwind uwtable
declare hidden void @nus_submission_queue_reset(ptr noundef) #1

attributes #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 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" }

!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, !12, i64 56}
!10 = !{!"NUS_submission_queue", !6, i64 0, !6, i64 8, !11, i64 16, !7, i64 88, !7, i64 168, !7, i64 248, !7, i64 288}
!11 = !{!"VkSubmitInfo", !12, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !12, i64 56, !6, i64 64}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, 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"

@vkQueueWaitIdle = external dso_local local_unnamed_addr global ptr, align 8
@vkResetFences = external dso_local local_unnamed_addr global ptr, align 8
@vkQueueSubmit = external dso_local local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [47 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_submission_queue_submit(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %20, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr @vkQueueWaitIdle, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = tail call i32 %7(ptr noundef %9) #2
  %11 = load ptr, ptr @vkResetFences, align 8, !tbaa !12
  %12 = tail call i32 %11(ptr noundef %1, i32 noundef 1, ptr noundef nonnull %0) #2
  %13 = load ptr, ptr @vkQueueSubmit, align 8, !tbaa !12
  %14 = load ptr, ptr %8, align 8, !tbaa !13
  %15 = load ptr, ptr %0, align 8, !tbaa !14
  %16 = tail call i32 %13(ptr noundef %14, i32 noundef 1, ptr noundef nonnull %6, ptr noundef %15) #2
  %.not8 = icmp eq i32 %16, 0
  br i1 %.not8, label %19, label %17

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

19:                                               ; preds = %5
  tail call void @nus_submission_queue_reset(ptr noundef nonnull %0)
  br label %20

20:                                               ; preds = %2, %19, %17
  %.0 = phi i32 [ 0, %17 ], [ 1, %19 ], [ 1, %2 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @nus_submission_queue_reset(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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, !11, i64 56}
!6 = !{!"NUS_submission_queue", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 88, !8, i64 168, !8, i64 248, !8, i64 288}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"VkSubmitInfo", !11, i64 0, !7, i64 8, !11, i64 16, !7, i64 24, !7, i64 32, !11, i64 40, !7, i64 48, !11, i64 56, !7, i64 64}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 0}


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