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

; 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_CBW = type <{ i32, i32, i32, i8, i8, i8, [16 x i8] }>
%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 = external hidden unnamed_addr constant [153 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [31 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

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

declare ptr @CopyMem(ptr noundef, ptr noundef, 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
define dso_local i64 @UsbBotSendCommand(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3, i32 noundef %4, i8 noundef zeroext %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca %struct.USB_BOT_CBW, align 1
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i8 %2, ptr %9, align 1, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !10
  store i32 %4, ptr %11, align 4, !tbaa !10
  store i8 %5, ptr %12, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 31, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  br label %18

18:                                               ; preds = %6
  %19 = call zeroext i8 @DebugAssertEnabled()
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %31

21:                                               ; preds = %18
  %22 = load i8, ptr %9, align 1, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %21
  %26 = load i8, ptr %9, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = icmp sle i32 %27, 16
  br i1 %28, label %30, label %29

29:                                               ; preds = %25, %21
  call void @DebugAssert(ptr noundef @.str, i64 noundef 168, ptr noundef @.str.2)
  br label %30

30:                                               ; preds = %29, %25
  br label %31

31:                                               ; preds = %30, %18
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  %34 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 0
  store i32 1128420181, ptr %34, align 1, !tbaa !12
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 8, !tbaa !14
  %38 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 1
  store i32 %37, ptr %38, align 1, !tbaa !17
  %39 = load i32, ptr %11, align 4, !tbaa !10
  %40 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 2
  store i32 %39, ptr %40, align 1, !tbaa !18
  %41 = load i32, ptr %10, align 4, !tbaa !10
  %42 = icmp eq i32 %41, 0
  %43 = zext i1 %42 to i64
  %44 = select i1 %42, i32 128, i32 0
  %45 = trunc i32 %44 to i8
  %46 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 3
  store i8 %45, ptr %46, align 1, !tbaa !19
  %47 = load i8, ptr %12, align 1, !tbaa !9
  %48 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 4
  store i8 %47, ptr %48, align 1, !tbaa !20
  %49 = load i8, ptr %9, align 1, !tbaa !9
  %50 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 5
  store i8 %49, ptr %50, align 1, !tbaa !21
  %51 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 6
  %52 = getelementptr inbounds [16 x i8], ptr %51, i64 0, i64 0
  %53 = call ptr @ZeroMem(ptr noundef %52, i64 noundef 16)
  %54 = getelementptr inbounds %struct.USB_BOT_CBW, ptr %13, i32 0, i32 6
  %55 = getelementptr inbounds [16 x i8], ptr %54, i64 0, i64 0
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load i8, ptr %9, align 1, !tbaa !9
  %58 = zext i8 %57 to i64
  %59 = call ptr @CopyMem(ptr noundef %55, ptr noundef %56, i64 noundef %58)
  store i32 0, ptr %15, align 4, !tbaa !10
  store i64 31, ptr %16, align 8, !tbaa !22
  store i64 3000, ptr %17, align 8, !tbaa !22
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !24
  %63 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !25
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !24
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !27
  %71 = getelementptr inbounds %struct.USB_ENDPOINT_DESCRIPTOR, ptr %70, i32 0, i32 2
  %72 = load i8, ptr %71, align 1, !tbaa !28
  %73 = load i64, ptr %17, align 8, !tbaa !22
  %74 = call i64 %64(ptr noundef %67, i8 noundef zeroext %72, ptr noundef %13, ptr noundef %16, i64 noundef %73, ptr noundef %15)
  store i64 %74, ptr %14, align 8, !tbaa !22
  %75 = load i64, ptr %14, align 8, !tbaa !22
  %76 = icmp slt i64 %75, 0
  br i1 %76, label %77, label %94

77:                                               ; preds = %33
  %78 = load i32, ptr %15, align 4, !tbaa !10
  %79 = and i32 %78, 2
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %87

81:                                               ; preds = %77
  %82 = load i32, ptr %10, align 4, !tbaa !10
  %83 = icmp eq i32 %82, 1
  br i1 %83, label %84, label %87

84:                                               ; preds = %81
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = call i64 @UsbBotResetDevice(ptr noundef %85, i8 noundef zeroext 0)
  br label %93

87:                                               ; preds = %81, %77
  %88 = load i32, ptr %15, align 4, !tbaa !10
  %89 = and i32 %88, 16
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %92

91:                                               ; preds = %87
  store i64 -9223372036854775802, ptr %14, align 8, !tbaa !22
  br label %92

92:                                               ; preds = %91, %87
  br label %93

93:                                               ; preds = %92, %84
  br label %94

94:                                               ; preds = %93, %33
  %95 = load i64, ptr %14, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 31, ptr %13) #3
  ret i64 %95
}

declare ptr @ZeroMem(ptr noundef, i64 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15}
!14 = !{!15, !11, i64 32}
!15 = !{!"", !16, i64 0, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40}
!16 = !{!"", !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}
!17 = !{!13, !11, i64 4}
!18 = !{!13, !11, i64 8}
!19 = !{!13, !7, i64 12}
!20 = !{!13, !7, i64 13}
!21 = !{!13, !7, i64 14}
!22 = !{!23, !23, i64 0}
!23 = !{!"long long", !7, i64 0}
!24 = !{!15, !6, i64 40}
!25 = !{!26, !6, i64 8}
!26 = !{!"_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}
!27 = !{!15, !6, i64 24}
!28 = !{!29, !7, i64 2}
!29 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !30, i64 4, !7, i64 6}
!30 = !{!"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"

%struct.USB_BOT_CBW = type <{ i32, i32, i32, i8, i8, i8, [16 x i8] }>

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [31 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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

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

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

; 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 @UsbBotSendCommand(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3, i32 noundef %4, i8 noundef zeroext %5) local_unnamed_addr #0 {
  %7 = alloca %struct.USB_BOT_CBW, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 31, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  %10 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %10, 0
  %11 = add i8 %2, -1
  %or.cond = icmp ult i8 %11, 16
  %or.cond22 = or i1 %or.cond, %.not
  br i1 %or.cond22, label %13, label %12

12:                                               ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 168, ptr noundef nonnull @.str.2) #3
  br label %13

13:                                               ; preds = %12, %6
  store i32 1128420181, ptr %7, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i32, ptr %14, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 %15, ptr %16, align 4, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 %4, ptr %17, align 4, !tbaa !15
  %18 = icmp eq i32 %3, 0
  %19 = select i1 %18, i8 -128, i8 0
  %20 = getelementptr inbounds i8, ptr %7, i64 12
  store i8 %19, ptr %20, align 4, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %7, i64 13
  store i8 %5, ptr %21, align 1, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %7, i64 14
  store i8 %2, ptr %22, align 2, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %7, i64 15
  %24 = call ptr @ZeroMem(ptr noundef nonnull %23, i64 noundef 16) #3
  %25 = zext i8 %2 to i64
  %26 = call ptr @CopyMem(ptr noundef nonnull %23, ptr noundef %1, i64 noundef %25) #3
  store i32 0, ptr %8, align 4, !tbaa !19
  store i64 31, ptr %9, align 8, !tbaa !20
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !23
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !25
  %33 = getelementptr inbounds i8, ptr %32, i64 2
  %34 = load i8, ptr %33, align 1, !tbaa !26
  %35 = call i64 %30(ptr noundef %28, i8 noundef zeroext %34, ptr noundef nonnull %7, ptr noundef nonnull %9, i64 noundef 3000, ptr noundef nonnull %8) #3
  %36 = icmp slt i64 %35, 0
  br i1 %36, label %37, label %46

37:                                               ; preds = %13
  %38 = load i32, ptr %8, align 4, !tbaa !19
  %39 = and i32 %38, 2
  %40 = icmp ne i32 %39, 0
  %41 = icmp eq i32 %3, 1
  %or.cond4 = and i1 %41, %40
  br i1 %or.cond4, label %42, label %44

42:                                               ; preds = %37
  %43 = call i64 @UsbBotResetDevice(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %46

44:                                               ; preds = %37
  %45 = and i32 %38, 16
  %.not21 = icmp eq i32 %45, 0
  %spec.select = select i1 %.not21, i64 %35, i64 -9223372036854775802
  br label %46

46:                                               ; preds = %44, %42, %13
  %.0 = phi i64 [ %35, %42 ], [ %35, %13 ], [ %spec.select, %44 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 31, ptr nonnull %7) #3
  ret i64 %.0
}

declare ptr @ZeroMem(ptr noundef, i64 noundef) 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 32}
!11 = !{!"", !12, i64 0, !13, i64 16, !13, i64 24, !7, i64 32, !13, i64 40}
!12 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !8, i64 12}
!17 = !{!6, !8, i64 13}
!18 = !{!6, !8, i64 14}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"long long", !8, i64 0}
!22 = !{!11, !13, i64 40}
!23 = !{!24, !13, i64 8}
!24 = !{!"_EFI_USB_IO_PROTOCOL", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96}
!25 = !{!11, !13, i64 24}
!26 = !{!27, !8, i64 2}
!27 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !28, i64 4, !8, i64 6}
!28 = !{!"short", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass