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

; 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.SPDIFRX_HandleTypeDef = type { ptr, %struct.SPDIFRX_InitTypeDef, ptr, ptr, i16, i16, i16, i16, ptr, ptr, i32, i32, i32 }
%struct.SPDIFRX_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.SPDIFRX_TypeDef = type { i32, i32, 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_SPDIFRX_ReceiveDataFlow(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i16, align 2
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i16 %2, ptr %8, align 2, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %14 = load i16, ptr %8, align 2, !tbaa !9
  store i16 %14, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %15, ptr %12, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %22, label %18

18:                                               ; preds = %4
  %19 = load i16, ptr %8, align 2, !tbaa !9
  %20 = zext i16 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %4
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

23:                                               ; preds = %18
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %24, i32 0, i32 11
  %26 = load volatile i32, ptr %25, align 4, !tbaa !13
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %94

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %30, i32 0, i32 10
  %32 = load volatile i32, ptr %31, align 8, !tbaa !16
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store i32 2, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

35:                                               ; preds = %29
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %36, i32 0, i32 10
  store volatile i32 1, ptr %37, align 8, !tbaa !16
  br label %38

38:                                               ; preds = %35
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %41, i32 0, i32 11
  store volatile i32 2, ptr %42, align 4, !tbaa !13
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = getelementptr inbounds %struct.SPDIFRX_TypeDef, ptr %45, i32 0, i32 0
  %47 = load volatile i32, ptr %46, align 4, !tbaa !18
  %48 = or i32 %47, 1
  store volatile i32 %48, ptr %46, align 4, !tbaa !18
  %49 = call i32 @HAL_GetTick()
  store i32 %49, ptr %10, align 4, !tbaa !11
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !11
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = call i32 @SPDIFRX_WaitOnFlagUntilTimeout(ptr noundef %50, i32 noundef 32, i32 noundef 0, i32 noundef %51, i32 noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %40
  store i32 3, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

56:                                               ; preds = %40
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !17
  %60 = getelementptr inbounds %struct.SPDIFRX_TypeDef, ptr %59, i32 0, i32 0
  %61 = load volatile i32, ptr %60, align 4, !tbaa !18
  %62 = or i32 %61, 3
  store volatile i32 %62, ptr %60, align 4, !tbaa !18
  br label %63

63:                                               ; preds = %75, %56
  %64 = load i16, ptr %11, align 2, !tbaa !9
  %65 = zext i16 %64 to i32
  %66 = icmp ugt i32 %65, 0
  br i1 %66, label %67, label %86

67:                                               ; preds = %63
  %68 = call i32 @HAL_GetTick()
  store i32 %68, ptr %10, align 4, !tbaa !11
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !11
  %71 = load i32, ptr %10, align 4, !tbaa !11
  %72 = call i32 @SPDIFRX_WaitOnFlagUntilTimeout(ptr noundef %69, i32 noundef 1, i32 noundef 0, i32 noundef %70, i32 noundef %71)
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %67
  store i32 3, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

75:                                               ; preds = %67
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !17
  %79 = getelementptr inbounds %struct.SPDIFRX_TypeDef, ptr %78, i32 0, i32 4
  %80 = load volatile i32, ptr %79, align 4, !tbaa !20
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 %80, ptr %81, align 4, !tbaa !11
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = getelementptr inbounds i32, ptr %82, i32 1
  store ptr %83, ptr %12, align 8, !tbaa !5
  %84 = load i16, ptr %11, align 2, !tbaa !9
  %85 = add i16 %84, -1
  store i16 %85, ptr %11, align 2, !tbaa !9
  br label %63, !llvm.loop !21

86:                                               ; preds = %63
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %87, i32 0, i32 11
  store volatile i32 1, ptr %88, align 4, !tbaa !13
  br label %89

89:                                               ; preds = %86
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %90, i32 0, i32 10
  store volatile i32 0, ptr %91, align 8, !tbaa !16
  br label %92

92:                                               ; preds = %89
  br label %93

93:                                               ; preds = %92
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

94:                                               ; preds = %23
  store i32 2, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

95:                                               ; preds = %94, %93, %74, %55, %34, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %96 = load i32, ptr %5, align 4
  ret i32 %96
}

declare i32 @HAL_GetTick() #2

; Function Attrs: nounwind uwtable
declare hidden i32 @SPDIFRX_WaitOnFlagUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

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 = { "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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 100}
!14 = !{!"", !6, i64 0, !15, i64 8, !6, i64 56, !6, i64 64, !10, i64 72, !10, i64 74, !10, i64 76, !10, i64 78, !6, i64 80, !6, i64 88, !12, i64 96, !12, i64 100, !12, i64 104}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!16 = !{!14, !12, i64 96}
!17 = !{!14, !6, i64 0}
!18 = !{!19, !12, i64 0}
!19 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!20 = !{!19, !12, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_SPDIFRX_ReceiveDataFlow(ptr noundef %0, ptr noundef writeonly %1, i16 noundef zeroext %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %1, null
  %6 = icmp eq i16 %2, 0
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %.loopexit, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 100
  %9 = load volatile i32, ptr %8, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %.loopexit

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 96
  %13 = load volatile i32, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %11
  store volatile i32 1, ptr %12, align 8, !tbaa !13
  store volatile i32 2, ptr %8, align 4, !tbaa !5
  %16 = load ptr, ptr %0, align 8, !tbaa !14
  %17 = load volatile i32, ptr %16, align 4, !tbaa !15
  %18 = or i32 %17, 1
  store volatile i32 %18, ptr %16, align 4, !tbaa !15
  %19 = tail call i32 @HAL_GetTick() #2
  %20 = tail call i32 @SPDIFRX_WaitOnFlagUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %3, i32 noundef %19)
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %15
  %21 = load ptr, ptr %0, align 8, !tbaa !14
  %22 = load volatile i32, ptr %21, align 4, !tbaa !15
  %23 = or i32 %22, 3
  store volatile i32 %23, ptr %21, align 4, !tbaa !15
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %26
  %.032 = phi ptr [ %30, %26 ], [ %1, %.lr.ph.preheader ]
  %.02531 = phi i16 [ %31, %26 ], [ %2, %.lr.ph.preheader ]
  %24 = tail call i32 @HAL_GetTick() #2
  %25 = tail call i32 @SPDIFRX_WaitOnFlagUntilTimeout(ptr noundef nonnull %0, i32 noundef 1, i32 noundef 0, i32 noundef %3, i32 noundef %24)
  %.not29 = icmp eq i32 %25, 0
  br i1 %.not29, label %26, label %.loopexit

26:                                               ; preds = %.lr.ph
  %27 = load ptr, ptr %0, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %29 = load volatile i32, ptr %28, align 4, !tbaa !17
  store i32 %29, ptr %.032, align 4, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %.032, i64 4
  %31 = add i16 %.02531, -1
  %.not28 = icmp eq i16 %31, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %26
  store volatile i32 1, ptr %8, align 4, !tbaa !5
  store volatile i32 0, ptr %12, align 8, !tbaa !13
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %7, %15, %11, %4, %._crit_edge
  %.026 = phi i32 [ 0, %._crit_edge ], [ 1, %4 ], [ 2, %11 ], [ 3, %15 ], [ 2, %7 ], [ 3, %.lr.ph ]
  ret i32 %.026
}

declare i32 @HAL_GetTick() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @SPDIFRX_WaitOnFlagUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

attributes #0 = { 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 #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 }

!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, !11, i64 100}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 56, !7, i64 64, !12, i64 72, !12, i64 74, !12, i64 76, !12, i64 78, !7, i64 80, !7, i64 88, !11, i64 96, !11, i64 100, !11, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !11, i64 96}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!17 = !{!16, !11, i64 16}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass