; 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 }
%struct._Device_cb = type { 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: 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_DataOutStage(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load i8, ptr %6, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %86

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %15, i32 0, i32 6
  %17 = getelementptr inbounds [16 x %struct.USBD_EndpointTypeDef], ptr %16, i64 0, i64 0
  store ptr %17, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %18, i32 0, i32 7
  %20 = load volatile i32, ptr %19, align 4, !tbaa !10
  %21 = icmp eq i32 %20, 3
  br i1 %21, label %22, label %84

22:                                               ; preds = %14
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = icmp ugt i32 %25, %28
  br i1 %29, label %30, label %58

30:                                               ; preds = %22
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 4, !tbaa !17
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = sub i32 %36, %33
  store i32 %37, ptr %35, align 4, !tbaa !15
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !15
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !17
  %46 = icmp ult i32 %42, %45
  br i1 %46, label %47, label %51

47:                                               ; preds = %30
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !15
  br label %55

51:                                               ; preds = %30
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !17
  br label %55

55:                                               ; preds = %51, %47
  %56 = phi i32 [ %50, %47 ], [ %54, %51 ]
  %57 = call i32 @USBD_CtlContinueRx(ptr noundef %38, ptr noundef %39, i32 noundef %56)
  br label %83

58:                                               ; preds = %22
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %59, i32 0, i32 9
  %61 = load volatile i8, ptr %60, align 4, !tbaa !18
  %62 = zext i8 %61 to i32
  %63 = icmp eq i32 %62, 3
  br i1 %63, label %64, label %80

64:                                               ; preds = %58
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %65, i32 0, i32 18
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = getelementptr inbounds %struct._Device_cb, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !20
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %79

71:                                               ; preds = %64
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %72, i32 0, i32 18
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  %75 = getelementptr inbounds %struct._Device_cb, ptr %74, i32 0, i32 4
  %76 = load ptr, ptr %75, align 8, !tbaa !20
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = call zeroext i8 %76(ptr noundef %77)
  br label %79

79:                                               ; preds = %71, %64
  br label %80

80:                                               ; preds = %79, %58
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = call i32 @USBD_CtlSendStatus(ptr noundef %81)
  br label %83

83:                                               ; preds = %80, %55
  br label %85

84:                                               ; preds = %14
  br label %85

85:                                               ; preds = %84, %83
  br label %116

86:                                               ; preds = %3
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %87, i32 0, i32 9
  %89 = load volatile i8, ptr %88, align 4, !tbaa !18
  %90 = zext i8 %89 to i32
  %91 = icmp eq i32 %90, 3
  br i1 %91, label %92, label %115

92:                                               ; preds = %86
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %93, i32 0, i32 18
  %95 = load ptr, ptr %94, align 8, !tbaa !19
  %96 = getelementptr inbounds %struct._Device_cb, ptr %95, i32 0, i32 6
  %97 = load ptr, ptr %96, align 8, !tbaa !22
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %114

99:                                               ; preds = %92
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %100, i32 0, i32 18
  %102 = load ptr, ptr %101, align 8, !tbaa !19
  %103 = getelementptr inbounds %struct._Device_cb, ptr %102, i32 0, i32 6
  %104 = load ptr, ptr %103, align 8, !tbaa !22
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = load i8, ptr %6, align 1, !tbaa !9
  %107 = call zeroext i8 %104(ptr noundef %105, i8 noundef zeroext %106)
  %108 = zext i8 %107 to i32
  store i32 %108, ptr %9, align 4, !tbaa !23
  %109 = load i32, ptr %9, align 4, !tbaa !23
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %113

111:                                              ; preds = %99
  %112 = load i32, ptr %9, align 4, !tbaa !23
  store i32 %112, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %117

113:                                              ; preds = %99
  br label %114

114:                                              ; preds = %113, %92
  br label %115

115:                                              ; preds = %114, %86
  br label %116

116:                                              ; preds = %115, %85
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %117

117:                                              ; preds = %116, %111
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %118 = load i32, ptr %4, align 4
  ret i32 %118
}

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

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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 660}
!11 = !{!"_USBD_HandleTypeDef", !7, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !7, i64 20, !7, i64 340, !12, i64 660, !12, i64 664, !7, i64 668, !7, i64 669, !7, i64 670, !7, i64 671, !7, i64 672, !12, i64 676, !7, i64 680, !13, i64 682, !6, i64 696, !6, i64 704, !6, i64 712, !6, i64 720, !6, i64 728, !6, i64 736, !6, i64 744}
!12 = !{!"int", !7, i64 0}
!13 = !{!"usb_setup_req", !7, i64 0, !7, i64 1, !14, i64 2, !14, i64 4, !14, i64 6}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !12, i64 8}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !14, i64 16, !14, i64 18}
!17 = !{!16, !12, i64 12}
!18 = !{!11, !7, i64 668}
!19 = !{!11, !6, i64 704}
!20 = !{!21, !6, i64 32}
!21 = !{!"_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}
!22 = !{!21, !6, i64 48}
!23 = !{!12, !12, 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 range(i32 0, 256) i32 @USBD_LL_DataOutStage(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i8 %1, 0
  br i1 %4, label %5, label %31

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 660
  %7 = load volatile i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 3
  br i1 %8, label %9, label %43

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 348
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 352
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = icmp ugt i32 %11, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %9
  %16 = sub i32 %11, %13
  store i32 %16, ptr %10, align 4, !tbaa !13
  %. = tail call i32 @llvm.umin.i32(i32 %16, i32 %13)
  %17 = tail call i32 @USBD_CtlContinueRx(ptr noundef nonnull %0, ptr noundef %2, i32 noundef %.) #3
  br label %43

18:                                               ; preds = %9
  %19 = getelementptr inbounds i8, ptr %0, i64 668
  %20 = load volatile i8, ptr %19, align 4, !tbaa !16
  %21 = icmp eq i8 %20, 3
  br i1 %21, label %22, label %29

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %0, i64 704
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %24, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %.not33 = icmp eq ptr %26, null
  br i1 %.not33, label %29, label %27

27:                                               ; preds = %22
  %28 = tail call zeroext i8 %26(ptr noundef nonnull %0) #3
  br label %29

29:                                               ; preds = %22, %27, %18
  %30 = tail call i32 @USBD_CtlSendStatus(ptr noundef nonnull %0) #3
  br label %43

31:                                               ; preds = %3
  %32 = getelementptr inbounds i8, ptr %0, i64 668
  %33 = load volatile i8, ptr %32, align 4, !tbaa !16
  %34 = icmp eq i8 %33, 3
  br i1 %34, label %35, label %43

35:                                               ; preds = %31
  %36 = getelementptr inbounds i8, ptr %0, i64 704
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = getelementptr inbounds i8, ptr %37, i64 48
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %.not = icmp eq ptr %39, null
  br i1 %.not, label %43, label %40

40:                                               ; preds = %35
  %41 = tail call zeroext i8 %39(ptr noundef nonnull %0, i8 noundef zeroext %1) #3
  %42 = zext i8 %41 to i32
  br label %43

43:                                               ; preds = %40, %5, %15, %29, %35, %31
  %.0 = phi i32 [ 0, %31 ], [ 0, %35 ], [ 0, %29 ], [ 0, %15 ], [ 0, %5 ], [ %42, %40 ]
  ret i32 %.0
}

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

declare i32 @USBD_CtlSendStatus(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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 = !{!14, !9, i64 8}
!14 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !11, i64 16, !11, i64 18}
!15 = !{!14, !9, i64 12}
!16 = !{!6, !7, i64 668}
!17 = !{!6, !12, i64 704}
!18 = !{!19, !12, i64 32}
!19 = !{!"_Device_cb", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104}
!20 = !{!19, !12, i64 48}


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