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

; 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.ETH_HandleTypeDef = type { ptr, %struct.ETH_InitTypeDef, %struct.ETH_TxDescListTypeDef, %struct.ETH_RxDescListTypeDef, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.ETH_InitTypeDef = type { ptr, i32, ptr, ptr, i32 }
%struct.ETH_TxDescListTypeDef = type { [4 x i32], i32 }
%struct.ETH_RxDescListTypeDef = type { [4 x i32], i32, i32, i32, i32, i32 }
%struct.ETH_DMADescTypeDef = type { 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 @HAL_ETH_DescAssignMemory(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ETH_HandleTypeDef, ptr %12, i32 0, i32 3
  %14 = getelementptr inbounds %struct.ETH_RxDescListTypeDef, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = inttoptr i64 %19 to ptr
  store ptr %20, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %26, label %23

23:                                               ; preds = %4
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = icmp uge i32 %24, 4
  br i1 %25, label %26, label %29

26:                                               ; preds = %23, %4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ETH_HandleTypeDef, ptr %27, i32 0, i32 7
  store volatile i32 1, ptr %28, align 4, !tbaa !11
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %62

29:                                               ; preds = %23
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i32
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ETH_DMADescTypeDef, ptr %32, i32 0, i32 0
  store volatile i32 %31, ptr %33, align 4, !tbaa !16
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i32
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ETH_DMADescTypeDef, ptr %36, i32 0, i32 4
  store volatile i32 %35, ptr %37, align 4, !tbaa !18
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ETH_DMADescTypeDef, ptr %38, i32 0, i32 3
  %40 = load volatile i32, ptr %39, align 4, !tbaa !19
  %41 = or i32 %40, 16777216
  store volatile i32 %41, ptr %39, align 4, !tbaa !19
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %57

44:                                               ; preds = %29
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = ptrtoint ptr %45 to i32
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ETH_DMADescTypeDef, ptr %47, i32 0, i32 2
  store volatile i32 %46, ptr %48, align 4, !tbaa !20
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = ptrtoint ptr %49 to i32
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ETH_DMADescTypeDef, ptr %51, i32 0, i32 5
  store volatile i32 %50, ptr %52, align 4, !tbaa !21
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ETH_DMADescTypeDef, ptr %53, i32 0, i32 3
  %55 = load volatile i32, ptr %54, align 4, !tbaa !19
  %56 = or i32 %55, 33554432
  store volatile i32 %56, ptr %54, align 4, !tbaa !19
  br label %57

57:                                               ; preds = %44, %29
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ETH_DMADescTypeDef, ptr %58, i32 0, i32 3
  %60 = load volatile i32, ptr %59, align 4, !tbaa !19
  %61 = or i32 %60, -2147483648
  store volatile i32 %61, ptr %59, align 4, !tbaa !19
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %62

62:                                               ; preds = %57, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %63 = load i32, ptr %5, align 4
  ret i32 %63
}

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, !10, i64 116}
!12 = !{!"", !6, i64 0, !13, i64 8, !14, i64 48, !15, i64 68, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132}
!13 = !{!"", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!14 = !{!"", !7, i64 0, !10, i64 16}
!15 = !{!"", !7, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!18 = !{!17, !10, i64 16}
!19 = !{!17, !10, i64 12}
!20 = !{!17, !10, i64 8}
!21 = !{!17, !10, 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 range(i32 0, 2) i32 @HAL_ETH_DescAssignMemory(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 68
  %6 = zext i32 %1 to i64
  %7 = getelementptr inbounds [4 x i32], ptr %5, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = inttoptr i64 %9 to ptr
  %11 = icmp eq ptr %2, null
  %12 = icmp ugt i32 %1, 3
  %or.cond = or i1 %12, %11
  br i1 %or.cond, label %13, label %15

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %0, i64 116
  store volatile i32 1, ptr %14, align 4, !tbaa !9
  br label %32

15:                                               ; preds = %4
  %16 = ptrtoint ptr %2 to i64
  %17 = trunc i64 %16 to i32
  store volatile i32 %17, ptr %10, align 4, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %10, i64 16
  store volatile i32 %17, ptr %18, align 4, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %10, i64 12
  %20 = load volatile i32, ptr %19, align 4, !tbaa !18
  %21 = or i32 %20, 16777216
  store volatile i32 %21, ptr %19, align 4, !tbaa !18
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %29, label %22

22:                                               ; preds = %15
  %23 = ptrtoint ptr %3 to i64
  %24 = trunc i64 %23 to i32
  %25 = getelementptr inbounds i8, ptr %10, i64 8
  store volatile i32 %24, ptr %25, align 4, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %10, i64 20
  store volatile i32 %24, ptr %26, align 4, !tbaa !20
  %27 = load volatile i32, ptr %19, align 4, !tbaa !18
  %28 = or i32 %27, 33554432
  store volatile i32 %28, ptr %19, align 4, !tbaa !18
  br label %29

29:                                               ; preds = %22, %15
  %30 = load volatile i32, ptr %19, align 4, !tbaa !18
  %31 = or i32 %30, -2147483648
  store volatile i32 %31, ptr %19, align 4, !tbaa !18
  br label %32

32:                                               ; preds = %29, %13
  %.0 = phi i32 [ 1, %13 ], [ 0, %29 ]
  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 116}
!10 = !{!"", !11, i64 0, !12, i64 8, !13, i64 48, !14, i64 68, !6, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !6, i64 128, !6, i64 132}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !11, i64 0, !6, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!13 = !{!"", !7, i64 0, !6, i64 16}
!14 = !{!"", !7, i64 0, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!17 = !{!16, !6, i64 16}
!18 = !{!16, !6, i64 12}
!19 = !{!16, !6, i64 8}
!20 = !{!16, !6, i64 20}


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