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

; 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.VkCommandPoolCreateInfo = type { i32, ptr, i32, i32 }
%struct.NUS_queue_family = type { ptr, ptr, i32, i32, i32, i32 }
%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 }

@vkCreateCommandPool = external dso_local global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [51 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_queue_family_build_submission_queues(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.VkCommandPoolCreateInfo, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  %9 = getelementptr inbounds %struct.VkCommandPoolCreateInfo, ptr %7, i32 0, i32 0
  store i32 39, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.VkCommandPoolCreateInfo, ptr %7, i32 0, i32 1
  store ptr null, ptr %10, align 8, !tbaa !12
  %11 = getelementptr inbounds %struct.VkCommandPoolCreateInfo, ptr %7, i32 0, i32 2
  store i32 2, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds %struct.VkCommandPoolCreateInfo, ptr %7, i32 0, i32 3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.NUS_queue_family, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !14
  store i32 %15, ptr %12, align 4, !tbaa !16
  %16 = load ptr, ptr @vkCreateCommandPool, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.NUS_queue_family, ptr %18, i32 0, i32 1
  %20 = call i32 %16(ptr noundef %17, ptr noundef %7, ptr noundef null, ptr noundef %19)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %2
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %56

24:                                               ; preds = %2
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.NUS_queue_family, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = zext i32 %27 to i64
  %29 = mul i64 368, %28
  %30 = call noalias ptr @malloc(i64 noundef %29) #5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.NUS_queue_family, ptr %31, i32 0, i32 0
  store ptr %30, ptr %32, align 8, !tbaa !18
  store i32 0, ptr %6, align 4, !tbaa !19
  br label %33

33:                                               ; preds = %52, %24
  %34 = load i32, ptr %6, align 4, !tbaa !19
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.NUS_queue_family, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !17
  %38 = icmp ult i32 %34, %37
  br i1 %38, label %39, label %55

39:                                               ; preds = %33
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.NUS_queue_family, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = load i32, ptr %6, align 4, !tbaa !19
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.NUS_queue_family, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = load i32, ptr %6, align 4, !tbaa !19
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds %struct.NUS_submission_queue, ptr %47, i64 %49
  %51 = call i32 @nus_submission_queue_build(ptr noundef %40, i32 noundef %43, i32 noundef %44, ptr noundef %50)
  br label %52

52:                                               ; preds = %39
  %53 = load i32, ptr %6, align 4, !tbaa !19
  %54 = add i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !19
  br label %33, !llvm.loop !20

55:                                               ; preds = %33
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %56

56:                                               ; preds = %55, %22
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %57 = load i32, ptr %3, align 4
  ret i32 %57
}

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

declare i32 @nus_submission_queue_build(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { 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, !11, i64 0}
!10 = !{!"VkCommandPoolCreateInfo", !11, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!15, !11, i64 20}
!15 = !{!"NUS_queue_family", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!16 = !{!10, !11, i64 20}
!17 = !{!15, !11, i64 16}
!18 = !{!15, !6, i64 0}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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.VkCommandPoolCreateInfo = type { i32, ptr, i32, i32 }
%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 }

@vkCreateCommandPool = external dso_local local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [51 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_queue_family_build_submission_queues(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.VkCommandPoolCreateInfo, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  store i32 39, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr null, ptr %4, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 2, ptr %5, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %3, i64 20
  %7 = getelementptr inbounds i8, ptr %1, i64 20
  %8 = load i32, ptr %7, align 4, !tbaa !13
  store i32 %8, ptr %6, align 4, !tbaa !15
  %9 = load ptr, ptr @vkCreateCommandPool, align 8, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = call i32 %9(ptr noundef %0, ptr noundef nonnull %3, ptr noundef null, ptr noundef nonnull %10) #5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %14, label %12

12:                                               ; preds = %2
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %.loopexit

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !17
  %17 = zext i32 %16 to i64
  %18 = mul nuw nsw i64 %17, 368
  %19 = call noalias ptr @malloc(i64 noundef %18) #6
  store ptr %19, ptr %1, align 8, !tbaa !18
  %.not15 = icmp eq i32 %16, 0
  br i1 %.not15, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %14, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %14 ]
  %20 = load i32, ptr %7, align 4, !tbaa !13
  %21 = load ptr, ptr %1, align 8, !tbaa !18
  %22 = getelementptr inbounds %struct.NUS_submission_queue, ptr %21, i64 %indvars.iv
  %23 = trunc nuw i64 %indvars.iv to i32
  %24 = call i32 @nus_submission_queue_build(ptr noundef %0, i32 noundef %20, i32 noundef %23, ptr noundef %22) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr %15, align 8, !tbaa !17
  %26 = zext i32 %25 to i64
  %27 = icmp ult i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %.loopexit, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph, %14, %12
  %.013 = phi i32 [ 0, %12 ], [ 1, %14 ], [ 1, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret i32 %.013
}

; 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_submission_queue_build(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !7, i64 0}
!6 = !{!"VkCommandPoolCreateInfo", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!14, !7, i64 20}
!14 = !{!"NUS_queue_family", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!15 = !{!6, !7, i64 20}
!16 = !{!10, !10, i64 0}
!17 = !{!14, !7, i64 16}
!18 = !{!14, !10, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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