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

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

; 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

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

declare i64 @UsbClearEndpointStall(ptr noundef, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBotGetStatus(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %struct.USB_BOT_CSW, align 1
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 13, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 2, ptr %15, align 1, !tbaa !11
  store i64 -9223372036854775801, ptr %10, align 8, !tbaa !12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds %struct.USB_ENDPOINT_DESCRIPTOR, ptr %18, i32 0, i32 2
  %20 = load i8, ptr %19, align 1, !tbaa !17
  store i8 %20, ptr %9, align 1, !tbaa !11
  %21 = load ptr, ptr %4, 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 !20
  store ptr %23, ptr %12, align 8, !tbaa !5
  store i64 3000, ptr %14, align 8, !tbaa !12
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %68, %3
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = icmp ult i32 %25, 3
  br i1 %26, label %27, label %71

27:                                               ; preds = %24
  %28 = call ptr @ZeroMem(ptr noundef %7, i64 noundef 13)
  store i32 0, ptr %11, align 4, !tbaa !9
  store i64 13, ptr %8, align 8, !tbaa !12
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = load i8, ptr %9, align 1, !tbaa !11
  %34 = load i64, ptr %14, align 8, !tbaa !12
  %35 = call i64 %31(ptr noundef %32, i8 noundef zeroext %33, ptr noundef %7, ptr noundef %8, i64 noundef %34, ptr noundef %11)
  store i64 %35, ptr %10, align 8, !tbaa !12
  %36 = load i64, ptr %10, align 8, !tbaa !12
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %38, label %47

38:                                               ; preds = %27
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = and i32 %39, 2
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %38
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = load i8, ptr %9, align 1, !tbaa !11
  %45 = call i64 @UsbClearEndpointStall(ptr noundef %43, i8 noundef zeroext %44)
  br label %46

46:                                               ; preds = %42, %38
  br label %68

47:                                               ; preds = %27
  %48 = getelementptr inbounds %struct.USB_BOT_CSW, ptr %7, i32 0, i32 0
  %49 = load i32, ptr %48, align 1, !tbaa !23
  %50 = icmp ne i32 %49, 1396855637
  br i1 %50, label %51, label %54

51:                                               ; preds = %47
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call i64 @UsbBotResetDevice(ptr noundef %52, i8 noundef zeroext 0)
  store i64 %53, ptr %10, align 8, !tbaa !12
  br label %67

54:                                               ; preds = %47
  %55 = getelementptr inbounds %struct.USB_BOT_CSW, ptr %7, i32 0, i32 3
  %56 = load i8, ptr %55, align 1, !tbaa !25
  %57 = zext i8 %56 to i32
  %58 = icmp eq i32 %57, 2
  br i1 %58, label %59, label %62

59:                                               ; preds = %54
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = call i64 @UsbBotResetDevice(ptr noundef %60, i8 noundef zeroext 0)
  store i64 %61, ptr %10, align 8, !tbaa !12
  br label %66

62:                                               ; preds = %54
  %63 = getelementptr inbounds %struct.USB_BOT_CSW, ptr %7, i32 0, i32 3
  %64 = load i8, ptr %63, align 1, !tbaa !25
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 %64, ptr %65, align 1, !tbaa !11
  br label %71

66:                                               ; preds = %59
  br label %67

67:                                               ; preds = %66, %51
  br label %68

68:                                               ; preds = %67, %46
  %69 = load i32, ptr %13, align 4, !tbaa !9
  %70 = add i32 %69, 1
  store i32 %70, ptr %13, align 4, !tbaa !9
  br label %24, !llvm.loop !26

71:                                               ; preds = %62, %24
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.USB_BOT_PROTOCOL, ptr %72, i32 0, i32 3
  %74 = load i32, ptr %73, align 8, !tbaa !28
  %75 = add i32 %74, 1
  store i32 %75, ptr %73, align 8, !tbaa !28
  %76 = load i64, ptr %10, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 13, ptr %7) #3
  ret i64 %76
}

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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"", !16, i64 0, !6, i64 16, !6, i64 24, !10, 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 = !{!18, !7, i64 2}
!18 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !19, i64 4, !7, i64 6}
!19 = !{!"short", !7, i64 0}
!20 = !{!15, !6, i64 40}
!21 = !{!22, !6, i64 8}
!22 = !{!"_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}
!23 = !{!24, !10, i64 0}
!24 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12}
!25 = !{!24, !7, i64 12}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!15, !10, i64 32}


; 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_CSW = type <{ i32, i32, i32, i8 }>

; 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

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

