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

; 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.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%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._EFI_DISK_INFO_PROTOCOL = type { %struct.GUID, ptr, ptr, ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 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 }
%struct._EFI_SCSI_IO_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, i32 }

@.str.1 = external hidden unnamed_addr constant [146 x i8], align 1
@gBS = external global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1

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

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) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @ScsiDiskReset(ptr noundef %0, i8 noundef zeroext %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, 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 = load ptr, ptr @gBS, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  %11 = call i64 %10(i64 noundef 8)
  store i64 %11, ptr %5, align 8, !tbaa !15
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = zext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = sub i64 %17, ptrtoint (ptr getelementptr inbounds (%struct.SCSI_DISK_DEV, ptr null, i32 0, i32 2) to i64)
  %19 = inttoptr i64 %18 to ptr
  %20 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = icmp ne i32 %21, 1801741171
  br i1 %22, label %23, label %25

23:                                               ; preds = %15
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 446, ptr noundef @.str.6)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  br label %30

25:                                               ; preds = %15, %2
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = sub i64 %27, ptrtoint (ptr getelementptr inbounds (%struct.SCSI_DISK_DEV, ptr null, i32 0, i32 2) to i64)
  %29 = inttoptr i64 %28 to ptr
  br label %30

30:                                               ; preds = %25, %23
  %31 = phi ptr [ %24, %23 ], [ %29, %25 ]
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !25
  %35 = getelementptr inbounds %struct._EFI_SCSI_IO_PROTOCOL, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !26
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !25
  %40 = call i64 %36(ptr noundef %39)
  store i64 %40, ptr %7, align 8, !tbaa !15
  %41 = load i64, ptr %7, align 8, !tbaa !15
  %42 = icmp slt i64 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %30
  store i64 -9223372036854775801, ptr %7, align 8, !tbaa !15
  br label %62

44:                                               ; preds = %30
  %45 = load i8, ptr %4, align 1, !tbaa !9
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  br label %62

48:                                               ; preds = %44
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %49, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !25
  %52 = getelementptr inbounds %struct._EFI_SCSI_IO_PROTOCOL, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !28
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SCSI_DISK_DEV, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !25
  %57 = call i64 %53(ptr noundef %56)
  store i64 %57, ptr %7, align 8, !tbaa !15
  %58 = load i64, ptr %7, align 8, !tbaa !15
  %59 = icmp slt i64 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %48
  store i64 -9223372036854775801, ptr %7, align 8, !tbaa !15
  br label %62

61:                                               ; preds = %48
  br label %62

