; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (Receive)

; 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.PCD_HandleTypeDef = type { ptr, %struct.USB_OTG_CfgTypeDef, i8, [16 x %struct.USB_OTG_EPTypeDef], [16 x %struct.USB_OTG_EPTypeDef], i32, i32, i32, [12 x i32], i32, i32, i32, i32, ptr }
%struct.USB_OTG_CfgTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USB_OTG_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i16, i32, ptr, i32, i32, i32 }

; 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 @HAL_PCD_EP_Receive(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  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
  store i32 %3, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %10, i32 0, i32 4
  %12 = load i8, ptr %6, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = and i32 %13, 15
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %11, i64 0, i64 %15
  store ptr %16, ptr %9, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %18, i32 0, i32 8
  store ptr %17, ptr %19, align 8, !tbaa !12
  %20 = load i32, ptr %8, align 4, !tbaa !10
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %21, i32 0, i32 10
  store i32 %20, ptr %22, align 4, !tbaa !15
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %23, i32 0, i32 11
  store i32 0, ptr %24, align 8, !tbaa !16
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %25, i32 0, i32 1
  store i8 0, ptr %26, align 1, !tbaa !17
  %27 = load i8, ptr %6, align 1, !tbaa !9
  %28 = zext i8 %27 to i32
  %29 = and i32 %28, 15
  %30 = trunc i32 %29 to i8
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %31, i32 0, i32 0
  store i8 %30, ptr %32, align 8, !tbaa !18
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.USB_OTG_CfgTypeDef, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %35, align 4, !tbaa !19
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %43

38:                                               ; preds = %4
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = ptrtoint ptr %39 to i32
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %41, i32 0, i32 9
  store i32 %40, ptr %42, align 8, !tbaa !22
  br label %43

43:                                               ; preds = %38, %4
  %44 = load i8, ptr %6, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, 15
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %59

48:                                               ; preds = %43
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !23
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.USB_OTG_CfgTypeDef, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !19
  %57 = trunc i32 %56 to i8
  %58 = call i32 @USB_EP0StartXfer(ptr noundef %51, ptr noundef %52, i8 noundef zeroext %57)
  br label %70

59:                                               ; preds = %43
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %64, i32 0, i32 1
  %66 = getelementptr inbounds %struct.USB_OTG_CfgTypeDef, ptr %65, i32 0, i32 3
  %67 = load i32, ptr %66, align 4, !tbaa !19
  %68 = trunc i32 %67 to i8
  %69 = call i32 @USB_EPStartXfer(ptr noundef %62, ptr noundef %63, i8 noundef zeroext %68)
  br label %70

70:                                               ; preds = %59, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 0
}

declare i32 @USB_EP0StartXfer(ptr noundef, ptr noundef, i8 noundef zeroext) #2

declare i32 @USB_EPStartXfer(ptr noundef, 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !14, i64 6, !11, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !11, i64 28}
!16 = !{!13, !11, i64 32}
!17 = !{!13, !7, i64 1}
!18 = !{!13, !7, i64 0}
!19 = !{!20, !11, i64 20}
!20 = !{!"", !6, i64 0, !21, i64 8, !7, i64 60, !7, i64 64, !7, i64 704, !11, i64 1344, !11, i64 1348, !11, i64 1352, !7, i64 1356, !11, i64 1404, !11, i64 1408, !11, i64 1412, !11, i64 1416, !6, i64 1424}
!21 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48}
!22 = !{!13, !11, i64 24}
!23 = !{!20, !6, 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"

%struct.USB_OTG_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i16, i32, ptr, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @HAL_PCD_EP_Receive(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 704
  %6 = and i8 %1, 15
  %7 = zext nneg i8 %6 to i64
  %8 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %5, i64 0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %2, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %8, i64 28
  store i32 %3, ptr %10, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %8, i64 32
  store i32 0, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %8, i64 1
  store i8 0, ptr %12, align 1, !tbaa !14
  store i8 %6, ptr %8, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 20
  %14 = load i32, ptr %13, align 4, !tbaa !16
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %20

16:                                               ; preds = %4
  %17 = ptrtoint ptr %2 to i64
  %18 = trunc i64 %17 to i32
  %19 = getelementptr inbounds i8, ptr %8, i64 24
  store i32 %18, ptr %19, align 8, !tbaa !19
  br label %20

20:                                               ; preds = %16, %4
  %21 = icmp eq i8 %6, 0
  %22 = load ptr, ptr %0, align 8, !tbaa !20
  %23 = trunc i32 %14 to i8
  br i1 %21, label %24, label %26

24:                                               ; preds = %20
  %25 = tail call i32 @USB_EP0StartXfer(ptr noundef %22, ptr noundef nonnull %8, i8 noundef zeroext %23) #2
  br label %28

26:                                               ; preds = %20
  %27 = tail call i32 @USB_EPStartXfer(ptr noundef %22, ptr noundef nonnull %8, i8 noundef zeroext %23) #2
  br label %28

28:                                               ; preds = %26, %24
  ret i32 0
}

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

declare i32 @USB_EPStartXfer(ptr noundef, 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, !11, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !9, i64 6, !10, i64 8, !11, i64 16, !10, i64 24, !10, i64 28, !10, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!6, !10, i64 28}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !7, i64 1}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !10, i64 20}
!17 = !{!"", !11, i64 0, !18, i64 8, !7, i64 60, !7, i64 64, !7, i64 704, !10, i64 1344, !10, i64 1348, !10, i64 1352, !7, i64 1356, !10, i64 1404, !10, i64 1408, !10, i64 1412, !10, i64 1416, !11, i64 1424}
!18 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48}
!19 = !{!6, !10, i64 24}
!20 = !{!17, !11, i64 0}


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