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

; 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.__UART_HandleTypeDef = type { ptr, %struct.UART_InitTypeDef, %struct.UART_AdvFeatureInitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, i32, i16, i16, ptr, ptr, ptr, ptr, i32, i32, i32, i32 }
%struct.UART_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.UART_AdvFeatureInitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.__DMA_HandleTypeDef = type { ptr, %struct.DMA_InitTypeDef, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, ptr, i32 }
%struct.DMA_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USART_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare hidden void @UART_DMAError(ptr noundef) #0

declare i32 @HAL_DMA_Start_IT(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_UART_Receive_DMA(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i16 %2, ptr %7, align 2, !tbaa !9
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %8, i32 0, i32 19
  %10 = load volatile i32, ptr %9, align 8, !tbaa !11
  %11 = icmp eq i32 %10, 32
  br i1 %11, label %12, label %118

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = load i16, ptr %7, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %12
  store i32 1, ptr %4, align 4
  br label %119

20:                                               ; preds = %15
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %22, i32 0, i32 17
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 2, ptr %4, align 4
  br label %119

27:                                               ; preds = %21
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %28, i32 0, i32 17
  store i32 1, ptr %29, align 8, !tbaa !16
  br label %30

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %33, i32 0, i32 6
  store ptr %32, ptr %34, align 8, !tbaa !17
  %35 = load i16, ptr %7, align 2, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %36, i32 0, i32 7
  store i16 %35, ptr %37, align 8, !tbaa !18
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %38, i32 0, i32 20
  store volatile i32 0, ptr %39, align 4, !tbaa !19
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %40, i32 0, i32 19
  store volatile i32 34, ptr %41, align 8, !tbaa !11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %42, i32 0, i32 16
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %89

46:                                               ; preds = %31
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %47, i32 0, i32 16
  %49 = load ptr, ptr %48, align 8, !tbaa !20
  %50 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %49, i32 0, i32 5
  store ptr @UART_DMAReceiveCplt, ptr %50, align 8, !tbaa !21
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %51, i32 0, i32 16
  %53 = load ptr, ptr %52, align 8, !tbaa !20
  %54 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %53, i32 0, i32 6
  store ptr @UART_DMARxHalfCplt, ptr %54, align 8, !tbaa !24
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %55, i32 0, i32 16
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  %58 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %57, i32 0, i32 9
  store ptr @UART_DMAError, ptr %58, align 8, !tbaa !25
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %59, i32 0, i32 16
  %61 = load ptr, ptr %60, align 8, !tbaa !20
  %62 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %61, i32 0, i32 10
  store ptr null, ptr %62, align 8, !tbaa !26
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %63, i32 0, i32 16
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !27
  %69 = getelementptr inbounds %struct.USART_TypeDef, ptr %68, i32 0, i32 9
  %70 = ptrtoint ptr %69 to i32
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %71, i32 0, i32 6
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  %74 = ptrtoint ptr %73 to i32
  %75 = load i16, ptr %7, align 2, !tbaa !9
  %76 = zext i16 %75 to i32
  %77 = call i32 @HAL_DMA_Start_IT(ptr noundef %65, i32 noundef %70, i32 noundef %74, i32 noundef %76)
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %88

79:                                               ; preds = %46
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %80, i32 0, i32 20
  store volatile i32 16, ptr %81, align 4, !tbaa !19
  br label %82

82:                                               ; preds = %79
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %83, i32 0, i32 17
  store i32 0, ptr %84, align 8, !tbaa !16
  br label %85

85:                                               ; preds = %82
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %86, i32 0, i32 18
  store volatile i32 32, ptr %87, align 4, !tbaa !28
  store i32 1, ptr %4, align 4
  br label %119

88:                                               ; preds = %46
  br label %89

89:                                               ; preds = %88, %31
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %91, i32 0, i32 17
  store i32 0, ptr %92, align 8, !tbaa !16
  br label %93

93:                                               ; preds = %90
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !27
  %97 = getelementptr inbounds %struct.USART_TypeDef, ptr %96, i32 0, i32 0
  %98 = load volatile i32, ptr %97, align 4, !tbaa !29
  %99 = zext i32 %98 to i64
  %100 = or i64 %99, 256
  %101 = trunc i64 %100 to i32
  store volatile i32 %101, ptr %97, align 4, !tbaa !29
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %102, i32 0, i32 0
  %104 = load ptr, ptr %103, align 8, !tbaa !27
  %105 = getelementptr inbounds %struct.USART_TypeDef, ptr %104, i32 0, i32 2
  %106 = load volatile i32, ptr %105, align 4, !tbaa !30
  %107 = zext i32 %106 to i64
  %108 = or i64 %107, 1
  %109 = trunc i64 %108 to i32
  store volatile i32 %109, ptr %105, align 4, !tbaa !30
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %110, i32 0, i32 0
  %112 = load ptr, ptr %111, align 8, !tbaa !27
  %113 = getelementptr inbounds %struct.USART_TypeDef, ptr %112, i32 0, i32 2
  %114 = load volatile i32, ptr %113, align 4, !tbaa !30
  %115 = zext i32 %114 to i64
  %116 = or i64 %115, 64
  %117 = trunc i64 %116 to i32
  store volatile i32 %117, ptr %113, align 4, !tbaa !30
  store i32 0, ptr %4, align 4
  br label %119

118:                                              ; preds = %3
  store i32 2, ptr %4, align 4
  br label %119

119:                                              ; preds = %118, %93, %85, %26, %19
  %120 = load i32, ptr %4, align 4
  ret i32 %120
}

; Function Attrs: nounwind uwtable
declare hidden void @UART_DMAReceiveCplt(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @UART_DMARxHalfCplt(ptr noundef) #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" }

!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, !14, i64 168}
!12 = !{!"__UART_HandleTypeDef", !6, i64 0, !13, i64 8, !15, i64 44, !6, i64 88, !10, i64 96, !10, i64 98, !6, i64 104, !10, i64 112, !10, i64 114, !10, i64 116, !14, i64 120, !10, i64 124, !10, i64 126, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !14, i64 160, !14, i64 164, !14, i64 168, !14, i64 172}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36}
!16 = !{!12, !14, i64 160}
!17 = !{!12, !6, i64 104}
!18 = !{!12, !10, i64 112}
!19 = !{!12, !14, i64 172}
!20 = !{!12, !6, i64 152}
!21 = !{!22, !6, i64 72}
!22 = !{!"__DMA_HandleTypeDef", !6, i64 0, !23, i64 8, !14, i64 56, !14, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !14, i64 120, !14, i64 124, !14, i64 128, !6, i64 136, !6, i64 144, !14, i64 152, !6, i64 160, !6, i64 168, !14, i64 176}
!23 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44}
!24 = !{!22, !6, i64 80}
!25 = !{!22, !6, i64 104}
!26 = !{!22, !6, i64 112}
!27 = !{!12, !6, i64 0}
!28 = !{!12, !14, i64 164}
!29 = !{!23, !14, i64 0}
!30 = !{!23, !14, i64 8}


; 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
declare hidden void @UART_DMAError(ptr noundef) #0

declare i32 @HAL_DMA_Start_IT(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

7:                                                ; preds = %3
  %8 = icmp eq ptr %1, null
  %9 = zext i16 %2 to i32
  %10 = icmp eq i16 %2, 0
  %or.cond = or i1 %8, %10
  br i1 %or.cond, label %44, label %11

11:                                               ; preds = %7
  %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 %44, label %15

15:                                               ; preds = %11
  store i32 1, ptr %12, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %1, ptr %16, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %0, i64 112
  store i16 %2, ptr %17, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %0, i64 172
  store volatile i32 0, ptr %18, align 4, !tbaa !17
  store volatile i32 34, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 152
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %35, label %21

21:                                               ; preds = %15
  %22 = getelementptr inbounds i8, ptr %20, i64 72
  store ptr @UART_DMAReceiveCplt, ptr %22, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %20, i64 80
  store ptr @UART_DMARxHalfCplt, ptr %23, align 8, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %20, i64 104
  store ptr @UART_DMAError, ptr %24, align 8, !tbaa !23
  %25 = getelementptr inbounds i8, ptr %20, i64 112
  store ptr null, ptr %25, align 8, !tbaa !24
  %26 = load ptr, ptr %0, align 8, !tbaa !25
  %27 = getelementptr inbounds i8, ptr %26, i64 36
  %28 = ptrtoint ptr %27 to i64
  %29 = trunc i64 %28 to i32
  %30 = ptrtoint ptr %1 to i64
  %31 = trunc i64 %30 to i32
  %32 = tail call i32 @HAL_DMA_Start_IT(ptr noundef nonnull %20, i32 noundef %29, i32 noundef %31, i32 noundef %9) #2
  %.not32 = icmp eq i32 %32, 0
  br i1 %.not32, label %35, label %33

33:                                               ; preds = %21
  store volatile i32 16, ptr %18, align 4, !tbaa !17
  store i32 0, ptr %12, align 8, !tbaa !14
  %34 = getelementptr inbounds i8, ptr %0, i64 164
  store volatile i32 32, ptr %34, align 4, !tbaa !26
  br label %44

35:                                               ; preds = %15, %21
  store i32 0, ptr %12, align 8, !tbaa !14
  %36 = load ptr, ptr %0, align 8, !tbaa !25
  %37 = load volatile i32, ptr %36, align 4, !tbaa !27
  %38 = or i32 %37, 256
  store volatile i32 %38, ptr %36, align 4, !tbaa !27
  %39 = getelementptr inbounds i8, ptr %36, i64 8
  %40 = load volatile i32, ptr %39, align 4, !tbaa !28
  %41 = or i32 %40, 1
  store volatile i32 %41, ptr %39, align 4, !tbaa !28
  %42 = load volatile i32, ptr %39, align 4, !tbaa !28
  %43 = or i32 %42, 64
  store volatile i32 %43, ptr %39, align 4, !tbaa !28
  br label %44

44:                                               ; preds = %3, %11, %7, %35, %33
  %.0 = phi i32 [ 1, %33 ], [ 0, %35 ], [ 1, %7 ], [ 2, %11 ], [ 2, %3 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @UART_DMAReceiveCplt(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @UART_DMARxHalfCplt(ptr noundef) #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 168}
!6 = !{!"__UART_HandleTypeDef", !7, i64 0, !10, i64 8, !12, i64 44, !7, i64 88, !13, i64 96, !13, i64 98, !7, i64 104, !13, i64 112, !13, i64 114, !13, i64 116, !11, i64 120, !13, i64 124, !13, i64 126, !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, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !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}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !11, i64 160}
!15 = !{!6, !7, i64 104}
!16 = !{!6, !13, i64 112}
!17 = !{!6, !11, i64 172}
!18 = !{!6, !7, i64 152}
!19 = !{!20, !7, i64 72}
!20 = !{!"__DMA_HandleTypeDef", !7, i64 0, !21, i64 8, !11, i64 56, !11, i64 60, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !11, i64 120, !11, i64 124, !11, i64 128, !7, i64 136, !7, i64 144, !11, i64 152, !7, i64 160, !7, i64 168, !11, i64 176}
!21 = !{!"", !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}
!22 = !{!20, !7, i64 80}
!23 = !{!20, !7, i64 104}
!24 = !{!20, !7, i64 112}
!25 = !{!6, !7, i64 0}
!26 = !{!6, !11, i64 164}
!27 = !{!21, !11, i64 0}
!28 = !{!21, !11, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass