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

; 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.USB_OTG_DeviceTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [15 x i32], i32 }
%struct.USB_OTG_INEndpointTypeDef = type { i32, i32, i32, i32, i32, 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 @USB_ReadDevInEPInterrupt(ptr noundef %0, i8 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = ptrtoint ptr %9 to i32
  store i32 %10, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %11 = load i32, ptr %5, align 4, !tbaa !10
  %12 = zext i32 %11 to i64
  %13 = add i64 %12, 2048
  %14 = inttoptr i64 %13 to ptr
  %15 = getelementptr inbounds %struct.USB_OTG_DeviceTypeDef, ptr %14, i32 0, i32 4
  %16 = load volatile i32, ptr %15, align 4, !tbaa !12
  store volatile i32 %16, ptr %7, align 4, !tbaa !10
  %17 = load i32, ptr %5, align 4, !tbaa !10
  %18 = zext i32 %17 to i64
  %19 = add i64 %18, 2048
  %20 = inttoptr i64 %19 to ptr
  %21 = getelementptr inbounds %struct.USB_OTG_DeviceTypeDef, ptr %20, i32 0, i32 13
  %22 = load volatile i32, ptr %21, align 4, !tbaa !14
  store volatile i32 %22, ptr %8, align 4, !tbaa !10
  %23 = load volatile i32, ptr %8, align 4, !tbaa !10
  %24 = load i8, ptr %4, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = and i32 %25, 15
  %27 = lshr i32 %23, %26
  %28 = and i32 %27, 1
  %29 = shl i32 %28, 7
  %30 = load volatile i32, ptr %7, align 4, !tbaa !10
  %31 = or i32 %30, %29
  store volatile i32 %31, ptr %7, align 4, !tbaa !10
  %32 = load i32, ptr %5, align 4, !tbaa !10
  %33 = zext i32 %32 to i64
  %34 = add i64 %33, 2304
  %35 = load i8, ptr %4, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = zext i32 %36 to i64
  %38 = mul i64 %37, 32
  %39 = add i64 %34, %38
  %40 = inttoptr i64 %39 to ptr
  %41 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %40, i32 0, i32 2
  %42 = load volatile i32, ptr %41, align 4, !tbaa !15
  %43 = load volatile i32, ptr %7, align 4, !tbaa !10
  %44 = and i32 %42, %43
  store volatile i32 %44, ptr %6, align 4, !tbaa !10
  %45 = load volatile i32, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %45
}

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 = { 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, !11, i64 16}
!13 = !{!"", !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, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !7, i64 72, !11, i64 132}
!14 = !{!13, !11, i64 52}
!15 = !{!16, !11, i64 8}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local i32 @USB_ReadDevInEPInterrupt(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = ptrtoint ptr %0 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5)
  %7 = and i64 %6, 4294967295
  %8 = add nuw nsw i64 %7, 2048
  %9 = inttoptr i64 %8 to ptr
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %11 = load volatile i32, ptr %10, align 4, !tbaa !5
  store volatile i32 %11, ptr %4, align 4, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %9, i64 52
  %13 = load volatile i32, ptr %12, align 4, !tbaa !11
  store volatile i32 %13, ptr %5, align 4, !tbaa !10
  %.0..0..0..0. = load volatile i32, ptr %5, align 4, !tbaa !10
  %14 = and i8 %1, 15
  %15 = zext nneg i8 %14 to i32
  %16 = lshr i32 %.0..0..0..0., %15
  %17 = shl i32 %16, 7
  %18 = and i32 %17, 128
  %.0..0..0..0.1 = load volatile i32, ptr %4, align 4, !tbaa !10
  %19 = or i32 %18, %.0..0..0..0.1
  store volatile i32 %19, ptr %4, align 4, !tbaa !10
  %20 = add nuw nsw i64 %7, 2304
  %21 = zext i8 %1 to i64
  %22 = shl nuw nsw i64 %21, 5
  %23 = add nuw nsw i64 %20, %22
  %24 = inttoptr i64 %23 to ptr
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load volatile i32, ptr %25, align 4, !tbaa !12
  %.0..0..0..0.2 = load volatile i32, ptr %4, align 4, !tbaa !10
  %27 = and i32 %.0..0..0..0.2, %26
  store volatile i32 %27, ptr %3, align 4, !tbaa !10
  %.0..0..0..0.3 = load volatile i32, ptr %3, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3)
  ret i32 %.0..0..0..0.3
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree norecurse 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" }

!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, !7, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !8, i64 72, !7, i64 132}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 52}
!12 = !{!13, !7, i64 8}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}


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