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

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct._EFI_DISK_INFO_PROTOCOL = type { %struct.GUID, ptr, ptr, ptr, ptr }
%struct.SCSI_DISK_DEV = type { i32, ptr, %struct._EFI_BLOCK_IO_PROTOCOL, %struct.EFI_BLOCK_IO_MEDIA, ptr, i8, i8, i16, ptr, i64, %struct.EFI_SCSI_INQUIRY_DATA, ptr, %struct._EFI_DISK_INFO_PROTOCOL, i32, i32, %struct.ATAPI_IDENTIFY_DATA, i8 }
%struct._EFI_BLOCK_IO_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }
%struct.EFI_SCSI_INQUIRY_DATA = type { i16, i8, i8, i8, [91 x i8] }
%struct.ATAPI_IDENTIFY_DATA = type { i16, i16, i16, [7 x i16], [20 x i8], [3 x i16], [8 x i8], [40 x i8], [2 x i16], i16, i16, i16, i16, i16, [8 x i16], i16, i16, i16, i16, i16, i16, i16, [2 x i16], [2 x i16], [2 x i16], i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, [13 x i16], [4 x i16], [4 x i16], [3 x i16], i16, i16, [4 x i16], i16, [2 x i16], i16, [31 x i16], [16 x i16], [46 x i16], i16, i16, [31 x i16], i16 }

@.str.1 = external hidden unnamed_addr constant [146 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1
@gEfiDiskInfoScsiInterfaceGuid = external global %struct.GUID, align 4
@gEfiDiskInfoUfsInterfaceGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @ScsiDiskInfoIdentify(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._EFI_DISK_INFO_PROTOCOL, ptr %11, i32 0, i32 0
  %13 = call zeroext i8 @CompareGuid(ptr noundef %12, ptr noundef @gEfiDiskInfoScsiInterfaceGuid)
  %14 = zext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %22, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._EFI_DISK_INFO_PROTOCOL, ptr %17, i32 0, i32 0
  %19 = call zeroext i8 @CompareGuid(ptr noundef %18, ptr noundef @gEfiDiskInfoUfsInterfaceGuid)
  %20 = zext i8 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %16, %3
  store i64 -9223372036854775794, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %56

23:                                               ; preds = %16
  %24 = call zeroext i8 @DebugAssertEnabled()
  %25 = zext i8 %24 to i32
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %37

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, ptrtoint (ptr getelementptr inbounds (%struct.SCSI_DISK_DEV, ptr null, i32 0, i32 12) to i64)
  %31 = inttoptr i64 %30 to ptr
  %32 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = icmp ne i32 %33, 1801741171
  br i1 %34, label %35, label %37

35:                                               ; preds = %27
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 3111, ptr noundef @.str.6)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  br label %42

37:                                               ; preds = %27, %23
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = ptrtoint ptr %38 to i64
  %40 = sub i64 %39, ptrtoint (ptr getelementptr inbounds (%struct.SCSI_DISK_DEV, ptr null, i32 0, i32 12) to i64)
  %41 = inttoptr i64 %40 to ptr
  br label %42

42:                                               ; preds = %37, %35
  %43 = phi ptr [ %36, %35 ], [ %41, %37 ]
  store ptr %43, ptr %9, align 8, !tbaa !5
  store i64 -9223372036854775803, ptr %8, align 8, !tbaa !20
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !21
  %46 = zext i32 %45 to i64
  %47 = icmp uge i64 %46, 512
  br i1 %47, label %48, label %53

48:                                               ; preds = %42
  store i64 0, ptr %8, align 8, !tbaa !20
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %50, i32 0, i32 15
  %52 = call ptr @CopyMem(ptr noundef %49, ptr noundef %51, i64 noundef 512)
  br label %53

53:                                               ; preds = %48, %42
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 512, ptr %54, align 4, !tbaa !21
  %55 = load i64, ptr %8, align 8, !tbaa !20
  store i64 %55, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %56

56:                                               ; preds = %53, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %57 = load i64, ptr %4, align 8
  ret i64 %57
}

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

declare zeroext i8 @DebugAssertEnabled() #2

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

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

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

