; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/usb/stm32/STM32_USB_Device_Library/Core/Src (usbd_ctlreq)

; 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_setup_req = type { i8, i8, i16, i16, i16 }
%struct._USBD_HandleTypeDef = type { i8, i32, i32, i32, i32, [16 x %struct.USBD_EndpointTypeDef], [16 x %struct.USBD_EndpointTypeDef], i32, i32, i8, i8, i8, i8, i8, i32, i8, %struct.usb_setup_req, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.USBD_EndpointTypeDef = type { i32, i32, i32, i32, i16, i16 }
%struct._Device_cb = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @USBD_StdDevReq(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.usb_setup_req, ptr %6, i32 0, i32 0
  %8 = load i8, ptr %7, align 2, !tbaa !11
  %9 = zext i8 %8 to i32
  %10 = and i32 %9, 96
  switch i32 %10, label %52 [
    i32 32, label %11
    i32 64, label %11
    i32 0, label %21
  ]

11:                                               ; preds = %2, %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %12, i32 0, i32 18
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds %struct._Device_cb, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call zeroext i8 %16(ptr noundef %17, ptr noundef %18)
  %20 = zext i8 %19 to i32
  store i32 %20, ptr %5, align 4, !tbaa !9
  br label %55

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.usb_setup_req, ptr %22, i32 0, i32 1
  %24 = load i8, ptr %23, align 1, !tbaa !18
  %25 = zext i8 %24 to i32
  switch i32 %25, label %48 [
    i32 6, label %26
    i32 5, label %29
    i32 9, label %32
    i32 8, label %36
    i32 0, label %39
    i32 3, label %42
    i32 1, label %45
  ]

26:                                               ; preds = %21
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_GetDescriptor(ptr noundef %27, ptr noundef %28)
  br label %51

29:                                               ; preds = %21
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_SetAddress(ptr noundef %30, ptr noundef %31)
  br label %51

32:                                               ; preds = %21
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = call i32 @USBD_SetConfig(ptr noundef %33, ptr noundef %34)
  store i32 %35, ptr %5, align 4, !tbaa !9
  br label %51

36:                                               ; preds = %21
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_GetConfig(ptr noundef %37, ptr noundef %38)
  br label %51

39:                                               ; preds = %21
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_GetStatus(ptr noundef %40, ptr noundef %41)
  br label %51

42:                                               ; preds = %21
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_SetFeature(ptr noundef %43, ptr noundef %44)
  br label %51

45:                                               ; preds = %21
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_ClrFeature(ptr noundef %46, ptr noundef %47)
  br label %51

48:                                               ; preds = %21
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_CtlError(ptr noundef %49, ptr noundef %50)
  br label %51

51:                                               ; preds = %48, %45, %42, %39, %36, %32, %29, %26
  br label %55

52:                                               ; preds = %2
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_CtlError(ptr noundef %53, ptr noundef %54)
  br label %55

55:                                               ; preds = %52, %51, %11
  %56 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %56
}

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

; Function Attrs: nounwind uwtable
declare hidden void @USBD_GetDescriptor(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_SetAddress(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @USBD_SetConfig(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_GetConfig(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_GetStatus(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_SetFeature(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_ClrFeature(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @USBD_CtlError(ptr noundef, ptr noundef) #0

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

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 = { 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, !7, i64 0}
!12 = !{!"usb_setup_req", !7, i64 0, !7, i64 1, !13, i64 2, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 704}
!15 = !{!"_USBD_HandleTypeDef", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !7, i64 340, !10, i64 660, !10, i64 664, !7, i64 668, !7, i64 669, !7, i64 670, !7, i64 671, !7, i64 672, !10, i64 676, !7, i64 680, !12, i64 682, !6, i64 696, !6, i64 704, !6, i64 712, !6, i64 720, !6, i64 728, !6, i64 736, !6, i64 744}
!16 = !{!17, !6, i64 16}
!17 = !{!"_Device_cb", !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, !6, i64 104}
!18 = !{!12, !7, i64 1}


; 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: nounwind uwtable
define dso_local i32 @USBD_StdDevReq(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %1, align 2, !tbaa !5
  %4 = lshr i8 %3, 5
  %5 = and i8 %4, 3
  switch i8 %5, label %default.unreachable [
    i8 1, label %6
    i8 2, label %6
    i8 0, label %13
    i8 3, label %25
  ]

6:                                                ; preds = %2, %2
  %7 = getelementptr inbounds i8, ptr %0, i64 704
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = tail call zeroext i8 %10(ptr noundef %0, ptr noundef nonnull %1) #1
  %12 = zext i8 %11 to i32
  br label %26

13:                                               ; preds = %2
  %14 = getelementptr inbounds i8, ptr %1, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !16
  switch i8 %15, label %24 [
    i8 6, label %16
    i8 5, label %17
    i8 9, label %18
    i8 8, label %20
    i8 0, label %21
    i8 3, label %22
    i8 1, label %23
  ]

16:                                               ; preds = %13
  tail call void @USBD_GetDescriptor(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

17:                                               ; preds = %13
  tail call void @USBD_SetAddress(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

18:                                               ; preds = %13
  %19 = tail call i32 @USBD_SetConfig(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

20:                                               ; preds = %13
  tail call void @USBD_GetConfig(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

21:                                               ; preds = %13
  tail call void @USBD_GetStatus(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

22:                                               ; preds = %13
  tail call void @USBD_SetFeature(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

23:                                               ; preds = %13
  tail call void @USBD_ClrFeature(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

24:                                               ; preds = %13
  tail call void @USBD_CtlError(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

default.unreachable:                              ; preds = %2
  unreachable

25:                                               ; preds = %2
  tail call void @USBD_CtlError(ptr noundef %0, ptr noundef nonnull %1)
  br label %26

26:                                               ; preds = %16, %17, %18, %20, %21, %22, %23, %24, %25, %6
  %.0 = phi i32 [ 0, %25 ], [ 0, %24 ], [ 0, %23 ], [ 0, %22 ], [ 0, %21 ], [ 0, %20 ], [ %19, %18 ], [ 0, %17 ], [ 0, %16 ], [ %12, %6 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @USBD_GetDescriptor(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_SetAddress(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @USBD_SetConfig(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_GetConfig(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_GetStatus(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_SetFeature(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @USBD_ClrFeature(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @USBD_CtlError(ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { 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 = !{!"usb_setup_req", !7, i64 0, !7, i64 1, !9, i64 2, !9, i64 4, !9, i64 6}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!11, !13, i64 704}
!11 = !{!"_USBD_HandleTypeDef", !7, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !7, i64 20, !7, i64 340, !12, i64 660, !12, i64 664, !7, i64 668, !7, i64 669, !7, i64 670, !7, i64 671, !7, i64 672, !12, i64 676, !7, i64 680, !6, i64 682, !13, i64 696, !13, i64 704, !13, i64 712, !13, i64 720, !13, i64 728, !13, i64 736, !13, i64 744}
!12 = !{!"int", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!15, !13, i64 16}
!15 = !{!"_Device_cb", !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, !13, i64 104}
!16 = !{!6, !7, i64 1}


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