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

; 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.__SMARTCARD_HandleTypeDef = type { ptr, %struct.SMARTCARD_InitTypeDef, %struct.SMARTCARD_AdvFeatureInitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, i16, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32 }
%struct.SMARTCARD_InitTypeDef = type { i32, i32, i32, i16, i16, i16, i16, i16, i16, i8, i8, i16, i32, i32, i8, i8, i32 }
%struct.SMARTCARD_AdvFeatureInitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i16 }
%struct.USART_TypeDef = type { i32, i32, i32, i32, 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

declare i32 @HAL_GetTick() #1

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

; 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_SMARTCARD_Receive(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, i32 noundef %3) #2 {
  %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 ptr, align 8
  %12 = 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 8, ptr %11) #3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %13, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %14, i32 0, i32 18
  %16 = load volatile i32, ptr %15, align 8, !tbaa !13
  %17 = icmp eq i32 %16, 32
  br i1 %17, label %18, label %86

18:                                               ; preds = %4
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %25, label %21

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

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

26:                                               ; preds = %21
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %28, i32 0, i32 16
  %30 = load i32, ptr %29, align 8, !tbaa !17
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  store i32 2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

33:                                               ; preds = %27
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %34, i32 0, i32 16
  store i32 1, ptr %35, align 8, !tbaa !17
  br label %36

36:                                               ; preds = %33
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %39, i32 0, i32 19
  store volatile i32 0, ptr %40, align 4, !tbaa !18
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %41, i32 0, i32 18
  store volatile i32 34, ptr %42, align 8, !tbaa !13
  %43 = call i32 @HAL_GetTick()
  store i32 %43, ptr %10, align 4, !tbaa !11
  %44 = load i16, ptr %8, align 2, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %45, i32 0, i32 7
  store i16 %44, ptr %46, align 8, !tbaa !19
  %47 = load i16, ptr %8, align 2, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %48, i32 0, i32 8
  store volatile i16 %47, ptr %49, align 2, !tbaa !20
  br label %50

50:                                               ; preds = %67, %38
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %51, i32 0, i32 8
  %53 = load volatile i16, ptr %52, align 2, !tbaa !20
  %54 = zext i16 %53 to i32
  %55 = icmp ugt i32 %54, 0
  br i1 %55, label %56, label %78

56:                                               ; preds = %50
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %57, i32 0, i32 8
  %59 = load volatile i16, ptr %58, align 2, !tbaa !20
  %60 = add i16 %59, -1
  store volatile i16 %60, ptr %58, align 2, !tbaa !20
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i32, ptr %10, align 4, !tbaa !11
  %63 = load i32, ptr %9, align 4, !tbaa !11
  %64 = call i32 @SMARTCARD_WaitOnFlagUntilTimeout(ptr noundef %61, i32 noundef 32, i32 noundef 0, i32 noundef %62, i32 noundef %63)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %56
  store i32 3, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

67:                                               ; preds = %56
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  %71 = getelementptr inbounds %struct.USART_TypeDef, ptr %70, i32 0, i32 9
  %72 = load volatile i32, ptr %71, align 4, !tbaa !22
  %73 = and i32 %72, 255
  %74 = trunc i32 %73 to i8
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 %74, ptr %75, align 1, !tbaa !24
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i32 1
  store ptr %77, ptr %11, align 8, !tbaa !5
  br label %50, !llvm.loop !25

78:                                               ; preds = %50
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %79, i32 0, i32 18
  store volatile i32 32, ptr %80, align 8, !tbaa !13
  br label %81

81:                                               ; preds = %78
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %82, i32 0, i32 16
  store i32 0, ptr %83, align 8, !tbaa !17
  br label %84

84:                                               ; preds = %81
  br label %85

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

86:                                               ; preds = %4
  store i32 2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

87:                                               ; preds = %86, %85, %66, %32, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %88 = load i32, ptr %5, align 4
  ret i32 %88
}

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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 168}
!14 = !{!"__SMARTCARD_HandleTypeDef", !6, i64 0, !15, i64 8, !16, i64 52, !6, i64 88, !10, i64 96, !10, i64 98, !6, i64 104, !10, i64 112, !10, i64 114, !10, i64 116, !10, i64 118, !12, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !10, i64 12, !10, i64 14, !10, i64 16, !10, i64 18, !10, i64 20, !10, i64 22, !7, i64 24, !7, i64 25, !10, i64 26, !12, i64 28, !12, i64 32, !7, i64 36, !7, i64 37, !12, i64 40}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !10, i64 32}
!17 = !{!14, !12, i64 160}
!18 = !{!14, !12, i64 172}
!19 = !{!14, !10, i64 112}
!20 = !{!14, !10, i64 114}
!21 = !{!14, !6, i64 0}
!22 = !{!23, !12, i64 36}
!23 = !{!"", !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}
!24 = !{!7, !7, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"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"

declare i32 @HAL_GetTick() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_SMARTCARD_Receive(ptr noundef %0, ptr noundef writeonly %1, i16 noundef zeroext %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 168
  %6 = load volatile i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 32
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %4
  %9 = icmp eq ptr %1, null
  %10 = icmp eq i16 %2, 0
  %or.cond = or i1 %9, %10
  br i1 %or.cond, label %.loopexit, label %11

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

15:                                               ; preds = %11
  store i32 1, ptr %12, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 172
  store volatile i32 0, ptr %16, align 4, !tbaa !15
  store volatile i32 34, ptr %5, align 8, !tbaa !5
  %17 = tail call i32 @HAL_GetTick() #2
  %18 = getelementptr inbounds i8, ptr %0, i64 112
  store i16 %2, ptr %18, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %0, i64 114
  store volatile i16 %2, ptr %19, align 2, !tbaa !17
  %20 = load volatile i16, ptr %19, align 2, !tbaa !17
  %.not27 = icmp eq i16 %20, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %24
  %.028 = phi ptr [ %29, %24 ], [ %1, %15 ]
  %21 = load volatile i16, ptr %19, align 2, !tbaa !17
  %22 = add i16 %21, -1
  store volatile i16 %22, ptr %19, align 2, !tbaa !17
  %23 = tail call i32 @SMARTCARD_WaitOnFlagUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %17, i32 noundef %3)
  %.not26 = icmp eq i32 %23, 0
  br i1 %.not26, label %24, label %.loopexit

24:                                               ; preds = %.lr.ph
  %25 = load ptr, ptr %0, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %25, i64 36
  %27 = load volatile i32, ptr %26, align 4, !tbaa !19
  %28 = trunc i32 %27 to i8
  store i8 %28, ptr %.028, align 1, !tbaa !21
  %29 = getelementptr inbounds i8, ptr %.028, i64 1
  %30 = load volatile i16, ptr %19, align 2, !tbaa !17
  %.not = icmp eq i16 %30, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %24, %15
  store volatile i32 32, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %12, align 8, !tbaa !14
  br label %.loopexit

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

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, !11, i64 168}
!6 = !{!"__SMARTCARD_HandleTypeDef", !7, i64 0, !10, i64 8, !13, i64 52, !7, i64 88, !12, i64 96, !12, i64 98, !7, i64 104, !12, i64 112, !12, i64 114, !12, i64 116, !12, i64 118, !11, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172}
!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, !12, i64 12, !12, i64 14, !12, i64 16, !12, i64 18, !12, i64 20, !12, i64 22, !8, i64 24, !8, i64 25, !12, i64 26, !11, i64 28, !11, i64 32, !8, i64 36, !8, i64 37, !11, i64 40}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !12, i64 32}
!14 = !{!6, !11, i64 160}
!15 = !{!6, !11, i64 172}
!16 = !{!6, !12, i64 112}
!17 = !{!6, !12, i64 114}
!18 = !{!6, !7, i64 0}
!19 = !{!20, !11, i64 36}
!20 = !{!"", !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}
!21 = !{!8, !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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