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

; 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._NVME_DEVICE_PRIVATE_DATA = type { i32, ptr, ptr, ptr, ptr, ptr, i32, i64, %struct.EFI_BLOCK_IO_MEDIA, %struct._EFI_BLOCK_IO_PROTOCOL, %struct._EFI_DISK_INFO_PROTOCOL, i64, [80 x i16], %struct.NVME_ADMIN_NAMESPACE_DATA, ptr }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }
%struct._EFI_BLOCK_IO_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_DISK_INFO_PROTOCOL = type { %struct.GUID, ptr, ptr, ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.NVME_ADMIN_NAMESPACE_DATA = type { i64, i64, i64, i8, i8, i8, i8, i8, i8, i8, i8, [88 x i8], i64, [16 x %struct.NVME_LBAFORMAT], [192 x i8], [3712 x i8] }
%struct.NVME_LBAFORMAT = type { i16, i8, i8 }

@.str = external hidden unnamed_addr constant [157 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @NvmExpressDiskInfoIdentify(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %9 = call zeroext i8 @DebugAssertEnabled()
  %10 = zext i8 %9 to i32
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %22

12:                                               ; preds = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = ptrtoint ptr %13 to i64
  %15 = sub i64 %14, ptrtoint (ptr getelementptr inbounds (%struct._NVME_DEVICE_PRIVATE_DATA, ptr null, i32 0, i32 10) to i64)
  %16 = inttoptr i64 %15 to ptr
  %17 = getelementptr inbounds %struct._NVME_DEVICE_PRIVATE_DATA, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = icmp ne i32 %18, 1146311512
  br i1 %19, label %20, label %22

20:                                               ; preds = %12
  call void @DebugAssert(ptr noundef @.str, i64 noundef 100, ptr noundef @.str.1)
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  br label %27

22:                                               ; preds = %12, %3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = ptrtoint ptr %23 to i64
  %25 = sub i64 %24, ptrtoint (ptr getelementptr inbounds (%struct._NVME_DEVICE_PRIVATE_DATA, ptr null, i32 0, i32 10) to i64)
  %26 = inttoptr i64 %25 to ptr
  br label %27

27:                                               ; preds = %22, %20
  %28 = phi ptr [ %21, %20 ], [ %26, %22 ]
  store ptr %28, ptr %8, align 8, !tbaa !5
  store i64 -9223372036854775803, ptr %7, align 8, !tbaa !19
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !20
  %31 = zext i32 %30 to i64
  %32 = icmp uge i64 %31, 4096
  br i1 %32, label %33, label %38

33:                                               ; preds = %27
  store i64 0, ptr %7, align 8, !tbaa !19
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._NVME_DEVICE_PRIVATE_DATA, ptr %35, i32 0, i32 13
  %37 = call ptr @CopyMem(ptr noundef %34, ptr noundef %36, i64 noundef 4096)
  br label %38

38:                                               ; preds = %33, %27
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 4096, ptr %39, align 4, !tbaa !20
  %40 = load i64, ptr %7, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %40
}

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

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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"_NVME_DEVICE_PRIVATE_DATA", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !12, i64 56, !13, i64 64, !14, i64 112, !15, i64 160, !12, i64 208, !7, i64 216, !18, i64 376, !6, i64 4472}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !11, i64 12, !11, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !11, i64 44}
!14 = !{!"_EFI_BLOCK_IO_PROTOCOL", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!"_EFI_DISK_INFO_PROTOCOL", !16, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!"", !11, i64 0, !17, i64 4, !17, i64 6, !7, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !7, i64 32, !12, i64 120, !7, i64 128, !7, i64 192, !7, i64 384}
!19 = !{!12, !12, i64 0}
!20 = !{!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"

@.str = external hidden unnamed_addr constant [157 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775803, 1) i64 @NvmExpressDiskInfoIdentify(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre8 = add i64 %.pre, -160
  %.pre10 = inttoptr i64 %.pre8 to ptr
  br i1 %.not, label %._crit_edge, label %5

5:                                                ; preds = %3
  %6 = load i32, ptr %.pre10, align 8, !tbaa !5
  %.not7 = icmp eq i32 %6, 1146311512
  br i1 %.not7, label %._crit_edge, label %7

7:                                                ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 100, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %3, %5, %7
  %8 = phi ptr [ %0, %7 ], [ %.pre10, %5 ], [ %.pre10, %3 ]
  %9 = load i32, ptr %2, align 4, !tbaa !18
  %10 = icmp ugt i32 %9, 4095
  br i1 %10, label %11, label %14

11:                                               ; preds = %._crit_edge
  %12 = getelementptr inbounds i8, ptr %8, i64 376
  %13 = tail call ptr @CopyMem(ptr noundef %1, ptr noundef nonnull %12, i64 noundef 4096) #2
  br label %14

14:                                               ; preds = %11, %._crit_edge
  %.0 = phi i64 [ 0, %11 ], [ -9223372036854775803, %._crit_edge ]
  store i32 4096, ptr %2, align 4, !tbaa !18
  ret i64 %.0
}

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 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 = { "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, !7, i64 0}
!6 = !{!"_NVME_DEVICE_PRIVATE_DATA", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !11, i64 56, !12, i64 64, !13, i64 112, !14, i64 160, !11, i64 208, !8, i64 216, !17, i64 376, !10, i64 4472}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"", !7, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !7, i64 12, !7, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !7, i64 44}
!13 = !{!"_EFI_BLOCK_IO_PROTOCOL", !11, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!14 = !{!"_EFI_DISK_INFO_PROTOCOL", !15, i64 0, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!15 = !{!"", !7, i64 0, !16, i64 4, !16, i64 6, !8, i64 8}
!16 = !{!"short", !8, i64 0}
!17 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !8, i64 24, !8, i64 25, !8, i64 26, !8, i64 27, !8, i64 28, !8, i64 29, !8, i64 30, !8, i64 31, !8, i64 32, !11, i64 120, !8, i64 128, !8, i64 192, !8, i64 384}
!18 = !{!7, !7, i64 0}


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