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

; 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._UFS_PASS_THRU_PRIVATE_DATA = type { i32, ptr, %struct.EFI_EXT_SCSI_PASS_THRU_MODE, %struct._EFI_EXT_SCSI_PASS_THRU_PROTOCOL, ptr, i64, i32, i8, ptr, i8, ptr, ptr, i8, ptr, %struct.UFS_EXPOSED_LUNS }
%struct.EFI_EXT_SCSI_PASS_THRU_MODE = type { i32, i32, i32 }
%struct._EFI_EXT_SCSI_PASS_THRU_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.UFS_EXPOSED_LUNS = type { [12 x i8], i16 }

@.str.39 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @UfsWaitMemSet(i64 noundef, i32 noundef, i32 noundef, i64 noundef) #0

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

declare i32 @MmioRead32(i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @DumpUicCmdExecResult(i8 noundef zeroext, i8 noundef zeroext) #0

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

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

declare i32 @MmioWrite32(i64 noundef, i32 noundef) #2

declare i64 @MultU64x32(i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @UfsExecUicCommands(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i8, align 1
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i8 %1, ptr %8, align 1, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !10
  store i32 %3, ptr %10, align 4, !tbaa !10
  store i32 %4, ptr %11, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._UFS_PASS_THRU_PRIVATE_DATA, ptr %18, i32 0, i32 5
  %20 = load i64, ptr %19, align 8, !tbaa !12
  store i64 %20, ptr %15, align 8, !tbaa !19
  %21 = load i64, ptr %15, align 8, !tbaa !19
  %22 = add i64 %21, 32
  store i64 %22, ptr %13, align 8, !tbaa !19
  %23 = load i64, ptr %13, align 8, !tbaa !19
  %24 = call i32 @MmioRead32(i64 noundef %23)
  store i32 %24, ptr %14, align 4, !tbaa !10
  %25 = load i32, ptr %14, align 4, !tbaa !10
  %26 = and i32 %25, 1024
  %27 = icmp eq i32 %26, 1024
  br i1 %27, label %28, label %32

28:                                               ; preds = %5
  %29 = load i64, ptr %13, align 8, !tbaa !19
  %30 = load i32, ptr %14, align 4, !tbaa !10
  %31 = call i32 @MmioWrite32(i64 noundef %29, i32 noundef %30)
  br label %32

32:                                               ; preds = %28, %5
  %33 = load i64, ptr %15, align 8, !tbaa !19
  %34 = add i64 %33, 148
  store i64 %34, ptr %13, align 8, !tbaa !19
  %35 = load i64, ptr %13, align 8, !tbaa !19
  %36 = load i32, ptr %9, align 4, !tbaa !10
  %37 = call i32 @MmioWrite32(i64 noundef %35, i32 noundef %36)
  %38 = load i64, ptr %15, align 8, !tbaa !19
  %39 = add i64 %38, 152
  store i64 %39, ptr %13, align 8, !tbaa !19
  %40 = load i64, ptr %13, align 8, !tbaa !19
  %41 = load i32, ptr %10, align 4, !tbaa !10
  %42 = call i32 @MmioWrite32(i64 noundef %40, i32 noundef %41)
  %43 = load i64, ptr %15, align 8, !tbaa !19
  %44 = add i64 %43, 156
  store i64 %44, ptr %13, align 8, !tbaa !19
  %45 = load i64, ptr %13, align 8, !tbaa !19
  %46 = load i32, ptr %11, align 4, !tbaa !10
  %47 = call i32 @MmioWrite32(i64 noundef %45, i32 noundef %46)
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._UFS_PASS_THRU_PRIVATE_DATA, ptr %48, i32 0, i32 5
  %50 = load i64, ptr %49, align 8, !tbaa !12
  %51 = add i64 %50, 48
  store i64 %51, ptr %13, align 8, !tbaa !19
  %52 = load i64, ptr %13, align 8, !tbaa !19
  %53 = call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000)
  %54 = call i64 @UfsWaitMemSet(i64 noundef %52, i32 noundef 8, i32 noundef 8, i64 noundef %53)
  store i64 %54, ptr %12, align 8, !tbaa !19
  %55 = load i64, ptr %12, align 8, !tbaa !19
  %56 = icmp slt i64 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %32
  %58 = load i64, ptr %12, align 8, !tbaa !19
  store i64 %58, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %137

59:                                               ; preds = %32
  %60 = load i64, ptr %15, align 8, !tbaa !19
  %61 = add i64 %60, 144
  store i64 %61, ptr %13, align 8, !tbaa !19
  %62 = load i64, ptr %13, align 8, !tbaa !19
  %63 = load i8, ptr %8, align 1, !tbaa !9
  %64 = zext i8 %63 to i32
  %65 = call i32 @MmioWrite32(i64 noundef %62, i32 noundef %64)
  %66 = load i64, ptr %15, align 8, !tbaa !19
  %67 = add i64 %66, 32
  store i64 %67, ptr %13, align 8, !tbaa !19
  %68 = load i64, ptr %13, align 8, !tbaa !19
  %69 = call i32 @MmioRead32(i64 noundef %68)
  store i32 %69, ptr %14, align 4, !tbaa !10
  %70 = load i64, ptr %13, align 8, !tbaa !19
  %71 = call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000)
  %72 = call i64 @UfsWaitMemSet(i64 noundef %70, i32 noundef 1024, i32 noundef 1024, i64 noundef %71)
  store i64 %72, ptr %12, align 8, !tbaa !19
  %73 = load i64, ptr %12, align 8, !tbaa !19
  %74 = icmp slt i64 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %59
  %76 = load i64, ptr %12, align 8, !tbaa !19
  store i64 %76, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %137

77:                                               ; preds = %59
  %78 = load i8, ptr %8, align 1, !tbaa !9
  %79 = zext i8 %78 to i32
  %80 = icmp ne i32 %79, 20
  br i1 %80, label %81, label %104

81:                                               ; preds = %77
  %82 = load i64, ptr %15, align 8, !tbaa !19
  %83 = add i64 %82, 152
  store i64 %83, ptr %13, align 8, !tbaa !19
  %84 = load i64, ptr %13, align 8, !tbaa !19
  %85 = call i32 @MmioRead32(i64 noundef %84)
  store i32 %85, ptr %14, align 4, !tbaa !10
  %86 = load i32, ptr %14, align 4, !tbaa !10
  %87 = and i32 %86, 255
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %103

89:                                               ; preds = %81
  br label %90

90:                                               ; preds = %89
  %91 = call zeroext i8 @DebugCodeEnabled()
  %92 = icmp ne i8 %91, 0
  br i1 %92, label %93, label %100

93:                                               ; preds = %90
  call void @llvm.lifetime.start.p0(i64 1, ptr %17) #3
  %94 = load i8, ptr %8, align 1, !tbaa !9
  %95 = load i32, ptr %14, align 4, !tbaa !10
  %96 = and i32 %95, 255
  %97 = trunc i32 %96 to i8
  call void @DumpUicCmdExecResult(i8 noundef zeroext %94, i8 noundef zeroext %97)
  store i8 0, ptr %17, align 1, !tbaa !9
  %98 = load i8, ptr %17, align 1, !tbaa !9
  %99 = add i8 %98, 1
  store i8 %99, ptr %17, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %17) #3
  br label %100

100:                                              ; preds = %93, %90
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101
  store i64 -9223372036854775801, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %137

103:                                              ; preds = %81
  br label %104

104:                                              ; preds = %103, %77
  %105 = load i64, ptr %15, align 8, !tbaa !19
  %106 = add i64 %105, 48
  store i64 %106, ptr %13, align 8, !tbaa !19
  %107 = load i64, ptr %13, align 8, !tbaa !19
  %108 = call i32 @MmioRead32(i64 noundef %107)
  store i32 %108, ptr %14, align 4, !tbaa !10
  %109 = load i32, ptr %14, align 4, !tbaa !10
  %110 = and i32 %109, 1
  %111 = icmp eq i32 %110, 0
  br i1 %111, label %112, label %122

112:                                              ; preds = %104
  %113 = load i64, ptr %15, align 8, !tbaa !19
  %114 = add i64 %113, 32
  store i64 %114, ptr %13, align 8, !tbaa !19
  %115 = load i64, ptr %13, align 8, !tbaa !19
  %116 = call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000)
  %117 = call i64 @UfsWaitMemSet(i64 noundef %115, i32 noundef 256, i32 noundef 256, i64 noundef %116)
  store i64 %117, ptr %12, align 8, !tbaa !19
  %118 = load i64, ptr %12, align 8, !tbaa !19
  %119 = icmp slt i64 %118, 0
  br i1 %119, label %120, label %121

120:                                              ; preds = %112
  store i64 -9223372036854775801, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %137

121:                                              ; preds = %112
  store i64 -9223372036854775794, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %137

122:                                              ; preds = %104
  br label %123

123:                                              ; preds = %122
  %124 = call zeroext i8 @DebugPrintEnabled()
  %125 = icmp ne i8 %124, 0
  br i1 %125, label %126, label %134

126:                                              ; preds = %123
  br label %127

127:                                              ; preds = %126
  %128 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %129 = icmp ne i8 %128, 0
  br i1 %129, label %130, label %131

130:                                              ; preds = %127
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.39)
  br label %131

131:                                              ; preds = %130, %127
  br label %132

132:                                              ; preds = %131
  br label %133

133:                                              ; preds = %132
  br label %134

134:                                              ; preds = %133, %123
  br label %135

135:                                              ; preds = %134
  br label %136

136:                                              ; preds = %135
  store i64 0, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %137

137:                                              ; preds = %136, %121, %120, %102, %75, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %138 = load i64, ptr %6, align 8
  ret i64 %138
}

declare zeroext i8 @DebugCodeEnabled() #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !16, i64 104}
!13 = !{!"_UFS_PASS_THRU_PRIVATE_DATA", !11, i64 0, !6, i64 8, !14, i64 16, !15, i64 32, !6, i64 96, !16, i64 104, !11, i64 112, !7, i64 116, !6, i64 120, !7, i64 128, !6, i64 136, !6, i64 144, !7, i64 152, !6, i64 160, !17, i64 168}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!15 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"", !7, i64 0, !18, i64 12, !18, i64 13}
!18 = !{!"short", !7, i64 0}
!19 = !{!16, !16, 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.39 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @UfsWaitMemSet(i64 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

declare i32 @MmioRead32(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @DumpUicCmdExecResult(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

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

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

declare i32 @MmioWrite32(i64 noundef, i32 noundef) local_unnamed_addr #1

declare i64 @MultU64x32(i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @UfsExecUicCommands(ptr nocapture noundef readonly %0, i8 noundef zeroext %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add i64 %7, 32
  %9 = tail call i32 @MmioRead32(i64 noundef %8) #2
  %10 = and i32 %9, 1024
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %13, label %11

11:                                               ; preds = %5
  %12 = tail call i32 @MmioWrite32(i64 noundef %8, i32 noundef %9) #2
  br label %13

13:                                               ; preds = %11, %5
  %14 = add i64 %7, 148
  %15 = tail call i32 @MmioWrite32(i64 noundef %14, i32 noundef %2) #2
  %16 = add i64 %7, 152
  %17 = tail call i32 @MmioWrite32(i64 noundef %16, i32 noundef %3) #2
  %18 = add i64 %7, 156
  %19 = tail call i32 @MmioWrite32(i64 noundef %18, i32 noundef %4) #2
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = add i64 %20, 48
  %22 = tail call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000) #2
  %23 = tail call i64 @UfsWaitMemSet(i64 noundef %21, i32 noundef 8, i32 noundef 8, i64 noundef %22)
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %55, label %25

25:                                               ; preds = %13
  %26 = add i64 %7, 144
  %27 = zext i8 %1 to i32
  %28 = tail call i32 @MmioWrite32(i64 noundef %26, i32 noundef %27) #2
  %29 = tail call i32 @MmioRead32(i64 noundef %8) #2
  %30 = tail call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000) #2
  %31 = tail call i64 @UfsWaitMemSet(i64 noundef %8, i32 noundef 1024, i32 noundef 1024, i64 noundef %30)
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %55, label %33

33:                                               ; preds = %25
  %.not43 = icmp eq i8 %1, 20
  br i1 %.not43, label %41, label %34

34:                                               ; preds = %33
  %35 = tail call i32 @MmioRead32(i64 noundef %16) #2
  %36 = and i32 %35, 255
  %.not44 = icmp eq i32 %36, 0
  br i1 %.not44, label %41, label %37

37:                                               ; preds = %34
  %38 = tail call zeroext i8 @DebugCodeEnabled() #2
  %.not47 = icmp eq i8 %38, 0
  br i1 %.not47, label %55, label %39

39:                                               ; preds = %37
  %40 = trunc i32 %35 to i8
  tail call void @DumpUicCmdExecResult(i8 noundef zeroext %1, i8 noundef zeroext %40)
  br label %55

41:                                               ; preds = %34, %33
  %42 = add i64 %7, 48
  %43 = tail call i32 @MmioRead32(i64 noundef %42) #2
  %44 = and i32 %43, 1
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %41
  %47 = tail call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000) #2
  %48 = tail call i64 @UfsWaitMemSet(i64 noundef %8, i32 noundef 256, i32 noundef 256, i64 noundef %47)
  %49 = icmp slt i64 %48, 0
  %. = select i1 %49, i64 -9223372036854775801, i64 -9223372036854775794
  br label %55

50:                                               ; preds = %41
  %51 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not45 = icmp eq i8 %51, 0
  br i1 %.not45, label %55, label %52

52:                                               ; preds = %50
  %53 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #2
  %.not46 = icmp eq i8 %53, 0
  br i1 %.not46, label %55, label %54

54:                                               ; preds = %52
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.39) #2
  br label %55

55:                                               ; preds = %50, %54, %52, %46, %37, %39, %25, %13
  %.0 = phi i64 [ %23, %13 ], [ %31, %25 ], [ -9223372036854775801, %39 ], [ -9223372036854775801, %37 ], [ %., %46 ], [ 0, %52 ], [ 0, %54 ], [ 0, %50 ]
  ret i64 %.0
}

declare zeroext i8 @DebugCodeEnabled() 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, !13, i64 104}
!6 = !{!"_UFS_PASS_THRU_PRIVATE_DATA", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 32, !10, i64 96, !13, i64 104, !7, i64 112, !8, i64 116, !10, i64 120, !8, i64 128, !10, i64 136, !10, i64 144, !8, i64 152, !10, i64 160, !14, i64 168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!12 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"", !8, i64 0, !15, i64 12, !15, i64 13}
!15 = !{!"short", !8, i64 0}


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