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

; 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 @ScsiDiskInfoWhichIde(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 ptr, align 8
  %9 = 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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._EFI_DISK_INFO_PROTOCOL, ptr %10, i32 0, i32 0
  %12 = call zeroext i8 @CompareGuid(ptr noundef %11, ptr noundef @gEfiDiskInfoScsiInterfaceGuid)
  %13 = zext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %21, label %15

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

21:                                               ; preds = %15, %3
  store i64 -9223372036854775805, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %51

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

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

34:                                               ; preds = %26
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 3180, ptr noundef @.str.6)
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  br label %41

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

41:                                               ; preds = %36, %34
  %42 = phi ptr [ %35, %34 ], [ %40, %36 ]
  store ptr %42, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %43, i32 0, i32 13
  %45 = load i32, ptr %44, align 8, !tbaa !20
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %45, ptr %46, align 4, !tbaa !21
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %47, i32 0, i32 14
  %49 = load i32, ptr %48, align 4, !tbaa !22
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %49, ptr %50, align 4, !tbaa !21
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %51

51:                                               ; preds = %41, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %52 = load i64, ptr %4, align 8
  ret i64 %52
}

; 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 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 = !{!10, !11, i64 296}
!21 = !{!11, !11, i64 0}
!22 = !{!10, !11, i64 300}


; 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 -9223372036854775805, 1) i64 @ScsiDiskInfoWhichIde(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %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 %17

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

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

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

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

._crit_edge:                                      ; preds = %7, %9, %11
  %12 = phi ptr [ %0, %11 ], [ %.pre14, %9 ], [ %.pre14, %7 ]
  %13 = getelementptr inbounds i8, ptr %12, i64 296
  %14 = load i32, ptr %13, align 8, !tbaa !19
  store i32 %14, ptr %1, align 4, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %12, i64 300
  %16 = load i32, ptr %15, align 4, !tbaa !21
  store i32 %16, ptr %2, align 4, !tbaa !20
  br label %17

17:                                               ; preds = %3, %5, %._crit_edge
  %.0 = phi i64 [ 0, %._crit_edge ], [ -9223372036854775805, %5 ], [ -9223372036854775805, %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 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 = !{!6, !7, i64 296}
!20 = !{!7, !7, i64 0}
!21 = !{!6, !7, i64 300}


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