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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @USBD_LL_SetupStage(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %5, i32 0, i32 15
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_ParseSetupRequest(ptr noundef %6, ptr noundef %7)
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %8, i32 0, i32 7
  store i32 1, ptr %9, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %10, i32 0, i32 15
  %12 = getelementptr inbounds %struct.usb_setup_req, ptr %11, i32 0, i32 4
  %13 = load i16, ptr %12, align 2, !tbaa !14
  %14 = zext i16 %13 to i32
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %15, i32 0, i32 8
  store i32 %14, ptr %16, align 8, !tbaa !15
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %17, i32 0, i32 15
  %19 = getelementptr inbounds %struct.usb_setup_req, ptr %18, i32 0, i32 0
  %20 = load i8, ptr %19, align 8, !tbaa !16
  %21 = zext i8 %20 to i32
  %22 = and i32 %21, 31
  switch i32 %22, label %38 [
    i32 0, label %23
    i32 1, label %28
    i32 2, label %33
  ]

23:                                               ; preds = %2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %25, i32 0, i32 15
  %27 = call i32 @USBD_StdDevReq(ptr noundef %24, ptr noundef %26)
  br label %48

28:                                               ; preds = %2
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %30, i32 0, i32 15
  %32 = call i32 @USBD_StdItfReq(ptr noundef %29, ptr noundef %31)
  br label %48

33:                                               ; preds = %2
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %35, i32 0, i32 15
  %37 = call i32 @USBD_StdEPReq(ptr noundef %34, ptr noundef %36)
  br label %48

38:                                               ; preds = %2
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %40, i32 0, i32 15
  %42 = getelementptr inbounds %struct.usb_setup_req, ptr %41, i32 0, i32 0
  %43 = load i8, ptr %42, align 8, !tbaa !16
  %44 = zext i8 %43 to i32
  %45 = and i32 %44, 128
  %46 = trunc i32 %45 to i8
  %47 = call i32 @USBD_LL_StallEP(ptr noundef %39, i8 noundef zeroext %46)
  br label %48

48:                                               ; preds = %38, %33, %28, %23
  ret i32 0
}

declare void @USBD_ParseSetupRequest(ptr noundef, ptr noundef) #1

declare i32 @USBD_StdDevReq(ptr noundef, ptr noundef) #1

declare i32 @USBD_StdItfReq(ptr noundef, ptr noundef) #1

declare i32 @USBD_StdEPReq(ptr noundef, ptr noundef) #1

declare i32 @USBD_LL_StallEP(ptr noundef, i8 noundef zeroext) #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 = { "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" }

!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, !11, i64 620}
!10 = !{!"_USBD_HandleTypeDef", !7, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 20, !7, i64 320, !11, i64 620, !11, i64 624, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !11, i64 636, !12, i64 640, !6, i64 648, !6, i64 656, !6, i64 664, !6, i64 672, !6, i64 680}
!11 = !{!"int", !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 = !{!10, !13, i64 646}
!15 = !{!10, !11, i64 624}
!16 = !{!10, !7, i64 640}


; 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_LL_SetupStage(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 640
  tail call void @USBD_ParseSetupRequest(ptr noundef nonnull %3, ptr noundef %1) #2
  %4 = getelementptr inbounds i8, ptr %0, i64 620
  store i32 1, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 646
  %6 = load i16, ptr %5, align 2, !tbaa !13
  %7 = zext i16 %6 to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 624
  store i32 %7, ptr %8, align 8, !tbaa !14
  %9 = load i8, ptr %3, align 8, !tbaa !15
  %10 = and i8 %9, 31
  switch i8 %10, label %17 [
    i8 0, label %11
    i8 1, label %13
    i8 2, label %15
  ]

11:                                               ; preds = %2
  %12 = tail call i32 @USBD_StdDevReq(ptr noundef nonnull %0, ptr noundef nonnull %3) #2
  br label %20

13:                                               ; preds = %2
  %14 = tail call i32 @USBD_StdItfReq(ptr noundef nonnull %0, ptr noundef nonnull %3) #2
  br label %20

15:                                               ; preds = %2
  %16 = tail call i32 @USBD_StdEPReq(ptr noundef nonnull %0, ptr noundef nonnull %3) #2
  br label %20

17:                                               ; preds = %2
  %18 = and i8 %9, -128
  %19 = tail call i32 @USBD_LL_StallEP(ptr noundef nonnull %0, i8 noundef zeroext %18) #2
  br label %20

20:                                               ; preds = %17, %15, %13, %11
  ret i32 0
}

declare void @USBD_ParseSetupRequest(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @USBD_StdDevReq(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @USBD_StdItfReq(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @USBD_StdEPReq(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @USBD_LL_StallEP(ptr noundef, i8 noundef zeroext) local_unnamed_addr #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 = { "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, !9, i64 620}
!6 = !{!"_USBD_HandleTypeDef", !7, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !7, i64 20, !7, i64 320, !9, i64 620, !9, i64 624, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !9, i64 636, !10, i64 640, !12, i64 648, !12, i64 656, !12, i64 664, !12, i64 672, !12, i64 680}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"usb_setup_req", !7, i64 0, !7, i64 1, !11, i64 2, !11, i64 4, !11, i64 6}
!11 = !{!"short", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!6, !11, i64 646}
!14 = !{!6, !9, i64 624}
!15 = !{!6, !7, i64 640}


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