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

; 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_CC = type { i16, i8, i8 }
%struct.NVME_CSTS = type { i32 }
%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 }
%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 }

@gBS = external global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [46 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

; 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
declare dso_local i64 @WriteNvmeControllerConfiguration(ptr noundef, ptr noundef) #1

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @ReadNvmeControllerStatus(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @NvmeEnableController(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.NVME_CC, align 1
  %5 = alloca %struct.NVME_CSTS, align 1
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %10 = call ptr @ZeroMem(ptr noundef %4, i64 noundef 4)
  %11 = load i16, ptr %4, align 1
  %12 = and i16 %11, -2
  %13 = or i16 %12, 1
  store i16 %13, ptr %4, align 1
  %14 = getelementptr inbounds %struct.NVME_CC, ptr %4, i32 0, i32 1
  %15 = load i8, ptr %14, align 1
  %16 = and i8 %15, -16
  %17 = or i8 %16, 6
  store i8 %17, ptr %14, align 1
  %18 = getelementptr inbounds %struct.NVME_CC, ptr %4, i32 0, i32 1
  %19 = load i8, ptr %18, align 1
  %20 = and i8 %19, 15
  %21 = or i8 %20, 64
  store i8 %21, ptr %18, align 1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i64 @WriteNvmeControllerConfiguration(ptr noundef %22, ptr noundef %4)
  store i64 %23, ptr %6, align 8, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %1
  %27 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %27, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %89

28:                                               ; preds = %1
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._NVME_CONTROLLER_PRIVATE_DATA, ptr %29, i32 0, i32 20
  %31 = getelementptr inbounds %struct.NVME_CAP, ptr %30, i32 0, i32 2
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  store i8 1, ptr %8, align 1, !tbaa !18
  br label %41

36:                                               ; preds = %28
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._NVME_CONTROLLER_PRIVATE_DATA, ptr %37, i32 0, i32 20
  %39 = getelementptr inbounds %struct.NVME_CAP, ptr %38, i32 0, i32 2
  %40 = load i8, ptr %39, align 1, !tbaa !11
  store i8 %40, ptr %8, align 1, !tbaa !18
  br label %41

41:                                               ; preds = %36, %35
  %42 = load i8, ptr %8, align 1, !tbaa !18
  %43 = zext i8 %42 to i32
  %44 = mul nsw i32 %43, 500
  store i32 %44, ptr %7, align 4, !tbaa !19
  br label %45

45:                                               ; preds = %65, %41
  %46 = load i32, ptr %7, align 4, !tbaa !19
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %68

48:                                               ; preds = %45
  %49 = load ptr, ptr @gBS, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %49, i32 0, i32 29
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = call i64 %51(i64 noundef 1000)
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call i64 @ReadNvmeControllerStatus(ptr noundef %53, ptr noundef %5)
  store i64 %54, ptr %6, align 8, !tbaa !9
  %55 = load i64, ptr %6, align 8, !tbaa !9
  %56 = icmp slt i64 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %48
  %58 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %58, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %89

59:                                               ; preds = %48
  %60 = load i32, ptr %5, align 1
  %61 = and i32 %60, 1
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %59
  br label %68

64:                                               ; preds = %59
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %7, align 4, !tbaa !19
  %67 = add i32 %66, -1
  store i32 %67, ptr %7, align 4, !tbaa !19
  br label %45, !llvm.loop !23

68:                                               ; preds = %63, %45
  %69 = load i32, ptr %7, align 4, !tbaa !19
  %70 = icmp eq i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  store i64 -9223372036854775790, ptr %6, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %71, %68
  br label %73

73:                                               ; preds = %72
  %74 = call zeroext i8 @DebugPrintEnabled()
  %75 = icmp ne i8 %74, 0
  br i1 %75, label %76, label %85

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  %78 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %79 = icmp ne i8 %78, 0
  br i1 %79, label %80, label %82

80:                                               ; preds = %77
  %81 = load i64, ptr %6, align 8, !tbaa !9
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.12, i64 noundef %81)
  br label %82

82:                                               ; preds = %80, %77
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84, %73
  br label %86

86:                                               ; preds = %85
  br label %87

87:                                               ; preds = %86
  %88 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %88, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %89

89:                                               ; preds = %87, %57, %26
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %90 = load i64, ptr %2, align 8
  ret i64 %90
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 241}
!12 = !{!"_NVME_CONTROLLER_PRIVATE_DATA", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !14, i64 56, !15, 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, !16, i64 238, !6, i64 248}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !10, i64 16, !13, i64 24}
!15 = !{!"_NVM_EXPRESS_PASS_THRU_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!16 = !{!"", !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}
!17 = !{!"short", !7, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!13, !13, i64 0}
!20 = !{!21, !6, i64 248}
!21 = !{!"", !22, 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}
!22 = !{!"", !10, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; 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.NVME_CC = type { i16, i8, i8 }
%struct.NVME_CSTS = type { i32 }

@gBS = external local_unnamed_addr global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [46 x i8], align 1

; 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @WriteNvmeControllerConfiguration(ptr noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @ReadNvmeControllerStatus(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @NvmeEnableController(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.NVME_CC, align 2
  %3 = alloca %struct.NVME_CSTS, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %4 = call ptr @ZeroMem(ptr noundef nonnull %2, i64 noundef 4) #3
  %5 = load i16, ptr %2, align 2
  %6 = or i16 %5, 1
  store i16 %6, ptr %2, align 2
  %7 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 70, ptr %7, align 2
  %8 = call i64 @WriteNvmeControllerConfiguration(ptr noundef %0, ptr noundef nonnull %2)
  %9 = icmp slt i64 %8, 0
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 241
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = icmp eq i8 %12, 0
  %14 = zext i8 %12 to i32
  %15 = mul nuw nsw i32 %14, 500
  %spec.select24 = select i1 %13, i32 500, i32 %15
  %.not25 = icmp eq i32 %spec.select24, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph

select.unfold:                                    ; preds = %23
  %16 = add nsw i32 %.01426, -1
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

.lr.ph:                                           ; preds = %10, %select.unfold
  %.01426 = phi i32 [ %16, %select.unfold ], [ %spec.select24, %10 ]
  %17 = load ptr, ptr @gBS, align 8, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %17, i64 248
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  %20 = call i64 %19(i64 noundef 1000) #3
  %21 = call i64 @ReadNvmeControllerStatus(ptr noundef %0, ptr noundef nonnull %3)
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %.loopexit, label %23

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr %3, align 4
  %25 = and i32 %24, 1
  %.not21 = icmp eq i32 %25, 0
  br i1 %.not21, label %select.unfold, label %._crit_edge

._crit_edge:                                      ; preds = %select.unfold, %23, %10
  %spec.select = phi i64 [ -9223372036854775790, %10 ], [ %21, %23 ], [ -9223372036854775790, %select.unfold ]
  %26 = call zeroext i8 @DebugPrintEnabled() #3
  %.not22 = icmp eq i8 %26, 0
  br i1 %.not22, label %.loopexit, label %27

27:                                               ; preds = %._crit_edge
  %28 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not23 = icmp eq i8 %28, 0
  br i1 %.not23, label %.loopexit, label %29

29:                                               ; preds = %27
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.12, i64 noundef %spec.select) #3
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %29, %27, %1
  %.016 = phi i64 [ %8, %1 ], [ %spec.select, %27 ], [ %spec.select, %29 ], [ %spec.select, %._crit_edge ], [ %21, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  ret i64 %.016
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !8, i64 241}
!6 = !{!"_NVME_CONTROLLER_PRIVATE_DATA", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !10, i64 48, !12, i64 56, !13, 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, !14, i64 238, !10, i64 248}
!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, !7, i64 4, !7, i64 8, !7, i64 12, !11, i64 16, !7, i64 24}
!13 = !{!"_NVM_EXPRESS_PASS_THRU_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!14 = !{!"", !15, i64 0, !8, i64 2, !8, i64 2, !8, i64 2, !8, i64 3, !15, i64 4, !15, i64 4, !15, i64 4, !15, i64 5, !8, i64 6, !8, i64 6, !8, i64 7}
!15 = !{!"short", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !10, i64 0}
!19 = !{!20, !10, i64 248}
!20 = !{!"", !21, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!21 = !{!"", !11, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass