; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Middlewares/ST/STM32_USB_Host_Library/Core/Src (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._USBH_HandleTypeDef = type { i32, i32, i32, %struct.USBH_CtrlTypeDef, %struct.USBH_DeviceTypeDef, [1 x ptr], ptr, i32, [16 x i32], i32, i32, i8, ptr, ptr }
%struct.USBH_CtrlTypeDef = type { i8, i8, i8, ptr, i16, i16, %union._USB_Setup, i32, i8 }
%union._USB_Setup = type { [2 x i32] }
%struct.USBH_DeviceTypeDef = type { [256 x i8], [512 x i8], i8, i8, i8, i8, i8, i8, i8, i8, i8, %struct._DeviceDescriptor, %struct._ConfigurationDescriptor }
%struct._DeviceDescriptor = type { i8, i8, i16, i8, i8, i8, i8, i16, i16, i16, i8, i8, i8, i8 }
%struct._ConfigurationDescriptor = type { i8, i8, i16, i8, i8, i8, i8, i8, [2 x %struct._InterfaceDescriptor] }
%struct._InterfaceDescriptor = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, [2 x %struct._EndpointDescriptor] }
%struct._EndpointDescriptor = type { i8, i8, i8, i8, i16, i8 }

; 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 i32 @USBH_CtlReq(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i16 %2, ptr %6, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !11
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !13
  switch i32 %10, label %48 [
    i32 1, label %11
    i32 2, label %25
  ]

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %13, i32 0, i32 3
  %15 = getelementptr inbounds %struct.USBH_CtrlTypeDef, ptr %14, i32 0, i32 3
  store ptr %12, ptr %15, align 8, !tbaa !19
  %16 = load i16, ptr %6, align 2, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %17, i32 0, i32 3
  %19 = getelementptr inbounds %struct.USBH_CtrlTypeDef, ptr %18, i32 0, i32 4
  store i16 %16, ptr %19, align 8, !tbaa !20
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %20, i32 0, i32 3
  %22 = getelementptr inbounds %struct.USBH_CtrlTypeDef, ptr %21, i32 0, i32 7
  store i32 1, ptr %22, align 4, !tbaa !21
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %23, i32 0, i32 2
  store i32 2, ptr %24, align 8, !tbaa !13
  store i32 1, ptr %7, align 4, !tbaa !11
  br label %49

25:                                               ; preds = %3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call i32 @USBH_HandleControl(ptr noundef %26)
  store i32 %27, ptr %7, align 4, !tbaa !11
  %28 = load i32, ptr %7, align 4, !tbaa !11
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %33, label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %7, align 4, !tbaa !11
  %32 = icmp eq i32 %31, 3
  br i1 %32, label %33, label %39

33:                                               ; preds = %30, %25
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %34, i32 0, i32 2
  store i32 1, ptr %35, align 8, !tbaa !13
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %36, i32 0, i32 3
  %38 = getelementptr inbounds %struct.USBH_CtrlTypeDef, ptr %37, i32 0, i32 7
  store i32 0, ptr %38, align 4, !tbaa !21
  br label %47

39:                                               ; preds = %30
  %40 = load i32, ptr %7, align 4, !tbaa !11
  %41 = icmp eq i32 %40, 2
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %43, i32 0, i32 2
  store i32 1, ptr %44, align 8, !tbaa !13
  br label %46

45:                                               ; preds = %39
  br label %46

46:                                               ; preds = %45, %42
  br label %47

47:                                               ; preds = %46, %33
  br label %49

48:                                               ; preds = %3
  br label %49

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

; Function Attrs: nounwind uwtable
declare hidden i32 @USBH_HandleControl(ptr noundef) #1

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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_USBH_HandleTypeDef", !12, i64 0, !12, i64 4, !12, i64 8, !15, i64 16, !16, i64 56, !7, i64 920, !6, i64 928, !12, i64 936, !7, i64 940, !12, i64 1004, !12, i64 1008, !7, i64 1012, !6, i64 1016, !6, i64 1024}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !6, i64 8, !10, i64 16, !10, i64 18, !7, i64 20, !12, i64 28, !7, i64 32}
!16 = !{!"", !7, i64 0, !7, i64 256, !7, i64 768, !7, i64 769, !7, i64 770, !7, i64 771, !7, i64 772, !7, i64 773, !7, i64 774, !7, i64 775, !7, i64 776, !17, i64 778, !18, i64 796}
!17 = !{!"_DeviceDescriptor", !7, i64 0, !7, i64 1, !10, i64 2, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 10, !10, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17}
!18 = !{!"_ConfigurationDescriptor", !7, i64 0, !7, i64 1, !10, i64 2, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 10}
!19 = !{!14, !6, i64 24}
!20 = !{!14, !10, i64 32}
!21 = !{!14, !12, i64 44}


; 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 @USBH_CtlReq(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  switch i32 %5, label %15 [
    i32 1, label %6
    i32 2, label %10
  ]

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %1, ptr %7, align 8, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  store i16 %2, ptr %8, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 1, ptr %9, align 4, !tbaa !18
  store i32 2, ptr %4, align 8, !tbaa !5
  br label %15

10:                                               ; preds = %3
  %11 = tail call i32 @USBH_HandleControl(ptr noundef nonnull %0)
  switch i32 %11, label %15 [
    i32 3, label %12
    i32 0, label %12
    i32 2, label %14
  ]

12:                                               ; preds = %10, %10
  store i32 1, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 0, ptr %13, align 4, !tbaa !18
  br label %15

14:                                               ; preds = %10
  store i32 1, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %10, %3, %12, %14, %6
  %.0 = phi i32 [ 1, %3 ], [ %11, %12 ], [ 2, %14 ], [ 1, %6 ], [ %11, %10 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @USBH_HandleControl(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" }

!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 8}
!6 = !{!"_USBH_HandleTypeDef", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !13, i64 56, !8, i64 920, !11, i64 928, !7, i64 936, !8, i64 940, !7, i64 1004, !7, i64 1008, !8, i64 1012, !11, i64 1016, !11, i64 1024}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !11, i64 8, !12, i64 16, !12, i64 18, !8, i64 20, !7, i64 28, !8, i64 32}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"", !8, i64 0, !8, i64 256, !8, i64 768, !8, i64 769, !8, i64 770, !8, i64 771, !8, i64 772, !8, i64 773, !8, i64 774, !8, i64 775, !8, i64 776, !14, i64 778, !15, i64 796}
!14 = !{!"_DeviceDescriptor", !8, i64 0, !8, i64 1, !12, i64 2, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !12, i64 8, !12, i64 10, !12, i64 12, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17}
!15 = !{!"_ConfigurationDescriptor", !8, i64 0, !8, i64 1, !12, i64 2, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !8, i64 10}
!16 = !{!6, !11, i64 24}
!17 = !{!6, !12, i64 32}
!18 = !{!6, !7, i64 44}


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