62:                                               ; preds = %61, %60, %47, %43
  %63 = load ptr, ptr @gBS, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !29
  %66 = load i64, ptr %5, align 8, !tbaa !15
  call void %65(i64 noundef %66)
  %67 = load i64, ptr %7, align 8, !tbaa !15
  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 8, ptr %5) #3
  ret i64 %67
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 24}
!11 = !{!"", !12, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!12 = !{!"", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !14, i64 0}
!17 = !{!"", !14, i64 0, !6, i64 8, !18, i64 16, !19, i64 64, !6, i64 112, !7, i64 120, !7, i64 121, !20, i64 122, !6, i64 128, !13, i64 136, !21, i64 144, !6, i64 240, !22, i64 248, !14, i64 296, !14, i64 300, !24, i64 304, !7, i64 816}
!18 = !{!"_EFI_BLOCK_IO_PROTOCOL", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!19 = !{!"", !14, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !14, i64 12, !14, i64 16, !13, i64 24, !13, i64 32, !14, i64 40, !14, i64 44}
!20 = !{!"short", !7, i64 0}
!21 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5}
!22 = !{!"_EFI_DISK_INFO_PROTOCOL", !23, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!23 = !{!"", !14, i64 0, !20, i64 4, !20, i64 6, !7, i64 8}
!24 = !{!"", !20, i64 0, !20, i64 2, !20, i64 4, !7, i64 6, !7, i64 20, !7, i64 40, !7, i64 46, !7, i64 54, !7, i64 94, !20, i64 98, !20, i64 100, !20, i64 102, !20, i64 104, !20, i64 106, !7, i64 108, !20, i64 124, !20, i64 126, !20, i64 128, !20, i64 130, !20, i64 132, !20, i64 134, !20, i64 136, !7, i64 138, !7, i64 142, !7, i64 146, !20, i64 150, !20, i64 152, !20, i64 154, !20, i64 156, !20, i64 158, !20, i64 160, !20, i64 162, !20, i64 164, !20, i64 166, !20, i64 168, !20, i64 170, !20, i64 172, !20, i64 174, !20, i64 176, !20, i64 178, !20, i64 180, !20, i64 182, !20, i64 184, !20, i64 186, !20, i64 188, !7, i64 190, !7, i64 216, !7, i64 224, !7, i64 232, !20, i64 238, !20, i64 240, !7, i64 242, !20, i64 250, !7, i64 252, !20, i64 256, !7, i64 258, !7, i64 320, !7, i64 352, !20, i64 444, !20, i64 446, !7, i64 448, !20, i64 510}
!25 = !{!17, !6, i64 112}
!26 = !{!27, !6, i64 24}
!27 = !{!"_EFI_SCSI_IO_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40}
!28 = !{!27, !6, i64 16}
!29 = !{!11, !6, i64 32}


; 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.1 = external hidden unnamed_addr constant [146 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ScsiDiskReset(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @gBS, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = tail call i64 %5(i64 noundef 8) #2
  %7 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %7, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre14 = add i64 %.pre, -16
  %.pre16 = inttoptr i64 %.pre14 to ptr
  br i1 %.not, label %._crit_edge, label %8

8:                                                ; preds = %2
  %9 = load i32, ptr %.pre16, align 8, !tbaa !14
  %.not12 = icmp eq i32 %9, 1801741171
  br i1 %.not12, label %._crit_edge, label %10

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

._crit_edge:                                      ; preds = %2, %8, %10
  %11 = phi ptr [ %0, %10 ], [ %.pre16, %8 ], [ %.pre16, %2 ]
  %12 = getelementptr inbounds i8, ptr %11, i64 112
  %13 = load ptr, ptr %12, align 8, !tbaa !23
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !24
  %16 = tail call i64 %15(ptr noundef %13) #2
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %25, label %18

18:                                               ; preds = %._crit_edge
  %.not13 = icmp eq i8 %1, 0
  br i1 %.not13, label %25, label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %12, align 8, !tbaa !23
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !26
  %23 = tail call i64 %22(ptr noundef %20) #2
  %24 = icmp slt i64 %23, 0
  %spec.store.select = select i1 %24, i64 -9223372036854775801, i64 %23
  br label %25

25:                                               ; preds = %._crit_edge, %19, %18
  %.0 = phi i64 [ %spec.store.select, %19 ], [ %16, %18 ], [ -9223372036854775801, %._crit_edge ]
  %26 = load ptr, ptr @gBS, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 32
  %28 = load ptr, ptr %27, align 8, !tbaa !27
  tail call void %28(i64 noundef %6) #2
  ret i64 %.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 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"", !13, i64 0, !6, i64 8, !16, i64 16, !17, i64 64, !6, i64 112, !7, i64 120, !7, i64 121, !18, i64 122, !6, i64 128, !12, i64 136, !19, i64 144, !6, i64 240, !20, i64 248, !13, i64 296, !13, i64 300, !22, i64 304, !7, i64 816}
!16 = !{!"_EFI_BLOCK_IO_PROTOCOL", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!"", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !13, i64 12, !13, i64 16, !12, i64 24, !12, i64 32, !13, i64 40, !13, i64 44}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5}
!20 = !{!"_EFI_DISK_INFO_PROTOCOL", !21, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!21 = !{!"", !13, i64 0, !18, i64 4, !18, i64 6, !7, i64 8}
!22 = !{!"", !18, i64 0, !18, i64 2, !18, i64 4, !7, i64 6, !7, i64 20, !7, i64 40, !7, i64 46, !7, i64 54, !7, i64 94, !18, i64 98, !18, i64 100, !18, i64 102, !18, i64 104, !18, i64 106, !7, i64 108, !18, i64 124, !18, i64 126, !18, i64 128, !18, i64 130, !18, i64 132, !18, i64 134, !18, i64 136, !7, i64 138, !7, i64 142, !7, i64 146, !18, i64 150, !18, i64 152, !18, i64 154, !18, i64 156, !18, i64 158, !18, i64 160, !18, i64 162, !18, i64 164, !18, i64 166, !18, i64 168, !18, i64 170, !18, i64 172, !18, i64 174, !18, i64 176, !18, i64 178, !18, i64 180, !18, i64 182, !18, i64 184, !18, i64 186, !18, i64 188, !7, i64 190, !7, i64 216, !7, i64 224, !7, i64 232, !18, i64 238, !18, i64 240, !7, i64 242, !18, i64 250, !7, i64 252, !18, i64 256, !7, i64 258, !7, i64 320, !7, i64 352, !18, i64 444, !18, i64 446, !7, i64 448, !18, i64 510}
!23 = !{!15, !6, i64 112}
!24 = !{!25, !6, i64 24}
!25 = !{!"_EFI_SCSI_IO_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40}
!26 = !{!25, !6, i64 16}
!27 = !{!10, !6, i64 32}


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