; 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_GlobalTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [39 x i32], i32, [15 x 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_EP0_OutStart(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = ptrtoint ptr %11 to i32
  store i32 %12, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %13, i32 0, i32 14
  %15 = getelementptr inbounds i32, ptr %14, i64 1
  %16 = load volatile i32, ptr %15, align 4, !tbaa !10
  store i32 %16, ptr %9, align 4, !tbaa !10
  %17 = load i32, ptr %9, align 4, !tbaa !10
  %18 = icmp ugt i32 %17, 1330917386
  br i1 %18, label %19, label %32

19:                                               ; preds = %3
  %20 = load i32, ptr %8, align 4, !tbaa !10
  %21 = zext i32 %20 to i64
  %22 = add i64 %21, 2816
  %23 = add i64 %22, 0
  %24 = inttoptr i64 %23 to ptr
  %25 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %24, i32 0, i32 0
  %26 = load volatile i32, ptr %25, align 4, !tbaa !12
  %27 = zext i32 %26 to i64
  %28 = and i64 %27, 2147483648
  %29 = icmp eq i64 %28, 2147483648
  br i1 %29, label %30, label %31

30:                                               ; preds = %19
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %90

31:                                               ; preds = %19
  br label %32

32:                                               ; preds = %31, %3
  %33 = load i32, ptr %8, align 4, !tbaa !10
  %34 = zext i32 %33 to i64
  %35 = add i64 %34, 2816
  %36 = add i64 %35, 0
  %37 = inttoptr i64 %36 to ptr
  %38 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %37, i32 0, i32 4
  store volatile i32 0, ptr %38, align 4, !tbaa !14
  %39 = load i32, ptr %8, align 4, !tbaa !10
  %40 = zext i32 %39 to i64
  %41 = add i64 %40, 2816
  %42 = add i64 %41, 0
  %43 = inttoptr i64 %42 to ptr
  %44 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %43, i32 0, i32 4
  %45 = load volatile i32, ptr %44, align 4, !tbaa !14
  %46 = zext i32 %45 to i64
  %47 = or i64 %46, 524288
  %48 = trunc i64 %47 to i32
  store volatile i32 %48, ptr %44, align 4, !tbaa !14
  %49 = load i32, ptr %8, align 4, !tbaa !10
  %50 = zext i32 %49 to i64
  %51 = add i64 %50, 2816
  %52 = add i64 %51, 0
  %53 = inttoptr i64 %52 to ptr
  %54 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %53, i32 0, i32 4
  %55 = load volatile i32, ptr %54, align 4, !tbaa !14
  %56 = or i32 %55, 24
  store volatile i32 %56, ptr %54, align 4, !tbaa !14
  %57 = load i32, ptr %8, align 4, !tbaa !10
  %58 = zext i32 %57 to i64
  %59 = add i64 %58, 2816
  %60 = add i64 %59, 0
  %61 = inttoptr i64 %60 to ptr
  %62 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %61, i32 0, i32 4
  %63 = load volatile i32, ptr %62, align 4, !tbaa !14
  %64 = zext i32 %63 to i64
  %65 = or i64 %64, 1610612736
  %66 = trunc i64 %65 to i32
  store volatile i32 %66, ptr %62, align 4, !tbaa !14
  %67 = load i8, ptr %6, align 1, !tbaa !9
  %68 = zext i8 %67 to i32
  %69 = icmp eq i32 %68, 1
  br i1 %69, label %70, label %89

70:                                               ; preds = %32
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = ptrtoint ptr %71 to i32
  %73 = load i32, ptr %8, align 4, !tbaa !10
  %74 = zext i32 %73 to i64
  %75 = add i64 %74, 2816
  %76 = add i64 %75, 0
  %77 = inttoptr i64 %76 to ptr
  %78 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %77, i32 0, i32 5
  store volatile i32 %72, ptr %78, align 4, !tbaa !15
  %79 = load i32, ptr %8, align 4, !tbaa !10
  %80 = zext i32 %79 to i64
  %81 = add i64 %80, 2816
  %82 = add i64 %81, 0
  %83 = inttoptr i64 %82 to ptr
  %84 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %83, i32 0, i32 0
  %85 = load volatile i32, ptr %84, align 4, !tbaa !12
  %86 = zext i32 %85 to i64
  %87 = or i64 %86, 2147516416
  %88 = trunc i64 %87 to i32
  store volatile i32 %88, ptr %84, align 4, !tbaa !12
  br label %89

89:                                               ; preds = %70, %32
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %90

90:                                               ; preds = %89, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %91 = load i32, ptr %4, align 4
  ret i32 %91
}

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 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !7, i64 24}
!14 = !{!13, !11, i64 16}
!15 = !{!13, !11, i64 20}


; 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_EP0_OutStart(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %0 to i64
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load volatile i32, ptr %5, align 4, !tbaa !5
  %7 = icmp ugt i32 %6, 1330917386
  %8 = and i64 %4, 4294967295
  %9 = add nuw nsw i64 %8, 2816
  %10 = inttoptr i64 %9 to ptr
  br i1 %7, label %11, label %._crit_edge

11:                                               ; preds = %3
  %12 = load volatile i32, ptr %10, align 4, !tbaa !9
  %.not = icmp sgt i32 %12, -1
  br i1 %.not, label %._crit_edge, label %27

._crit_edge:                                      ; preds = %3, %11
  %13 = getelementptr inbounds i8, ptr %10, i64 16
  store volatile i32 0, ptr %13, align 4, !tbaa !11
  %14 = load volatile i32, ptr %13, align 4, !tbaa !11
  %15 = or i32 %14, 524288
  store volatile i32 %15, ptr %13, align 4, !tbaa !11
  %16 = load volatile i32, ptr %13, align 4, !tbaa !11
  %17 = or i32 %16, 24
  store volatile i32 %17, ptr %13, align 4, !tbaa !11
  %18 = load volatile i32, ptr %13, align 4, !tbaa !11
  %19 = or i32 %18, 1610612736
  store volatile i32 %19, ptr %13, align 4, !tbaa !11
  %20 = icmp eq i8 %1, 1
  br i1 %20, label %21, label %27

21:                                               ; preds = %._crit_edge
  %22 = ptrtoint ptr %2 to i64
  %23 = trunc i64 %22 to i32
  %24 = getelementptr inbounds i8, ptr %10, i64 20
  store volatile i32 %23, ptr %24, align 4, !tbaa !12
  %25 = load volatile i32, ptr %10, align 4, !tbaa !9
  %26 = or i32 %25, -2147450880
  store volatile i32 %26, ptr %10, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %._crit_edge, %21, %11
  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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !7, i64 24}
!11 = !{!10, !6, i64 16}
!12 = !{!10, !6, i64 20}


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