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

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

declare i32 @USBD_LL_StallEP(ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @USBD_LL_DataOutStage(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #2 {
  %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
  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
  %10 = load i8, ptr %6, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %95

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

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

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

46:                                               ; preds = %29
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 4, !tbaa !15
  br label %54

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

54:                                               ; preds = %50, %46
  %55 = phi i32 [ %49, %46 ], [ %53, %50 ]
  %56 = trunc i32 %55 to i16
  %57 = call i32 @USBD_CtlContinueRx(ptr noundef %37, ptr noundef %38, i16 noundef zeroext %56)
  br label %82

58:                                               ; preds = %21
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %59, i32 0, i32 17
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = getelementptr inbounds %struct._Device_cb, ptr %61, i32 0, i32 4
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %79

65:                                               ; preds = %58
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %66, i32 0, i32 9
  %68 = load i8, ptr %67, align 4, !tbaa !21
  %69 = zext i8 %68 to i32
  %70 = icmp eq i32 %69, 3
  br i1 %70, label %71, label %79

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

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

82:                                               ; preds = %79, %54
  br label %94

83:                                               ; preds = %13
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %84, i32 0, i32 7
  %86 = load i32, ptr %85, align 4, !tbaa !10
  %87 = icmp eq i32 %86, 5
  br i1 %87, label %88, label %93

88:                                               ; preds = %83
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %89, i32 0, i32 7
  store i32 0, ptr %90, align 4, !tbaa !10
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = call i32 @USBD_LL_StallEP(ptr noundef %91, i8 noundef zeroext 0)
  br label %93

93:                                               ; preds = %88, %83
  br label %94

94:                                               ; preds = %93, %82
  br label %119

95:                                               ; preds = %3
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %96, i32 0, i32 17
  %98 = load ptr, ptr %97, align 8, !tbaa !18
  %99 = getelementptr inbounds %struct._Device_cb, ptr %98, i32 0, i32 6
  %100 = load ptr, ptr %99, align 8, !tbaa !22
  %101 = icmp ne ptr %100, null
  br i1 %101, label %102, label %117

102:                                              ; preds = %95
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %103, i32 0, i32 9
  %105 = load i8, ptr %104, align 4, !tbaa !21
  %106 = zext i8 %105 to i32
  %107 = icmp eq i32 %106, 3
  br i1 %107, label %108, label %117

108:                                              ; preds = %102
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %109, i32 0, i32 17
  %111 = load ptr, ptr %110, align 8, !tbaa !18
  %112 = getelementptr inbounds %struct._Device_cb, ptr %111, i32 0, i32 6
  %113 = load ptr, ptr %112, align 8, !tbaa !22
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = load i8, ptr %6, align 1, !tbaa !9
  %116 = call zeroext i8 %113(ptr noundef %114, i8 noundef zeroext %115)
  br label %118

117:                                              ; preds = %102, %95
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %120

118:                                              ; preds = %108
  br label %119

119:                                              ; preds = %118, %94
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %120

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

declare i32 @USBD_CtlContinueRx(ptr noundef, ptr noundef, i16 noundef zeroext) #1

declare i32 @USBD_CtlSendStatus(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 620}
!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, !13, i64 640, !6, i64 648, !6, i64 656, !6, i64 664, !6, i64 672, !6, i64 680}
!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 12}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!17 = !{!16, !12, i64 16}
!18 = !{!11, !6, i64 656}
!19 = !{!20, !6, i64 32}
!20 = !{!"_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}
!21 = !{!11, !7, i64 628}
!22 = !{!20, !6, i64 48}


; 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"

declare i32 @USBD_LL_StallEP(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @USBD_LL_DataOutStage(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i8 %1, 0
  br i1 %4, label %5, label %33

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 620
  %7 = load i32, ptr %6, align 4, !tbaa !5
  switch i32 %7, label %44 [
    i32 3, label %8
    i32 5, label %31
  ]

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

14:                                               ; preds = %8
  %15 = sub i32 %10, %12
  store i32 %15, ptr %9, align 4, !tbaa !13
  %. = tail call i32 @llvm.umin.i32(i32 %15, i32 %12)
  %16 = trunc i32 %. to i16
  %17 = tail call i32 @USBD_CtlContinueRx(ptr noundef nonnull %0, ptr noundef %2, i16 noundef zeroext %16) #3
  br label %44

18:                                               ; preds = %8
  %19 = getelementptr inbounds i8, ptr %0, i64 656
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %20, i64 32
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %.not33 = icmp eq ptr %22, null
  br i1 %.not33, label %29, label %23

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %0, i64 628
  %25 = load i8, ptr %24, align 4, !tbaa !19
  %26 = icmp eq i8 %25, 3
  br i1 %26, label %27, label %29

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

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

31:                                               ; preds = %5
  store i32 0, ptr %6, align 4, !tbaa !5
  %32 = tail call i32 @USBD_LL_StallEP(ptr noundef nonnull %0, i8 noundef zeroext 0) #3
  br label %44

33:                                               ; preds = %3
  %34 = getelementptr inbounds i8, ptr %0, i64 656
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = getelementptr inbounds i8, ptr %35, i64 48
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  %.not = icmp eq ptr %37, null
  br i1 %.not, label %44, label %38

38:                                               ; preds = %33
  %39 = getelementptr inbounds i8, ptr %0, i64 628
  %40 = load i8, ptr %39, align 4, !tbaa !19
  %41 = icmp eq i8 %40, 3
  br i1 %41, label %42, label %44

42:                                               ; preds = %38
  %43 = tail call zeroext i8 %37(ptr noundef nonnull %0, i8 noundef zeroext %1) #3
  br label %44

44:                                               ; preds = %42, %31, %14, %29, %5, %33, %38
  %.0 = phi i32 [ 2, %38 ], [ 2, %33 ], [ 0, %5 ], [ 0, %29 ], [ 0, %14 ], [ 0, %31 ], [ 0, %42 ]
  ret i32 %.0
}

declare i32 @USBD_CtlContinueRx(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare i32 @USBD_CtlSendStatus(ptr noundef) local_unnamed_addr #0

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

attributes #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 = { 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 = { 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 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 = !{!14, !9, i64 12}
!14 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16}
!15 = !{!14, !9, i64 16}
!16 = !{!6, !12, i64 656}
!17 = !{!18, !12, i64 32}
!18 = !{!"_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, !12, i64 112}
!19 = !{!6, !7, i64 628}
!20 = !{!18, !12, i64 48}


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