; 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_EPSetStall(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 %63

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, 2147483648
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %49

32:                                               ; preds = %18
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %49

35:                                               ; preds = %32
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = add i64 %37, 2304
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = mul i64 %40, 32
  %42 = add i64 %38, %41
  %43 = inttoptr i64 %42 to ptr
  %44 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %43, i32 0, i32 0
  %45 = load volatile i32, ptr %44, align 4, !tbaa !15
  %46 = zext i32 %45 to i64
  %47 = and i64 %46, -1073741825
  %48 = trunc i64 %47 to i32
  store volatile i32 %48, ptr %44, align 4, !tbaa !15
  br label %49

49:                                               ; preds = %35, %32, %18
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = add i64 %51, 2304
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = mul i64 %54, 32
  %56 = add i64 %52, %55
  %57 = inttoptr i64 %56 to ptr
  %58 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %57, i32 0, i32 0
  %59 = load volatile i32, ptr %58, align 4, !tbaa !15
  %60 = zext i32 %59 to i64
  %61 = or i64 %60, 2097152
  %62 = trunc i64 %61 to i32
  store volatile i32 %62, ptr %58, align 4, !tbaa !15
  br label %108

63:                                               ; preds = %2
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = add i64 %65, 2816
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  %69 = mul i64 %68, 32
  %70 = add i64 %66, %69
  %71 = inttoptr i64 %70 to ptr
  %72 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %71, i32 0, i32 0
  %73 = load volatile i32, ptr %72, align 4, !tbaa !17
  %74 = zext i32 %73 to i64
  %75 = and i64 %74, 2147483648
  %76 = icmp eq i64 %75, 0
  br i1 %76, label %77, label %94

77:                                               ; preds = %63
  %78 = load i32, ptr %6, align 4, !tbaa !9
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %94

80:                                               ; preds = %77
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = zext i32 %81 to i64
  %83 = add i64 %82, 2816
  %84 = load i32, ptr %6, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = mul i64 %85, 32
  %87 = add i64 %83, %86
  %88 = inttoptr i64 %87 to ptr
  %89 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %88, i32 0, i32 0
  %90 = load volatile i32, ptr %89, align 4, !tbaa !17
  %91 = zext i32 %90 to i64
  %92 = and i64 %91, -1073741825
  %93 = trunc i64 %92 to i32
  store volatile i32 %93, ptr %89, align 4, !tbaa !17
  br label %94

94:                                               ; preds = %80, %77, %63
  %95 = load i32, ptr %5, align 4, !tbaa !9
  %96 = zext i32 %95 to i64
  %97 = add i64 %96, 2816
  %98 = load i32, ptr %6, align 4, !tbaa !9
  %99 = zext i32 %98 to i64
  %100 = mul i64 %99, 32
  %101 = add i64 %97, %100
  %102 = inttoptr i64 %101 to ptr
  %103 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %102, i32 0, i32 0
  %104 = load volatile i32, ptr %103, align 4, !tbaa !17
  %105 = zext i32 %104 to i64
  %106 = or i64 %105, 2097152
  %107 = trunc i64 %106 to i32
  store volatile i32 %107, ptr %103, align 4, !tbaa !17
  br label %108

108:                                              ; preds = %94, %49
  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 = !{!18, !10, i64 0}
!18 = !{!"", !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_EPSetStall(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 = icmp ne i8 %4, 0
  br i1 %7, label %12, label %18

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 = icmp sgt i32 %16, -1
  %or.cond = select i1 %17, i1 %11, i1 false
  br i1 %or.cond, label %.sink.split, label %26

18:                                               ; preds = %2
  %19 = add nuw nsw i64 %8, 2816
  %20 = add nuw nsw i64 %19, %10
  %21 = inttoptr i64 %20 to ptr
  %22 = load volatile i32, ptr %21, align 4, !tbaa !15
  %23 = icmp sgt i32 %22, -1
  %or.cond3 = select i1 %23, i1 %11, i1 false
  br i1 %or.cond3, label %.sink.split, label %26

.sink.split:                                      ; preds = %18, %12
  %.sink24 = phi ptr [ %15, %12 ], [ %21, %18 ]
  %24 = load volatile i32, ptr %.sink24, align 4, !tbaa !17
  %25 = and i32 %24, -1073741825
  store volatile i32 %25, ptr %.sink24, align 4, !tbaa !17
  br label %26

26:                                               ; preds = %.sink.split, %18, %12
  %.sink = phi ptr [ %15, %12 ], [ %21, %18 ], [ %.sink24, %.sink.split ]
  %27 = load volatile i32, ptr %.sink, align 4, !tbaa !17
  %28 = or i32 %27, 2097152
  store volatile i32 %28, ptr %.sink, align 4, !tbaa !17
  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 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24}
!17 = !{!10, !10, i64 0}


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