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

; 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.USB_BOT_PROTOCOL = type { %struct.USB_INTERFACE_DESCRIPTOR, ptr, ptr, i32, ptr }
%struct.USB_INTERFACE_DESCRIPTOR = type { i8, i8, i8, i8, i8, i8, i8, i8, i8 }
%struct._EFI_USB_IO_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.USB_ENDPOINT_DESCRIPTOR = type <{ i8, i8, i8, i8, i16, i8 }>

@.str.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbBotResetDevice(ptr noundef, i8 noundef zeroext) #0

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

; 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
define dso_local i64 @UsbBotDataTransfer(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  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
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %22, label %18

18:                                               ; preds = %5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %5
  store i64 0, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %127

23:                                               ; preds = %18
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  store ptr %29, ptr %12, align 8, !tbaa !5
  br label %34

30:                                               ; preds = %23
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  store ptr %33, ptr %12, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %30, %26
  store i32 0, ptr %14, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = udiv i32 %35, 1000
  store i32 %36, ptr %11, align 4, !tbaa !9
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.USB_ENDPOINT_DESCRIPTOR, ptr %45, i32 0, i32 2
  %47 = load i8, ptr %46, align 1, !tbaa !20
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = call i64 %41(ptr noundef %44, i8 noundef zeroext %47, ptr noundef %48, ptr noundef %49, i64 noundef %51, ptr noundef %14)
  store i64 %52, ptr %13, align 8, !tbaa !11
  %53 = load i64, ptr %13, align 8, !tbaa !11
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %125

55:                                               ; preds = %34
  %56 = load i32, ptr %14, align 4, !tbaa !9
  %57 = and i32 %56, 2
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %96

59:                                               ; preds = %55
  br label %60

60:                                               ; preds = %59
  %61 = call zeroext i8 @DebugPrintEnabled()
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %63, label %72

63:                                               ; preds = %60
  br label %64

64:                                               ; preds = %63
  %65 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %64
  %68 = load i64, ptr %13, align 8, !tbaa !11
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.3, i64 noundef %68)
  br label %69

69:                                               ; preds = %67, %64
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  br label %72

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

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = call zeroext i8 @DebugPrintEnabled()
  %77 = icmp ne i8 %76, 0
  br i1 %77, label %78, label %86

78:                                               ; preds = %75
  br label %79

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

82:                                               ; preds = %79
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.4)
  br label %83

83:                                               ; preds = %82, %79
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  br label %86

86:                                               ; preds = %85, %75
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %89, i32 0, i32 4
  %91 = load ptr, ptr %90, align 8, !tbaa !17
  %92 = load ptr, ptr %12, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.USB_ENDPOINT_DESCRIPTOR, ptr %92, i32 0, i32 2
  %94 = load i8, ptr %93, align 1, !tbaa !20
  %95 = call i64 @UsbClearEndpointStall(ptr noundef %91, i8 noundef zeroext %94)
  br label %118

96:                                               ; preds = %55
  %97 = load i32, ptr %14, align 4, !tbaa !9
  %98 = and i32 %97, 16
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %100, label %101

100:                                              ; preds = %96
  store i64 -9223372036854775802, ptr %13, align 8, !tbaa !11
  br label %117

101:                                              ; preds = %96
  br label %102

102:                                              ; preds = %101
  %103 = call zeroext i8 @DebugPrintEnabled()
  %104 = icmp ne i8 %103, 0
  br i1 %104, label %105, label %114

105:                                              ; preds = %102
  br label %106

106:                                              ; preds = %105
  %107 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %108 = icmp ne i8 %107, 0
  br i1 %108, label %109, label %111

109:                                              ; preds = %106
  %110 = load i64, ptr %13, align 8, !tbaa !11
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3, i64 noundef %110)
  br label %111

111:                                              ; preds = %109, %106
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113, %102
  br label %115

115:                                              ; preds = %114
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116, %100
  br label %118

118:                                              ; preds = %117, %88
  %119 = load i64, ptr %13, align 8, !tbaa !11
  %120 = icmp eq i64 %119, -9223372036854775790
  br i1 %120, label %121, label %124

121:                                              ; preds = %118
  %122 = load ptr, ptr %7, align 8, !tbaa !5
  %123 = call i64 @UsbBotResetDevice(ptr noundef %122, i8 noundef zeroext 0)
  br label %124

124:                                              ; preds = %121, %118
  br label %125

125:                                              ; preds = %124, %34
  %126 = load i64, ptr %13, align 8, !tbaa !11
  store i64 %126, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %127

127:                                              ; preds = %125, %22
  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
  %128 = load i64, ptr %6, align 8
  ret i64 %128
}

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

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

declare i64 @UsbClearEndpointStall(ptr noundef, i8 noundef zeroext) #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"", !15, i64 0, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !6, i64 40}
!18 = !{!19, !6, i64 8}
!19 = !{!"_EFI_USB_IO_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, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!20 = !{!21, !7, i64 2}
!21 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !22, i64 4, !7, i64 6}
!22 = !{!"short", !7, 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.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbBotResetDevice(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBotDataTransfer(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %7 = icmp eq i32 %1, 2
  br i1 %7, label %.thread, label %8

8:                                                ; preds = %5
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %.thread, label %11

11:                                               ; preds = %8
  %12 = icmp eq i32 %1, 0
  %.020.in.v = select i1 %12, i64 16, i64 24
  %.020.in = getelementptr inbounds i8, ptr %0, i64 %.020.in.v
  %.020 = load ptr, ptr %.020.in, align 8, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !11
  %13 = udiv i32 %4, 1000
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %.020, i64 2
  %19 = load i8, ptr %18, align 1, !tbaa !18
  %20 = zext nneg i32 %13 to i64
  %21 = call i64 %17(ptr noundef %15, i8 noundef zeroext %19, ptr noundef %2, ptr noundef nonnull %3, i64 noundef %20, ptr noundef nonnull %6) #3
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %23, label %.thread

23:                                               ; preds = %11
  %24 = load i32, ptr %6, align 4, !tbaa !11
  %25 = and i32 %24, 2
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %40, label %26

26:                                               ; preds = %23
  %27 = call zeroext i8 @DebugPrintEnabled() #3
  %.not28 = icmp eq i8 %27, 0
  br i1 %.not28, label %31, label %28

28:                                               ; preds = %26
  %29 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not29 = icmp eq i8 %29, 0
  br i1 %.not29, label %31, label %30

30:                                               ; preds = %28
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.3, i64 noundef %21) #3
  br label %31

31:                                               ; preds = %26, %30, %28
  %32 = call zeroext i8 @DebugPrintEnabled() #3
  %.not30 = icmp eq i8 %32, 0
  br i1 %.not30, label %36, label %33

33:                                               ; preds = %31
  %34 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not31 = icmp eq i8 %34, 0
  br i1 %.not31, label %36, label %35

35:                                               ; preds = %33
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.4) #3
  br label %36

36:                                               ; preds = %33, %35, %31
  %37 = load ptr, ptr %14, align 8, !tbaa !13
  %38 = load i8, ptr %18, align 1, !tbaa !18
  %39 = call i64 @UsbClearEndpointStall(ptr noundef %37, i8 noundef zeroext %38) #3
  br label %47

40:                                               ; preds = %23
  %41 = and i32 %24, 16
  %.not25 = icmp eq i32 %41, 0
  br i1 %.not25, label %42, label %.thread

42:                                               ; preds = %40
  %43 = call zeroext i8 @DebugPrintEnabled() #3
  %.not26 = icmp eq i8 %43, 0
  br i1 %.not26, label %47, label %44

44:                                               ; preds = %42
  %45 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not27 = icmp eq i8 %45, 0
  br i1 %.not27, label %47, label %46

46:                                               ; preds = %44
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3, i64 noundef %21) #3
  br label %47

47:                                               ; preds = %44, %46, %42, %36
  %48 = icmp eq i64 %21, -9223372036854775790
  br i1 %48, label %49, label %.thread

49:                                               ; preds = %47
  %50 = call i64 @UsbBotResetDevice(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %.thread

.thread:                                          ; preds = %40, %11, %49, %47, %5, %8
  %.021 = phi i64 [ 0, %8 ], [ 0, %5 ], [ -9223372036854775790, %49 ], [ %21, %47 ], [ %21, %11 ], [ -9223372036854775802, %40 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  ret i64 %.021
}

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

declare i64 @UsbClearEndpointStall(ptr noundef, i8 noundef zeroext) local_unnamed_addr #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 = { mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 40}
!14 = !{!"", !15, i64 0, !10, i64 16, !10, i64 24, !12, i64 32, !10, i64 40}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8}
!16 = !{!17, !10, i64 8}
!17 = !{!"_EFI_USB_IO_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, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!18 = !{!19, !7, i64 2}
!19 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !20, i64 4, !7, i64 6}
!20 = !{!"short", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass