; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/Pci (NvmeCreateIoCompletionQueue)

; 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.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET = type { i64, ptr, i32, ptr, i32, i8, ptr, ptr, i8 }
%struct.NVM_EXPRESS_COMMAND = type { %struct.NVME_CDW0, i8, i32, i32, i32, i32, i32, i32, i32 }
%struct.NVME_CDW0 = type { i8, i8, i16 }
%struct.NVM_EXPRESS_RESPONSE = type { i32, i32, i32, i32 }
%struct.NVME_ADMIN_CRIOCQ = type { i64 }
%struct._NVME_CONTROLLER_PRIVATE_DATA = type { i32, ptr, ptr, ptr, ptr, i64, ptr, %struct.NVM_EXPRESS_PASS_THRU_MODE, %struct._NVM_EXPRESS_PASS_THRU_PROTOCOL, ptr, ptr, ptr, [2 x ptr], [2 x ptr], [2 x ptr], [2 x ptr], [2 x %struct.NVME_SQTDBL], [2 x %struct.NVME_CQHDBL], [2 x i8], [2 x i16], %struct.NVME_CAP, ptr }
%struct.NVM_EXPRESS_PASS_THRU_MODE = type { i32, i32, i32, i32, i64, i32 }
%struct._NVM_EXPRESS_PASS_THRU_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }
%struct.NVME_SQTDBL = type { i16, i16 }
%struct.NVME_CQHDBL = type { i16, i16 }
%struct.NVME_CAP = type { i16, i8, i8, i16, i8, i8 }

; 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

declare ptr @ZeroMem(ptr noundef, i64 noundef) #1

declare i64 @MultU64x32(i64 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @NvmeCreateIoCompletionQueue(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, align 8
  %4 = alloca %struct.NVM_EXPRESS_COMMAND, align 4
  %5 = alloca %struct.NVM_EXPRESS_RESPONSE, align 4
  %6 = alloca i64, align 8
  %7 = alloca %struct.NVME_ADMIN_CRIOCQ, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 36, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = call ptr @ZeroMem(ptr noundef %3, i64 noundef 64)
  %9 = call ptr @ZeroMem(ptr noundef %4, i64 noundef 36)
  %10 = call ptr @ZeroMem(ptr noundef %5, i64 noundef 16)
  %11 = call ptr @ZeroMem(ptr noundef %7, i64 noundef 8)
  %12 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 6
  store ptr %4, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 7
  store ptr %5, ptr %13, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.NVM_EXPRESS_COMMAND, ptr %4, i32 0, i32 0
  %15 = getelementptr inbounds %struct.NVME_CDW0, ptr %14, i32 0, i32 0
  store i8 5, ptr %15, align 4, !tbaa !14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._NVME_CONTROLLER_PRIVATE_DATA, ptr %16, i32 0, i32 19
  %18 = getelementptr inbounds [2 x i16], ptr %17, i64 0, i64 0
  %19 = load i16, ptr %18, align 2, !tbaa !18
  %20 = add i16 %19, 1
  store i16 %20, ptr %18, align 2, !tbaa !18
  %21 = getelementptr inbounds %struct.NVM_EXPRESS_COMMAND, ptr %4, i32 0, i32 0
  %22 = getelementptr inbounds %struct.NVME_CDW0, ptr %21, i32 0, i32 2
  store i16 %19, ptr %22, align 2, !tbaa !19
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._NVME_CONTROLLER_PRIVATE_DATA, ptr %23, i32 0, i32 15
  %25 = getelementptr inbounds [2 x ptr], ptr %24, i64 0, i64 1
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 1
  store ptr %26, ptr %27, align 8, !tbaa !20
  %28 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 2
  store i32 4096, ptr %28, align 8, !tbaa !21
  %29 = call i64 @MultU64x32(i64 noundef 5, i32 noundef 10000000)
  %30 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 0
  store i64 %29, ptr %30, align 8, !tbaa !22
  %31 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 5
  store i8 0, ptr %31, align 4, !tbaa !23
  %32 = load i64, ptr %7, align 1
  %33 = and i64 %32, -65536
  %34 = or i64 %33, 1
  store i64 %34, ptr %7, align 1
  %35 = load i64, ptr %7, align 1
  %36 = and i64 %35, -4294901761
  %37 = or i64 %36, 65536
  store i64 %37, ptr %7, align 1
  %38 = load i64, ptr %7, align 1
  %39 = and i64 %38, -4294967297
  %40 = or i64 %39, 4294967296
  store i64 %40, ptr %7, align 1
  %41 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 6
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.NVM_EXPRESS_COMMAND, ptr %42, i32 0, i32 3
  %44 = call ptr @CopyMem(ptr noundef %43, ptr noundef %7, i64 noundef 8)
  %45 = getelementptr inbounds %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, ptr %3, i32 0, i32 6
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.NVM_EXPRESS_COMMAND, ptr %46, i32 0, i32 1
  store i8 3, ptr %47, align 4, !tbaa !24
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._NVME_CONTROLLER_PRIVATE_DATA, ptr %48, i32 0, i32 8
  %50 = getelementptr inbounds %struct._NVM_EXPRESS_PASS_THRU_PROTOCOL, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !25
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._NVME_CONTROLLER_PRIVATE_DATA, ptr %52, i32 0, i32 8
  %54 = call i64 %51(ptr noundef %53, i32 noundef 0, i64 noundef 0, ptr noundef %3, ptr noundef null)
  store i64 %54, ptr %6, align 8, !tbaa !30
  %55 = load i64, ptr %6, align 8, !tbaa !30
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 36, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %3) #3
  ret i64 %55
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

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

!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 40}
!10 = !{!"", !11, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !12, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !7, i64 56}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 48}
!14 = !{!15, !7, i64 0}
!15 = !{!"", !16, i64 0, !7, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32}
!16 = !{!"", !7, i64 0, !7, i64 1, !17, i64 2}
!17 = !{!"short", !7, i64 0}
!18 = !{!17, !17, i64 0}
!19 = !{!15, !17, i64 2}
!20 = !{!10, !6, i64 8}
!21 = !{!10, !12, i64 16}
!22 = !{!10, !11, i64 0}
!23 = !{!10, !7, i64 36}
!24 = !{!15, !7, i64 4}
!25 = !{!26, !6, i64 96}
!26 = !{!"_NVME_CONTROLLER_PRIVATE_DATA", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !27, i64 56, !28, i64 88, !6, i64 128, !6, i64 136, !6, i64 144, !7, i64 152, !7, i64 168, !7, i64 184, !7, i64 200, !7, i64 216, !7, i64 224, !7, i64 232, !7, i64 234, !29, i64 238, !6, i64 248}
!27 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !11, i64 16, !12, i64 24}
!28 = !{!"_NVM_EXPRESS_PASS_THRU_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!29 = !{!"", !17, i64 0, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 3, !17, i64 4, !17, i64 4, !17, i64 4, !17, i64 5, !7, i64 6, !7, i64 6, !7, i64 7}
!30 = !{!11, !11, 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"

%struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET = type { i64, ptr, i32, ptr, i32, i8, ptr, ptr, i8 }
%struct.NVM_EXPRESS_COMMAND = type { %struct.NVME_CDW0, i8, i32, i32, i32, i32, i32, i32, i32 }
%struct.NVME_CDW0 = type { i8, i8, i16 }
%struct.NVM_EXPRESS_RESPONSE = type { i32, i32, i32, i32 }
%struct.NVME_ADMIN_CRIOCQ = type { i64 }

; 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

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #1

declare i64 @MultU64x32(i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @NvmeCreateIoCompletionQueue(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.NVM_EXPRESS_PASS_THRU_COMMAND_PACKET, align 8
  %3 = alloca %struct.NVM_EXPRESS_COMMAND, align 4
  %4 = alloca %struct.NVM_EXPRESS_RESPONSE, align 4
  %5 = alloca %struct.NVME_ADMIN_CRIOCQ, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = call ptr @ZeroMem(ptr noundef nonnull %2, i64 noundef 64) #3
  %7 = call ptr @ZeroMem(ptr noundef nonnull %3, i64 noundef 36) #3
  %8 = call ptr @ZeroMem(ptr noundef nonnull %4, i64 noundef 16) #3
  %9 = call ptr @ZeroMem(ptr noundef nonnull %5, i64 noundef 8) #3
  %10 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %3, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %2, i64 48
  store ptr %4, ptr %11, align 8, !tbaa !12
  store i8 5, ptr %3, align 4, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 234
  %13 = load i16, ptr %12, align 2, !tbaa !17
  %14 = add i16 %13, 1
  store i16 %14, ptr %12, align 2, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %3, i64 2
  store i16 %13, ptr %15, align 2, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %0, i64 208
  %17 = load ptr, ptr %16, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %17, ptr %18, align 8, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 4096, ptr %19, align 8, !tbaa !21
  %20 = call i64 @MultU64x32(i64 noundef 5, i32 noundef 10000000) #3
  store i64 %20, ptr %2, align 8, !tbaa !22
  %21 = getelementptr inbounds i8, ptr %2, i64 36
  store i8 0, ptr %21, align 4, !tbaa !23
  %22 = load i64, ptr %5, align 8
  %23 = and i64 %22, -8589934592
  %24 = or disjoint i64 %23, 4295032833
  store i64 %24, ptr %5, align 8
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 12
  %27 = call ptr @CopyMem(ptr noundef nonnull %26, ptr noundef nonnull %5, i64 noundef 8) #3
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 4
  store i8 3, ptr %29, align 4, !tbaa !24
  %30 = getelementptr inbounds i8, ptr %0, i64 88
  %31 = getelementptr inbounds i8, ptr %0, i64 96
  %32 = load ptr, ptr %31, align 8, !tbaa !25
  %33 = call i64 %32(ptr noundef nonnull %30, i32 noundef 0, i64 noundef 0, ptr noundef nonnull %2, ptr noundef null) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #3
  ret i64 %33
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

!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, !10, i64 40}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 24, !11, i64 32, !8, i64 36, !10, i64 40, !10, i64 48, !8, i64 56}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 48}
!13 = !{!14, !8, i64 0}
!14 = !{!"", !15, i64 0, !8, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32}
!15 = !{!"", !8, i64 0, !8, i64 1, !16, i64 2}
!16 = !{!"short", !8, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!14, !16, i64 2}
!19 = !{!10, !10, i64 0}
!20 = !{!6, !10, i64 8}
!21 = !{!6, !11, i64 16}
!22 = !{!6, !7, i64 0}
!23 = !{!6, !8, i64 36}
!24 = !{!14, !8, i64 4}
!25 = !{!26, !10, i64 96}
!26 = !{!"_NVME_CONTROLLER_PRIVATE_DATA", !11, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !10, i64 48, !27, i64 56, !28, i64 88, !10, i64 128, !10, i64 136, !10, i64 144, !8, i64 152, !8, i64 168, !8, i64 184, !8, i64 200, !8, i64 216, !8, i64 224, !8, i64 232, !8, i64 234, !29, i64 238, !10, i64 248}
!27 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !7, i64 16, !11, i64 24}
!28 = !{!"_NVM_EXPRESS_PASS_THRU_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!29 = !{!"", !16, i64 0, !8, i64 2, !8, i64 2, !8, i64 2, !8, i64 3, !16, i64 4, !16, i64 4, !16, i64 4, !16, i64 5, !8, i64 6, !8, i64 6, !8, i64 7}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass