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

; 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_CBI_PROTOCOL = type { %struct.USB_INTERFACE_DESCRIPTOR, ptr, ptr, ptr, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

19:                                               ; preds = %43, %3
  %20 = load i64, ptr %11, align 8, !tbaa !18
  %21 = icmp slt i64 %20, 3
  br i1 %21, label %22, label %46

22:                                               ; preds = %19
  store i32 0, ptr %10, align 4, !tbaa !9
  store i64 2, ptr %7, align 8, !tbaa !18
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.USB_CBI_PROTOCOL, ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.USB_CBI_PROTOCOL, ptr %28, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %31 = load i8, ptr %8, align 1, !tbaa !17
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = call i64 %27(ptr noundef %30, i8 noundef zeroext %31, ptr noundef %32, ptr noundef %7, i64 noundef %34, ptr noundef %10)
  store i64 %35, ptr %9, align 8, !tbaa !18
  %36 = load i64, ptr %9, align 8, !tbaa !18
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %22
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 16
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  br label %43

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

43:                                               ; preds = %41
  %44 = load i64, ptr %11, align 8, !tbaa !18
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %11, align 8, !tbaa !18
  br label %19, !llvm.loop !23

46:                                               ; preds = %42, %19
  %47 = load i64, ptr %9, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %47
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !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, !6, i64 32}
!12 = !{!"", !13, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"", !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}
!14 = !{!15, !7, i64 2}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !16, i64 4, !7, i64 6}
!16 = !{!"short", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"long long", !7, i64 0}
!20 = !{!12, !6, i64 40}
!21 = !{!22, !6, i64 24}
!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 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; 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"

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbCbiGetStatus(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 2
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = udiv i32 %1, 1000
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = zext nneg i32 %10 to i64
  store i32 0, ptr %5, align 4, !tbaa !14
  store i64 2, ptr %4, align 8, !tbaa !16
  %13 = load ptr, ptr %11, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !19
  %16 = call i64 %15(ptr noundef %13, i8 noundef zeroext %9, ptr noundef %2, ptr noundef nonnull %4, i64 noundef %12, ptr noundef nonnull %5) #2
  %17 = icmp slt i64 %16, 0
  %18 = load i32, ptr %5, align 4
  %19 = icmp eq i32 %18, 16
  %or.cond = select i1 %17, i1 %19, i1 false
  br i1 %or.cond, label %20, label %33

20:                                               ; preds = %3
  store i32 0, ptr %5, align 4, !tbaa !14
  store i64 2, ptr %4, align 8, !tbaa !16
  %21 = load ptr, ptr %11, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %21, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !19
  %24 = call i64 %23(ptr noundef %21, i8 noundef zeroext %9, ptr noundef %2, ptr noundef nonnull %4, i64 noundef %12, ptr noundef nonnull %5) #2
  %25 = icmp slt i64 %24, 0
  %26 = load i32, ptr %5, align 4
  %27 = icmp eq i32 %26, 16
  %or.cond.1 = select i1 %25, i1 %27, i1 false
  br i1 %or.cond.1, label %28, label %33

28:                                               ; preds = %20
  store i32 0, ptr %5, align 4, !tbaa !14
  store i64 2, ptr %4, align 8, !tbaa !16
  %29 = load ptr, ptr %11, align 8, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %29, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = call i64 %31(ptr noundef %29, i8 noundef zeroext %9, ptr noundef %2, ptr noundef nonnull %4, i64 noundef %12, ptr noundef nonnull %5) #2
  br label %33

33:                                               ; preds = %28, %20, %3
  %.lcssa = phi i64 [ %16, %3 ], [ %24, %20 ], [ %32, %28 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i64 %.lcssa
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 32}
!6 = !{!"", !7, i64 0, !10, i64 16, !10, i64 24, !10, 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 = !{!12, !8, i64 2}
!12 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !13, i64 4, !8, i64 6}
!13 = !{!"short", !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !8, i64 0}
!18 = !{!6, !10, i64 40}
!19 = !{!20, !10, i64 24}
!20 = !{!"_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}


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