declare zeroext i8 @CompareGuid(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !6, i64 8, !12, i64 16, !14, i64 64, !6, i64 112, !7, i64 120, !7, i64 121, !15, i64 122, !6, i64 128, !13, i64 136, !16, i64 144, !6, i64 240, !17, i64 248, !11, i64 296, !11, i64 300, !19, i64 304, !7, i64 816}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_BLOCK_IO_PROTOCOL", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !11, i64 12, !11, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !11, i64 44}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5}
!17 = !{!"_EFI_DISK_INFO_PROTOCOL", !18, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!"", !11, i64 0, !15, i64 4, !15, i64 6, !7, i64 8}
!19 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !7, i64 6, !7, i64 20, !7, i64 40, !7, i64 46, !7, i64 54, !7, i64 94, !15, i64 98, !15, i64 100, !15, i64 102, !15, i64 104, !15, i64 106, !7, i64 108, !15, i64 124, !15, i64 126, !15, i64 128, !15, i64 130, !15, i64 132, !15, i64 134, !15, i64 136, !7, i64 138, !7, i64 142, !7, i64 146, !15, i64 150, !15, i64 152, !15, i64 154, !15, i64 156, !15, i64 158, !15, i64 160, !15, i64 162, !15, i64 164, !15, i64 166, !15, i64 168, !15, i64 170, !15, i64 172, !15, i64 174, !15, i64 176, !15, i64 178, !15, i64 180, !15, i64 182, !15, i64 184, !15, i64 186, !15, i64 188, !7, i64 190, !7, i64 216, !7, i64 224, !7, i64 232, !15, i64 238, !15, i64 240, !7, i64 242, !15, i64 250, !7, i64 252, !15, i64 256, !7, i64 258, !7, i64 320, !7, i64 352, !15, i64 444, !15, i64 446, !7, i64 448, !15, i64 510}
!20 = !{!13, !13, i64 0}
!21 = !{!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.GUID = type { i32, i16, i16, [8 x i8] }

@.str.1 = external hidden unnamed_addr constant [146 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1
@gEfiDiskInfoScsiInterfaceGuid = external global %struct.GUID, align 4
@gEfiDiskInfoUfsInterfaceGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775803, 1) i64 @ScsiDiskInfoIdentify(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @CompareGuid(ptr noundef %0, ptr noundef nonnull @gEfiDiskInfoScsiInterfaceGuid) #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %19

5:                                                ; preds = %3
  %6 = tail call zeroext i8 @CompareGuid(ptr noundef %0, ptr noundef nonnull @gEfiDiskInfoUfsInterfaceGuid) #2
  %.not11 = icmp eq i8 %6, 0
  br i1 %.not11, label %7, label %19

7:                                                ; preds = %5
  %8 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not12 = icmp eq i8 %8, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre14 = add i64 %.pre, -248
  %.pre16 = inttoptr i64 %.pre14 to ptr
  br i1 %.not12, label %._crit_edge, label %9

9:                                                ; preds = %7
  %10 = load i32, ptr %.pre16, align 8, !tbaa !5
  %.not13 = icmp eq i32 %10, 1801741171
  br i1 %.not13, label %._crit_edge, label %11

11:                                               ; preds = %9
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 3111, ptr noundef nonnull @.str.6) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %7, %9, %11
  %12 = phi ptr [ %0, %11 ], [ %.pre16, %9 ], [ %.pre16, %7 ]
  %13 = load i32, ptr %2, align 4, !tbaa !19
  %14 = icmp ugt i32 %13, 511
  br i1 %14, label %15, label %18

15:                                               ; preds = %._crit_edge
  %16 = getelementptr inbounds i8, ptr %12, i64 304
  %17 = tail call ptr @CopyMem(ptr noundef %1, ptr noundef nonnull %16, i64 noundef 512) #2
  br label %18

18:                                               ; preds = %15, %._crit_edge
  %.010 = phi i64 [ 0, %15 ], [ -9223372036854775803, %._crit_edge ]
  store i32 512, ptr %2, align 4, !tbaa !19
  br label %19

19:                                               ; preds = %3, %5, %18
  %.0 = phi i64 [ %.010, %18 ], [ -9223372036854775794, %5 ], [ -9223372036854775794, %3 ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

declare zeroext i8 @CompareGuid(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 = { "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 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16, !13, i64 64, !10, i64 112, !8, i64 120, !8, i64 121, !14, i64 122, !10, i64 128, !12, i64 136, !15, i64 144, !10, i64 240, !16, i64 248, !7, i64 296, !7, i64 300, !18, i64 304, !8, i64 816}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_BLOCK_IO_PROTOCOL", !12, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"", !7, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !7, i64 12, !7, i64 16, !12, i64 24, !12, i64 32, !7, i64 40, !7, i64 44}
!14 = !{!"short", !8, i64 0}
!15 = !{!"", !8, i64 0, !8, i64 0, !8, i64 1, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5}
!16 = !{!"_EFI_DISK_INFO_PROTOCOL", !17, i64 0, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!17 = !{!"", !7, i64 0, !14, i64 4, !14, i64 6, !8, i64 8}
!18 = !{!"", !14, i64 0, !14, i64 2, !14, i64 4, !8, i64 6, !8, i64 20, !8, i64 40, !8, i64 46, !8, i64 54, !8, i64 94, !14, i64 98, !14, i64 100, !14, i64 102, !14, i64 104, !14, i64 106, !8, i64 108, !14, i64 124, !14, i64 126, !14, i64 128, !14, i64 130, !14, i64 132, !14, i64 134, !14, i64 136, !8, i64 138, !8, i64 142, !8, i64 146, !14, i64 150, !14, i64 152, !14, i64 154, !14, i64 156, !14, i64 158, !14, i64 160, !14, i64 162, !14, i64 164, !14, i64 166, !14, i64 168, !14, i64 170, !14, i64 172, !14, i64 174, !14, i64 176, !14, i64 178, !14, i64 180, !14, i64 182, !14, i64 184, !14, i64 186, !14, i64 188, !8, i64 190, !8, i64 216, !8, i64 224, !8, i64 232, !14, i64 238, !14, i64 240, !8, i64 242, !14, i64 250, !8, i64 252, !14, i64 256, !8, i64 258, !8, i64 320, !8, i64 352, !14, i64 444, !14, i64 446, !8, i64 448, !14, i64 510}
!19 = !{!7, !7, i64 0}


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