; LLVM IR from reazon-research/OpenArm :: control/canfd_control/Drivers/STM32H7xx_HAL_Driver/Src (stm32h7xx_hal_pcd)

; 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_CfgTypeDef, i8, [16 x %struct.USB_EPTypeDef], [16 x %struct.USB_EPTypeDef], i32, i32, i32, [12 x i32], i32, i32, i32, i32, i32, ptr }
%struct.USB_CfgTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USB_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i32, ptr, i32, i32, i8, i16, 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_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_EPTypeDef, ptr %18, i32 0, i32 7
  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_EPTypeDef, ptr %21, i32 0, i32 8
  store i32 %20, ptr %22, align 8, !tbaa !15
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.USB_EPTypeDef, ptr %23, i32 0, i32 9
  store i32 0, ptr %24, align 4, !tbaa !16
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.USB_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_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_CfgTypeDef, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !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_EPTypeDef, ptr %41, i32 0, i32 12
  store i32 %40, ptr %42, align 4, !tbaa !22
  br label %43

43:                                               ; preds = %38, %4
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds %struct.USB_CfgTypeDef, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = trunc i32 %51 to i8
  %53 = call i32 @USB_EPStartXfer(ptr noundef %46, ptr noundef %47, i8 noundef zeroext %52)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 0
}

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, !11, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !7, i64 32, !14, i64 34, !11, i64 36, !11, i64 40}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !11, i64 24}
!16 = !{!13, !11, i64 28}
!17 = !{!13, !7, i64 1}
!18 = !{!13, !7, i64 0}
!19 = !{!20, !11, i64 16}
!20 = !{!"", !6, i64 0, !21, i64 8, !7, i64 60, !7, i64 64, !7, i64 832, !11, i64 1600, !11, i64 1604, !11, i64 1608, !7, i64 1612, !11, i64 1660, !11, i64 1664, !11, i64 1668, !11, i64 1672, !11, i64 1676, !6, i64 1680}
!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 36}
!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_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i32, ptr, i32, i32, i8, i16, 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 832
  %6 = and i8 %1, 15
  %7 = zext nneg i8 %6 to i64
  %8 = getelementptr inbounds [16 x %struct.USB_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 24
  store i32 %3, ptr %10, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %8, i64 28
  store i32 0, ptr %11, align 4, !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 16
  %14 = load i32, ptr %13, align 8, !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 36
  store i32 %18, ptr %19, align 4, !tbaa !19
  br label %20

20:                                               ; preds = %16, %4
  %21 = load ptr, ptr %0, align 8, !tbaa !20
  %22 = trunc i32 %14 to i8
  %23 = tail call i32 @USB_EPStartXfer(ptr noundef %21, ptr noundef nonnull %8, i8 noundef zeroext %22) #2
  ret i32 0
}

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, !10, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !9, i64 8, !10, i64 16, !9, i64 24, !9, i64 28, !7, i64 32, !11, i64 34, !9, i64 36, !9, i64 40}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!6, !9, i64 24}
!13 = !{!6, !9, i64 28}
!14 = !{!6, !7, i64 1}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !9, i64 16}
!17 = !{!"", !10, i64 0, !18, i64 8, !7, i64 60, !7, i64 64, !7, i64 832, !9, i64 1600, !9, i64 1604, !9, i64 1608, !7, i64 1612, !9, i64 1660, !9, i64 1664, !9, i64 1668, !9, i64 1672, !9, i64 1676, !10, i64 1680}
!18 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !9, i64 24, !9, i64 28, !9, i64 32, !9, i64 36, !9, i64 40, !9, i64 44, !9, i64 48}
!19 = !{!6, !9, i64 36}
!20 = !{!17, !10, i64 0}


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