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

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

; 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 @USBD_LL_SetupStage(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
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %6, i32 0, i32 16
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @USBD_ParseSetupRequest(ptr noundef %7, ptr noundef %8)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %9, i32 0, i32 7
  store volatile i32 1, ptr %10, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %11, i32 0, i32 16
  %13 = getelementptr inbounds %struct.usb_setup_req, ptr %12, i32 0, i32 4
  %14 = load i16, ptr %13, align 2, !tbaa !14
  %15 = zext i16 %14 to i32
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %16, i32 0, i32 8
  store i32 %15, ptr %17, align 8, !tbaa !15
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %18, i32 0, i32 16
  %20 = getelementptr inbounds %struct.usb_setup_req, ptr %19, i32 0, i32 0
  %21 = load i8, ptr %20, align 2, !tbaa !16
  %22 = zext i8 %21 to i32
  %23 = and i32 %22, 31
  switch i32 %23, label %39 [
    i32 0, label %24
    i32 1, label %29
    i32 2, label %34
  ]

24:                                               ; preds = %2
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %26, i32 0, i32 16
  %28 = call i32 @USBD_StdDevReq(ptr noundef %25, ptr noundef %27)
  store i32 %28, ptr %5, align 4, !tbaa !17
  br label %49

29:                                               ; preds = %2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %31, i32 0, i32 16
  %33 = call i32 @USBD_StdItfReq(ptr noundef %30, ptr noundef %32)
  store i32 %33, ptr %5, align 4, !tbaa !17
  br label %49

34:                                               ; preds = %2
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %36, i32 0, i32 16
  %38 = call i32 @USBD_StdEPReq(ptr noundef %35, ptr noundef %37)
  store i32 %38, ptr %5, align 4, !tbaa !17
  br label %49

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

49:                                               ; preds = %39, %34, %29, %24
  %50 = load i32, ptr %5, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %50
}

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

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

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

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

declare i32 @USBD_LL_StallEP(ptr noundef, i8 noundef zeroext) #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, !11, i64 660}
!10 = !{!"_USBD_HandleTypeDef", !7, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 20, !7, i64 340, !11, i64 660, !11, i64 664, !7, i64 668, !7, i64 669, !7, i64 670, !7, i64 671, !7, i64 672, !11, 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}
!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 688}
!15 = !{!10, !11, i64 664}
!16 = !{!10, !7, i64 682}
!17 = !{!11, !11, i64 0}


; 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_LL_SetupStage(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 682
  tail call void @USBD_ParseSetupRequest(ptr noundef nonnull %3, ptr noundef %1) #2
  %4 = getelementptr inbounds i8, ptr %0, i64 660
  store volatile i32 1, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 688
  %6 = load i16, ptr %5, align 2, !tbaa !13
  %7 = zext i16 %6 to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 664
  store i32 %7, ptr %8, align 8, !tbaa !14
  %9 = load i8, ptr %3, align 2, !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
  %.0 = phi i32 [ %19, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %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 660}
!6 = !{!"_USBD_HandleTypeDef", !7, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !7, i64 20, !7, i64 340, !9, i64 660, !9, i64 664, !7, i64 668, !7, i64 669, !7, i64 670, !7, i64 671, !7, i64 672, !9, i64 676, !7, i64 680, !10, i64 682, !12, i64 696, !12, i64 704, !12, i64 712, !12, i64 720, !12, i64 728, !12, i64 736, !12, i64 744}
!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 688}
!14 = !{!6, !9, i64 664}
!15 = !{!6, !7, i64 682}


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