; 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_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i16, i32, ptr, i32, i32, i32 }
%struct.USB_OTG_INEndpointTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USB_OTG_OUTEndpointTypeDef = type { i32, i32, i32, i32, i32, i32, [2 x 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_EPClearStall(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = ptrtoint ptr %7 to i32
  store i32 %8, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %9, i32 0, i32 0
  %11 = load i8, ptr %10, align 8, !tbaa !11
  %12 = zext i8 %11 to i32
  store i32 %12, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %13, i32 0, i32 1
  %15 = load i8, ptr %14, align 1, !tbaa !14
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %58

18:                                               ; preds = %2
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = add i64 %20, 2304
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = mul i64 %23, 32
  %25 = add i64 %21, %24
  %26 = inttoptr i64 %25 to ptr
  %27 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %26, i32 0, i32 0
  %28 = load volatile i32, ptr %27, align 4, !tbaa !15
  %29 = zext i32 %28 to i64
  %30 = and i64 %29, -2097153
  %31 = trunc i64 %30 to i32
  store volatile i32 %31, ptr %27, align 4, !tbaa !15
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %32, i32 0, i32 3
  %34 = load i8, ptr %33, align 1, !tbaa !17
  %35 = zext i8 %34 to i32
  %36 = icmp eq i32 %35, 3
  br i1 %36, label %43, label %37

37:                                               ; preds = %18
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %38, i32 0, i32 3
  %40 = load i8, ptr %39, align 1, !tbaa !17
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 2
  br i1 %42, label %43, label %57

43:                                               ; preds = %37, %18
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = add i64 %45, 2304
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = mul i64 %48, 32
  %50 = add i64 %46, %49
  %51 = inttoptr i64 %50 to ptr
  %52 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %51, i32 0, i32 0
  %53 = load volatile i32, ptr %52, align 4, !tbaa !15
  %54 = zext i32 %53 to i64
  %55 = or i64 %54, 268435456
  %56 = trunc i64 %55 to i32
  store volatile i32 %56, ptr %52, align 4, !tbaa !15
  br label %57

57:                                               ; preds = %43, %37
  br label %98

58:                                               ; preds = %2
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = add i64 %60, 2816
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = mul i64 %63, 32
  %65 = add i64 %61, %64
  %66 = inttoptr i64 %65 to ptr
  %67 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %66, i32 0, i32 0
  %68 = load volatile i32, ptr %67, align 4, !tbaa !18
  %69 = zext i32 %68 to i64
  %70 = and i64 %69, -2097153
  %71 = trunc i64 %70 to i32
  store volatile i32 %71, ptr %67, align 4, !tbaa !18
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %72, i32 0, i32 3
  %74 = load i8, ptr %73, align 1, !tbaa !17
  %75 = zext i8 %74 to i32
  %76 = icmp eq i32 %75, 3
  br i1 %76, label %83, label %77

77:                                               ; preds = %58
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %78, i32 0, i32 3
  %80 = load i8, ptr %79, align 1, !tbaa !17
  %81 = zext i8 %80 to i32
  %82 = icmp eq i32 %81, 2
  br i1 %82, label %83, label %97

83:                                               ; preds = %77, %58
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = add i64 %85, 2816
  %87 = load i32, ptr %6, align 4, !tbaa !9
  %88 = zext i32 %87 to i64
  %89 = mul i64 %88, 32
  %90 = add i64 %86, %89
  %91 = inttoptr i64 %90 to ptr
  %92 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %91, i32 0, i32 0
  %93 = load volatile i32, ptr %92, align 4, !tbaa !18
  %94 = zext i32 %93 to i64
  %95 = or i64 %94, 268435456
  %96 = trunc i64 %95 to i32
  store volatile i32 %96, ptr %92, align 4, !tbaa !18
  br label %97

97:                                               ; preds = %83, %77
  br label %98

98:                                               ; preds = %97, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 0
}

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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !13, i64 6, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !7, i64 1}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!17 = !{!12, !7, i64 3}
!18 = !{!19, !10, i64 0}
!19 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24}


; 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: nofree norecurse nounwind uwtable
define dso_local noundef i32 @USB_EPClearStall(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = ptrtoint ptr %0 to i64
  %4 = load i8, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !12
  %7 = icmp eq i8 %6, 1
  %8 = and i64 %3, 4294967295
  %9 = zext i8 %4 to i64
  %10 = shl nuw nsw i64 %9, 5
  %11 = getelementptr inbounds i8, ptr %1, i64 3
  br i1 %7, label %12, label %20

12:                                               ; preds = %2
  %13 = add nuw nsw i64 %8, 2304
  %14 = add nuw nsw i64 %13, %10
  %15 = inttoptr i64 %14 to ptr
  %16 = load volatile i32, ptr %15, align 4, !tbaa !13
  %17 = and i32 %16, -2097153
  store volatile i32 %17, ptr %15, align 4, !tbaa !13
  %18 = load i8, ptr %11, align 1, !tbaa !15
  %19 = and i8 %18, -2
  %switch = icmp eq i8 %19, 2
  br i1 %switch, label %.sink.split, label %30

20:                                               ; preds = %2
  %21 = add nuw nsw i64 %8, 2816
  %22 = add nuw nsw i64 %21, %10
  %23 = inttoptr i64 %22 to ptr
  %24 = load volatile i32, ptr %23, align 4, !tbaa !16
  %25 = and i32 %24, -2097153
  store volatile i32 %25, ptr %23, align 4, !tbaa !16
  %26 = load i8, ptr %11, align 1, !tbaa !15
  %27 = and i8 %26, -2
  %switch16 = icmp eq i8 %27, 2
  br i1 %switch16, label %.sink.split, label %30

.sink.split:                                      ; preds = %20, %12
  %.sink = phi ptr [ %15, %12 ], [ %23, %20 ]
  %28 = load volatile i32, ptr %.sink, align 4, !tbaa !18
  %29 = or i32 %28, 268435456
  store volatile i32 %29, ptr %.sink, align 4, !tbaa !18
  br label %30

30:                                               ; preds = %.sink.split, %20, %12
  ret i32 0
}

attributes #0 = { 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 0}
!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, !7, i64 1}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!6, !7, i64 3}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24}
!18 = !{!10, !10, i64 0}


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