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

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

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

; 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 i32 @USBD_StdItfReq(ptr noundef %0, ptr noundef %1) #1 {
  %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) #3
  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 %55 [
    i32 32, label %11
    i32 64, label %11
    i32 0, label %11
  ]

11:                                               ; preds = %2, %2, %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %12, i32 0, i32 9
  %14 = load i8, ptr %13, align 4, !tbaa !14
  %15 = zext i8 %14 to i32
  switch i32 %15, label %51 [
    i32 1, label %16
    i32 2, label %16
    i32 3, label %16
  ]

16:                                               ; preds = %11, %11, %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.usb_setup_req, ptr %17, i32 0, i32 3
  %19 = load i16, ptr %18, align 2, !tbaa !16
  %20 = zext i16 %19 to i32
  %21 = and i32 %20, 255
  %22 = trunc i32 %21 to i8
  %23 = zext i8 %22 to i32
  %24 = icmp ule i32 %23, 1
  br i1 %24, label %25, label %47

25:                                               ; preds = %16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %26, i32 0, i32 17
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds %struct._Device_cb, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call zeroext i8 %30(ptr noundef %31, ptr noundef %32)
  %34 = zext i8 %33 to i32
  store i32 %34, ptr %5, align 4, !tbaa !9
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.usb_setup_req, ptr %35, i32 0, i32 4
  %37 = load i16, ptr %36, align 2, !tbaa !20
  %38 = zext i16 %37 to i32
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %25
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %40
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i32 @USBD_CtlSendStatus(ptr noundef %44)
  br label %46

46:                                               ; preds = %43, %40, %25
  br label %50

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

50:                                               ; preds = %47, %46
  br label %54

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

54:                                               ; preds = %51, %50
  br label %58

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

58:                                               ; preds = %55, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 0
}

declare i32 @USBD_CtlSendStatus(ptr noundef) #2

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 = { "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 = !{!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, !7, i64 628}
!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 = !{!12, !13, i64 4}
!17 = !{!15, !6, i64 656}
!18 = !{!19, !6, i64 16}
!19 = !{!"_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}
!20 = !{!12, !13, i64 6}


; 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
declare dso_local void @USBD_CtlError(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @USBD_StdItfReq(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %1, align 2, !tbaa !5
  %4 = and i8 %3, 96
  %switch.not = icmp eq i8 %4, 96
  br i1 %switch.not, label %27, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 628
  %7 = load i8, ptr %6, align 4, !tbaa !10
  %.off = add i8 %7, -1
  %switch16 = icmp ult i8 %.off, 3
  br i1 %switch16, label %8, label %26

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 4
  %10 = load i16, ptr %9, align 2, !tbaa !14
  %11 = and i16 %10, 254
  %12 = icmp eq i16 %11, 0
  br i1 %12, label %13, label %25

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 656
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = tail call zeroext i8 %17(ptr noundef nonnull %0, ptr noundef nonnull %1) #2
  %19 = getelementptr inbounds i8, ptr %1, i64 6
  %20 = load i16, ptr %19, align 2, !tbaa !18
  %21 = icmp eq i16 %20, 0
  %22 = icmp eq i8 %18, 0
  %or.cond = select i1 %21, i1 %22, i1 false
  br i1 %or.cond, label %23, label %28

23:                                               ; preds = %13
  %24 = tail call i32 @USBD_CtlSendStatus(ptr noundef nonnull %0) #2
  br label %28

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

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

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

28:                                               ; preds = %26, %13, %23, %25, %27
  ret i32 0
}

declare i32 @USBD_CtlSendStatus(ptr noundef) 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, !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, !7, i64 628}
!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 = !{!6, !9, i64 4}
!15 = !{!11, !13, i64 656}
!16 = !{!17, !13, i64 16}
!17 = !{!"_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}
!18 = !{!6, !9, i64 6}


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