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

; 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_DEVICE_REQUEST = type { i8, i8, i16, i16, i16 }
%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.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.USB_ENDPOINT_DESCRIPTOR = type <{ i8, i8, i8, i8, i16, i8 }>

@gBS = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBotResetDevice(ptr noundef %0, i8 noundef zeroext %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca %struct.USB_DEVICE_REQUEST, align 1
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load i8, ptr %5, align 1, !tbaa !9
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %29

15:                                               ; preds = %2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !10
  %19 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %18, i32 0, i32 12
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !10
  %24 = call i64 %20(ptr noundef %23)
  store i64 %24, ptr %8, align 8, !tbaa !16
  %25 = load i64, ptr %8, align 8, !tbaa !16
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %15
  store i64 -9223372036854775801, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %77

28:                                               ; preds = %15
  br label %29

29:                                               ; preds = %28, %2
  %30 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 0
  store i8 33, ptr %30, align 1, !tbaa !18
  %31 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 1
  store i8 -1, ptr %31, align 1, !tbaa !21
  %32 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 2
  store i16 0, ptr %32, align 1, !tbaa !22
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.USB_INTERFACE_DESCRIPTOR, ptr %34, i32 0, i32 2
  %36 = load i8, ptr %35, align 2, !tbaa !23
  %37 = zext i8 %36 to i16
  %38 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 3
  store i16 %37, ptr %38, align 1, !tbaa !24
  %39 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 4
  store i16 0, ptr %39, align 1, !tbaa !25
  store i32 3000, ptr %10, align 4, !tbaa !26
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !10
  %43 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !27
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !10
  %48 = load i32, ptr %10, align 4, !tbaa !26
  %49 = call i64 %44(ptr noundef %47, ptr noundef %7, i32 noundef 2, i32 noundef %48, ptr noundef null, i64 noundef 0, ptr noundef %9)
  store i64 %49, ptr %8, align 8, !tbaa !16
  %50 = load i64, ptr %8, align 8, !tbaa !16
  %51 = icmp slt i64 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %29
  store i64 -9223372036854775801, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %77

53:                                               ; preds = %29
  %54 = load ptr, ptr @gBS, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %54, i32 0, i32 29
  %56 = load ptr, ptr %55, align 8, !tbaa !28
  %57 = call i64 %56(i64 noundef 100000)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %58, i32 0, i32 4
  %60 = load ptr, ptr %59, align 8, !tbaa !10
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !31
  %64 = getelementptr inbounds %struct.USB_ENDPOINT_DESCRIPTOR, ptr %63, i32 0, i32 2
  %65 = load i8, ptr %64, align 1, !tbaa !32
  %66 = call i64 @UsbClearEndpointStall(ptr noundef %60, i8 noundef zeroext %65)
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !10
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !34
  %73 = getelementptr inbounds %struct.USB_ENDPOINT_DESCRIPTOR, ptr %72, i32 0, i32 2
  %74 = load i8, ptr %73, align 1, !tbaa !32
  %75 = call i64 @UsbClearEndpointStall(ptr noundef %69, i8 noundef zeroext %74)
  %76 = load i64, ptr %8, align 8, !tbaa !16
  store i64 %76, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %77

77:                                               ; preds = %53, %52, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %78 = load i64, ptr %3, align 8
  ret i64 %78
}

; 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

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


; 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_DEVICE_REQUEST = type { i8, i8, i16, i16, i16 }

@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, -9223372036854775800) i64 @UsbBotResetDevice(ptr nocapture noundef readonly %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = alloca %struct.USB_DEVICE_REQUEST, align 1
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %.not = icmp eq i8 %1, 0
  br i1 %.not, label %12, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 96
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = tail call i64 %9(ptr noundef %7) #3
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %42, label %12

12:                                               ; preds = %5, %2
  store i8 33, ptr %3, align 1, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 -1, ptr %13, align 1, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %3, i64 2
  store i16 0, ptr %14, align 1, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %0, i64 2
  %16 = load i8, ptr %15, align 2, !tbaa !19
  %17 = zext i8 %16 to i16
  %18 = getelementptr inbounds i8, ptr %3, i64 4
  store i16 %17, ptr %18, align 1, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %3, i64 6
  store i16 0, ptr %19, align 1, !tbaa !21
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = call i64 %22(ptr noundef nonnull %21, ptr noundef nonnull %3, i32 noundef 2, i32 noundef 3000, ptr noundef null, i64 noundef 0, ptr noundef nonnull %4) #3
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %42, label %25

25:                                               ; preds = %12
  %26 = load ptr, ptr @gBS, align 8, !tbaa !23
  %27 = getelementptr inbounds i8, ptr %26, i64 248
  %28 = load ptr, ptr %27, align 8, !tbaa !24
  %29 = call i64 %28(i64 noundef 100000) #3
  %30 = load ptr, ptr %20, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !28
  %33 = getelementptr inbounds i8, ptr %32, i64 2
  %34 = load i8, ptr %33, align 1, !tbaa !29
  %35 = call i64 @UsbClearEndpointStall(ptr noundef %30, i8 noundef zeroext %34) #3
  %36 = load ptr, ptr %20, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  %38 = load ptr, ptr %37, align 8, !tbaa !31
  %39 = getelementptr inbounds i8, ptr %38, i64 2
  %40 = load i8, ptr %39, align 1, !tbaa !29
  %41 = call i64 @UsbClearEndpointStall(ptr noundef %36, i8 noundef zeroext %40) #3
  br label %42

42:                                               ; preds = %12, %5, %25
  %.0 = phi i64 [ %23, %25 ], [ -9223372036854775801, %5 ], [ -9223372036854775801, %12 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i64 %.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

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, !10, i64 40}
!6 = !{!"", !7, i64 0, !10, i64 16, !10, i64 24, !11, i64 32, !10, i64 40}
!7 = !{!"", !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}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !10, i64 96}
!13 = !{!"_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}
!14 = !{!15, !8, i64 0}
!15 = !{!"", !8, i64 0, !8, i64 1, !16, i64 2, !16, i64 4, !16, i64 6}
!16 = !{!"short", !8, i64 0}
!17 = !{!15, !8, i64 1}
!18 = !{!15, !16, i64 2}
!19 = !{!6, !8, i64 2}
!20 = !{!15, !16, i64 4}
!21 = !{!15, !16, i64 6}
!22 = !{!13, !10, i64 0}
!23 = !{!10, !10, i64 0}
!24 = !{!25, !10, i64 248}
!25 = !{!"", !26, 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}
!26 = !{!"", !27, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!27 = !{!"long long", !8, i64 0}
!28 = !{!6, !10, i64 16}
!29 = !{!30, !8, i64 2}
!30 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !16, i64 4, !8, i64 6}
!31 = !{!6, !10, i64 24}


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