declare i64 @UsbClearEndpointStall(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBotGetStatus(ptr noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca %struct.USB_BOT_CSW, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 13, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i8 2, ptr %2, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %8, i64 2
  %10 = load i8, ptr %9, align 1, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = getelementptr inbounds i8, ptr %4, i64 12
  %15 = call ptr @ZeroMem(ptr noundef nonnull %4, i64 noundef 13) #3
  store i32 0, ptr %6, align 4, !tbaa !17
  store i64 13, ptr %5, align 8, !tbaa !18
  %16 = load ptr, ptr %13, align 8, !tbaa !20
  %17 = call i64 %16(ptr noundef %12, i8 noundef zeroext %10, ptr noundef nonnull %4, ptr noundef nonnull %5, i64 noundef 3000, ptr noundef nonnull %6) #3
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %3
  %20 = load i32, ptr %6, align 4, !tbaa !17
  %21 = and i32 %20, 2
  %.not19 = icmp eq i32 %21, 0
  br i1 %.not19, label %34, label %22

22:                                               ; preds = %19
  %23 = call i64 @UsbClearEndpointStall(ptr noundef nonnull %12, i8 noundef zeroext %10) #3
  br label %34

24:                                               ; preds = %3
  %25 = load i32, ptr %4, align 4, !tbaa !22
  %.not = icmp eq i32 %25, 1396855637
  br i1 %.not, label %28, label %26

26:                                               ; preds = %24
  %27 = call i64 @UsbBotResetDevice(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %34

28:                                               ; preds = %24
  %29 = load i8, ptr %14, align 4, !tbaa !24
  %30 = icmp eq i8 %29, 2
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = call i64 @UsbBotResetDevice(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %34

33:                                               ; preds = %62, %43, %28
  %.lcssa23 = phi i64 [ %17, %28 ], [ %37, %43 ], [ %56, %62 ]
  %.lcssa = phi i8 [ %29, %28 ], [ %44, %43 ], [ %63, %62 ]
  store i8 %.lcssa, ptr %2, align 1, !tbaa !5
  br label %.loopexit

34:                                               ; preds = %26, %31, %19, %22
  %35 = call ptr @ZeroMem(ptr noundef nonnull %4, i64 noundef 13) #3
  store i32 0, ptr %6, align 4, !tbaa !17
  store i64 13, ptr %5, align 8, !tbaa !18
  %36 = load ptr, ptr %13, align 8, !tbaa !20
  %37 = call i64 %36(ptr noundef nonnull %12, i8 noundef zeroext %10, ptr noundef nonnull %4, ptr noundef nonnull %5, i64 noundef 3000, ptr noundef nonnull %6) #3
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %48, label %39

39:                                               ; preds = %34
  %40 = load i32, ptr %4, align 4, !tbaa !22
  %.not.1 = icmp eq i32 %40, 1396855637
  br i1 %.not.1, label %43, label %41

41:                                               ; preds = %39
  %42 = call i64 @UsbBotResetDevice(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %53

43:                                               ; preds = %39
  %44 = load i8, ptr %14, align 4, !tbaa !24
  %45 = icmp eq i8 %44, 2
  br i1 %45, label %46, label %33

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

48:                                               ; preds = %34
  %49 = load i32, ptr %6, align 4, !tbaa !17
  %50 = and i32 %49, 2
  %.not19.1 = icmp eq i32 %50, 0
  br i1 %.not19.1, label %53, label %51

51:                                               ; preds = %48
  %52 = call i64 @UsbClearEndpointStall(ptr noundef nonnull %12, i8 noundef zeroext %10) #3
  br label %53

53:                                               ; preds = %51, %48, %46, %41
  %54 = call ptr @ZeroMem(ptr noundef nonnull %4, i64 noundef 13) #3
  store i32 0, ptr %6, align 4, !tbaa !17
  store i64 13, ptr %5, align 8, !tbaa !18
  %55 = load ptr, ptr %13, align 8, !tbaa !20
  %56 = call i64 %55(ptr noundef nonnull %12, i8 noundef zeroext %10, ptr noundef nonnull %4, ptr noundef nonnull %5, i64 noundef 3000, ptr noundef nonnull %6) #3
  %57 = icmp slt i64 %56, 0
  br i1 %57, label %67, label %58

58:                                               ; preds = %53
  %59 = load i32, ptr %4, align 4, !tbaa !22
  %.not.2 = icmp eq i32 %59, 1396855637
  br i1 %.not.2, label %62, label %60

60:                                               ; preds = %58
  %61 = call i64 @UsbBotResetDevice(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %.loopexit

62:                                               ; preds = %58
  %63 = load i8, ptr %14, align 4, !tbaa !24
  %64 = icmp eq i8 %63, 2
  br i1 %64, label %65, label %33

65:                                               ; preds = %62
  %66 = call i64 @UsbBotResetDevice(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %.loopexit

67:                                               ; preds = %53
  %68 = load i32, ptr %6, align 4, !tbaa !17
  %69 = and i32 %68, 2
  %.not19.2 = icmp eq i32 %69, 0
  br i1 %.not19.2, label %.loopexit, label %70

70:                                               ; preds = %67
  %71 = call i64 @UsbClearEndpointStall(ptr noundef nonnull %12, i8 noundef zeroext %10) #3
  br label %.loopexit

.loopexit:                                        ; preds = %60, %65, %67, %70, %33
  %.2 = phi i64 [ %.lcssa23, %33 ], [ %56, %70 ], [ %56, %67 ], [ %61, %60 ], [ %66, %65 ]
  %72 = getelementptr inbounds i8, ptr %0, i64 32
  %73 = load i32, ptr %72, align 8, !tbaa !25
  %74 = add i32 %73, 1
  store i32 %74, ptr %72, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 13, ptr nonnull %4) #3
  ret i64 %.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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 16}
!9 = !{!"", !10, i64 0, !11, i64 16, !11, i64 24, !12, i64 32, !11, i64 40}
!10 = !{!"", !6, i64 0, !6, i64 1, !6, i64 2, !6, i64 3, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !6, i64 8}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!14, !6, i64 2}
!14 = !{!"", !6, i64 0, !6, i64 1, !6, i64 2, !6, i64 3, !15, i64 4, !6, i64 6}
!15 = !{!"short", !6, i64 0}
!16 = !{!9, !11, i64 40}
!17 = !{!12, !12, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"long long", !6, i64 0}
!20 = !{!21, !11, i64 8}
!21 = !{!"_EFI_USB_IO_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96}
!22 = !{!23, !12, i64 0}
!23 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 12}
!24 = !{!23, !6, i64 12}
!25 = !{!9, !12, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass