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

; 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_TypeDef = type { i32, i32, i32, i32, i32, i32, [14 x i32], i32, i32, i32, i32, i32, i32, [2 x i32], i32, [7 x i32], i32, [7 x i32], i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, [12 x i32], i32, i32, i32, i32, i32, i32, [54 x i32], i32, i32, [2 x i32], i32, [59 x i32], i32, i32, i32, i32, i32, i32, i32, i32, [248 x i32], i32, i32, i32, i32, i32, [14 x i32], i32, i32, [5 x i32], i32, [10 x i32], i32, i32, [10 x i32], i32, [9 x i32], i32, i32, i32, i32, [65 x i32], i32, i32, [2 x i32], i32, i32, i32, i32, [4 x i32], i32, i32, [2 x i32], i32, i32, i32, i32, [108 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, [4 x i32], i32, [3 x i32], i32, i32, i32, i32, [12 x i32], i32, i32, i32, i32, i32, [11 x i32], i32, [7 x i32], i32, [55 x i32], i32, i32, i32, [8 x i32], i32, i32, i32, i32, [177 x i32], i32, i32, i32, i32, [60 x i32], i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x 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

declare i32 @HAL_GetTick() #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_ETH_ReadPHYRegister(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ETH_HandleTypeDef, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.ETH_TypeDef, ptr %15, i32 0, i32 37
  %17 = load volatile i32, ptr %16, align 4, !tbaa !16
  %18 = zext i32 %17 to i64
  %19 = and i64 %18, 1
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %84

22:                                               ; preds = %4
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ETH_HandleTypeDef, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.ETH_TypeDef, ptr %25, i32 0, i32 37
  %27 = load volatile i32, ptr %26, align 4, !tbaa !16
  store i32 %27, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = and i64 %29, -65011713
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = shl i32 %31, 21
  %33 = zext i32 %32 to i64
  %34 = or i64 %30, %33
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %10, align 4, !tbaa !9
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = and i64 %37, -2031617
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = shl i32 %39, 16
  %41 = zext i32 %40 to i64
  %42 = or i64 %38, %41
  %43 = trunc i64 %42 to i32
  store i32 %43, ptr %10, align 4, !tbaa !9
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = and i64 %45, -13
  %47 = or i64 %46, 12
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = or i64 %50, 1
  %52 = trunc i64 %51 to i32
  store i32 %52, ptr %10, align 4, !tbaa !9
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ETH_HandleTypeDef, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = getelementptr inbounds %struct.ETH_TypeDef, ptr %56, i32 0, i32 37
  store volatile i32 %53, ptr %57, align 4, !tbaa !16
  %58 = call i32 @HAL_GetTick()
  store i32 %58, ptr %11, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %74, %22
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ETH_HandleTypeDef, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = getelementptr inbounds %struct.ETH_TypeDef, ptr %62, i32 0, i32 37
  %64 = load volatile i32, ptr %63, align 4, !tbaa !16
  %65 = zext i32 %64 to i64
  %66 = and i64 %65, 1
  %67 = icmp ugt i64 %66, 0
  br i1 %67, label %68, label %75

68:                                               ; preds = %59
  %69 = call i32 @HAL_GetTick()
  %70 = load i32, ptr %11, align 4, !tbaa !9
  %71 = sub i32 %69, %70
  %72 = icmp ugt i32 %71, 1000
  br i1 %72, label %73, label %74

73:                                               ; preds = %68
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %84

74:                                               ; preds = %68
  br label %59, !llvm.loop !18

75:                                               ; preds = %59
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.ETH_HandleTypeDef, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !11
  %79 = getelementptr inbounds %struct.ETH_TypeDef, ptr %78, i32 0, i32 38
  %80 = load volatile i32, ptr %79, align 4, !tbaa !20
  %81 = trunc i32 %80 to i16
  %82 = zext i16 %81 to i32
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %82, ptr %83, align 4, !tbaa !9
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %84

84:                                               ; preds = %75, %73, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %85 = load i32, ptr %5, align 4
  ret i32 %85
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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, !6, i64 0}
!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 512}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !7, i64 104, !10, i64 112, !7, i64 116, !10, i64 144, !7, i64 148, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !10, i64 196, !7, i64 200, !10, i64 208, !10, i64 212, !10, i64 216, !10, i64 220, !7, i64 224, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !10, i64 288, !10, i64 292, !7, i64 296, !10, i64 512, !10, i64 516, !7, i64 520, !10, i64 528, !7, i64 532, !10, i64 768, !10, i64 772, !10, i64 776, !10, i64 780, !10, i64 784, !10, i64 788, !10, i64 792, !10, i64 796, !7, i64 800, !10, i64 1792, !10, i64 1796, !10, i64 1800, !10, i64 1804, !10, i64 1808, !7, i64 1812, !10, i64 1868, !10, i64 1872, !7, i64 1876, !10, i64 1896, !7, i64 1900, !10, i64 1940, !10, i64 1944, !7, i64 1948, !10, i64 1988, !7, i64 1992, !10, i64 2028, !10, i64 2032, !10, i64 2036, !10, i64 2040, !7, i64 2044, !10, i64 2304, !10, i64 2308, !7, i64 2312, !10, i64 2320, !10, i64 2324, !10, i64 2328, !10, i64 2332, !7, i64 2336, !10, i64 2352, !10, i64 2356, !7, i64 2360, !10, i64 2368, !10, i64 2372, !10, i64 2376, !10, i64 2380, !7, i64 2384, !10, i64 2816, !10, i64 2820, !10, i64 2824, !10, i64 2828, !10, i64 2832, !10, i64 2836, !10, i64 2840, !10, i64 2844, !10, i64 2848, !7, i64 2852, !10, i64 2864, !10, i64 2868, !7, i64 2872, !10, i64 2880, !10, i64 2884, !10, i64 2888, !10, i64 2892, !10, i64 2896, !10, i64 2900, !10, i64 2904, !10, i64 2908, !7, i64 2912, !10, i64 2928, !7, i64 2932, !10, i64 2944, !10, i64 2948, !10, i64 2952, !10, i64 2956, !7, i64 2960, !10, i64 3008, !10, i64 3012, !10, i64 3016, !10, i64 3020, !10, i64 3024, !7, i64 3028, !10, i64 3072, !7, i64 3076, !10, i64 3104, !7, i64 3108, !10, i64 3328, !10, i64 3332, !10, i64 3336, !7, i64 3340, !10, i64 3372, !10, i64 3376, !10, i64 3380, !10, i64 3384, !7, i64 3388, !10, i64 4096, !10, i64 4100, !10, i64 4104, !10, i64 4108, !7, i64 4112, !10, i64 4352, !10, i64 4356, !10, i64 4360, !7, i64 4364, !10, i64 4372, !10, i64 4376, !10, i64 4380, !10, i64 4384, !10, i64 4388, !10, i64 4392, !10, i64 4396, !10, i64 4400, !10, i64 4404, !10, i64 4408, !10, i64 4412, !10, i64 4416, !10, i64 4420, !10, i64 4424, !10, i64 4428, !10, i64 4432, !10, i64 4436, !10, i64 4440, !10, i64 4444, !10, i64 4448, !7, i64 4452, !10, i64 4460}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!17, !10, i64 516}


; 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"

declare i32 @HAL_GetTick() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_ETH_ReadPHYRegister(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 512
  %7 = load volatile i32, ptr %6, align 4, !tbaa !14
  %8 = and i32 %7, 1
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.loopexit

9:                                                ; preds = %4
  %10 = load volatile i32, ptr %6, align 4, !tbaa !14
  %11 = and i32 %10, -67043342
  %12 = shl i32 %1, 21
  %13 = shl i32 %2, 16
  %14 = or i32 %12, %13
  %15 = or i32 %14, %11
  %16 = or disjoint i32 %15, 13
  store volatile i32 %16, ptr %6, align 4, !tbaa !14
  %17 = tail call i32 @HAL_GetTick() #2
  br label %18

18:                                               ; preds = %23, %9
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 512
  %21 = load volatile i32, ptr %20, align 4, !tbaa !14
  %22 = and i32 %21, 1
  %.not14 = icmp eq i32 %22, 0
  br i1 %.not14, label %27, label %23

23:                                               ; preds = %18
  %24 = tail call i32 @HAL_GetTick() #2
  %25 = sub i32 %24, %17
  %26 = icmp ugt i32 %25, 1000
  br i1 %26, label %.loopexit, label %18, !llvm.loop !16

27:                                               ; preds = %18
  %28 = getelementptr inbounds i8, ptr %19, i64 516
  %29 = load volatile i32, ptr %28, align 4, !tbaa !18
  %30 = and i32 %29, 65535
  store i32 %30, ptr %3, align 4, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %23, %4, %27
  %.0 = phi i32 [ 0, %27 ], [ 1, %4 ], [ 1, %23 ]
  ret i32 %.0
}

attributes #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 #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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !12, i64 48, !13, i64 68, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !11, i64 32}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !8, i64 0, !11, i64 16}
!13 = !{!"", !8, i64 0, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32}
!14 = !{!15, !11, i64 512}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !8, i64 24, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !8, i64 104, !11, i64 112, !8, i64 116, !11, i64 144, !8, i64 148, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !8, i64 200, !11, i64 208, !11, i64 212, !11, i64 216, !11, i64 220, !8, i64 224, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !11, i64 288, !11, i64 292, !8, i64 296, !11, i64 512, !11, i64 516, !8, i64 520, !11, i64 528, !8, i64 532, !11, i64 768, !11, i64 772, !11, i64 776, !11, i64 780, !11, i64 784, !11, i64 788, !11, i64 792, !11, i64 796, !8, i64 800, !11, i64 1792, !11, i64 1796, !11, i64 1800, !11, i64 1804, !11, i64 1808, !8, i64 1812, !11, i64 1868, !11, i64 1872, !8, i64 1876, !11, i64 1896, !8, i64 1900, !11, i64 1940, !11, i64 1944, !8, i64 1948, !11, i64 1988, !8, i64 1992, !11, i64 2028, !11, i64 2032, !11, i64 2036, !11, i64 2040, !8, i64 2044, !11, i64 2304, !11, i64 2308, !8, i64 2312, !11, i64 2320, !11, i64 2324, !11, i64 2328, !11, i64 2332, !8, i64 2336, !11, i64 2352, !11, i64 2356, !8, i64 2360, !11, i64 2368, !11, i64 2372, !11, i64 2376, !11, i64 2380, !8, i64 2384, !11, i64 2816, !11, i64 2820, !11, i64 2824, !11, i64 2828, !11, i64 2832, !11, i64 2836, !11, i64 2840, !11, i64 2844, !11, i64 2848, !8, i64 2852, !11, i64 2864, !11, i64 2868, !8, i64 2872, !11, i64 2880, !11, i64 2884, !11, i64 2888, !11, i64 2892, !11, i64 2896, !11, i64 2900, !11, i64 2904, !11, i64 2908, !8, i64 2912, !11, i64 2928, !8, i64 2932, !11, i64 2944, !11, i64 2948, !11, i64 2952, !11, i64 2956, !8, i64 2960, !11, i64 3008, !11, i64 3012, !11, i64 3016, !11, i64 3020, !11, i64 3024, !8, i64 3028, !11, i64 3072, !8, i64 3076, !11, i64 3104, !8, i64 3108, !11, i64 3328, !11, i64 3332, !11, i64 3336, !8, i64 3340, !11, i64 3372, !11, i64 3376, !11, i64 3380, !11, i64 3384, !8, i64 3388, !11, i64 4096, !11, i64 4100, !11, i64 4104, !11, i64 4108, !8, i64 4112, !11, i64 4352, !11, i64 4356, !11, i64 4360, !8, i64 4364, !11, i64 4372, !11, i64 4376, !11, i64 4380, !11, i64 4384, !11, i64 4388, !11, i64 4392, !11, i64 4396, !11, i64 4400, !11, i64 4404, !11, i64 4408, !11, i64 4412, !11, i64 4416, !11, i64 4420, !11, i64 4424, !11, i64 4428, !11, i64 4432, !11, i64 4436, !11, i64 4440, !11, i64 4444, !11, i64 4448, !8, i64 4452, !11, i64 4460}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!15, !11, i64 516}
!19 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass