; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Middlewares/ST/STM32_USB_Device_Library/Core/Src (StdDevReq)

; 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, [15 x %struct.USBD_EndpointTypeDef], [15 x %struct.USBD_EndpointTypeDef], i32, i32, i8, i8, i8, i8, i8, i32, %struct.usb_setup_req, ptr, ptr, ptr, ptr, ptr }
%struct.USBD_EndpointTypeDef = type { i32, i32, i32, i32, i32 }
%struct._Device_cb = type { ptr, 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 %50 [
    i32 32, label %11
    i32 64, label %11
    i32 0, label %20
  ]

11:                                               ; preds = %2, %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %12, i32 0, i32 17
  %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)
  br label %53

20:                                               ; preds = %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.usb_setup_req, ptr %21, i32 0, i32 1
  %23 = load i8, ptr %22, align 1, !tbaa !18
  %24 = zext i8 %23 to i32
  switch i32 %24, label %46 [
    i32 6, label %25
    i32 5, label %28
    i32 9, label %31
    i32 8, label %34
    i32 0, label %37
    i32 3, label %40
    i32 1, label %43
  ]

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

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

31:                                               ; preds = %20
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_SetConfig(ptr noundef %32, ptr noundef %33)
  br label %49

34:                                               ; preds = %20
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_GetConfig(ptr noundef %35, ptr noundef %36)
  br label %49

37:                                               ; preds = %20
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_GetStatus(ptr noundef %38, ptr noundef %39)
  br label %49

40:                                               ; preds = %20
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_SetFeature(ptr noundef %41, ptr noundef %42)
  br label %49

43:                                               ; preds = %20
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_ClrFeature(ptr noundef %44, ptr noundef %45)
  br label %49

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

49:                                               ; preds = %46, %43, %40, %37, %34, %31, %28, %25
  br label %53

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

53:                                               ; preds = %50, %49, %11
  %54 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %54
}

; 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 void @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 656}
!15 = !{!"_USBD_HandleTypeDef", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !7, i64 320, !10, i64 620, !10, i64 624, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !10, i64 636, !12, i64 640, !6, i64 648, !6, i64 656, !6, i64 664, !6, i64 672, !6, i64 680}
!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, !6, i64 112}
!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 noundef 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 %12
    i8 3, label %23
  ]

6:                                                ; preds = %2, %2
  %7 = getelementptr inbounds i8, ptr %0, i64 656
  %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
  br label %24

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

15:                                               ; preds = %12
  tail call void @USBD_GetDescriptor(ptr noundef %0, ptr noundef nonnull %1)
  br label %24

16:                                               ; preds = %12
  tail call void @USBD_SetAddress(ptr noundef %0, ptr noundef nonnull %1)
  br label %24

17:                                               ; preds = %12
  tail call void @USBD_SetConfig(ptr noundef %0, ptr noundef nonnull %1)
  br label %24

18:                                               ; preds = %12
  tail call void @USBD_GetConfig(ptr noundef %0, ptr noundef nonnull %1)
  br label %24

19:                                               ; preds = %12
  tail call void @USBD_GetStatus(ptr noundef %0, ptr noundef nonnull %1)
  br label %24

20:                                               ; preds = %12
  tail call void @USBD_SetFeature(ptr noundef %0, ptr noundef nonnull %1)
  br label %24

21:                                               ; preds = %12
  tail call void @USBD_ClrFeature(ptr noundef %0, ptr noundef nonnull %1)
  br label %24

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

default.unreachable:                              ; preds = %2
  unreachable

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

24:                                               ; preds = %15, %16, %17, %18, %19, %20, %21, %22, %23, %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 void @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 656}
!11 = !{!"_USBD_HandleTypeDef", !7, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !7, i64 20, !7, i64 320, !12, i64 620, !12, i64 624, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !12, i64 636, !6, i64 640, !13, i64 648, !13, i64 656, !13, i64 664, !13, i64 672, !13, i64 680}
!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, !13, i64 112}
!16 = !{!6, !7, i64 1}


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