; 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.__USART_HandleTypeDef = type { ptr, %struct.USART_InitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, i16, i16, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32 }
%struct.USART_InitTypeDef = type { 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: 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_USART_Transmit_DMA(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %11, i32 0, i32 18
  %13 = load volatile i32, ptr %12, align 4, !tbaa !13
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %110

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %22, label %18

18:                                               ; preds = %15
  %19 = load i16, ptr %7, 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, %15
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %111

23:                                               ; preds = %18
  br label %24

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

29:                                               ; preds = %24
  store i32 2, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %111

30:                                               ; preds = %24
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %31, i32 0, i32 17
  store i32 1, ptr %32, align 8, !tbaa !16
  br label %33

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %37, i32 0, i32 2
  store ptr %36, ptr %38, align 8, !tbaa !17
  %39 = load i16, ptr %7, align 2, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %40, i32 0, i32 3
  store i16 %39, ptr %41, align 8, !tbaa !18
  %42 = load i16, ptr %7, align 2, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %43, i32 0, i32 4
  store volatile i16 %42, ptr %44, align 2, !tbaa !19
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %45, i32 0, i32 19
  store volatile i32 0, ptr %46, align 8, !tbaa !20
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %47, i32 0, i32 18
  store volatile i32 18, ptr %48, align 4, !tbaa !13
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %49, i32 0, i32 15
  %51 = load ptr, ptr %50, align 8, !tbaa !21
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %79

53:                                               ; preds = %35
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %54, i32 0, i32 15
  %56 = load ptr, ptr %55, align 8, !tbaa !21
  %57 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %56, i32 0, i32 5
  store ptr @USART_DMATransmitCplt, ptr %57, align 8, !tbaa !22
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %58, i32 0, i32 15
  %60 = load ptr, ptr %59, align 8, !tbaa !21
  %61 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %60, i32 0, i32 6
  store ptr @USART_DMATxHalfCplt, ptr %61, align 8, !tbaa !25
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %62, i32 0, i32 15
  %64 = load ptr, ptr %63, align 8, !tbaa !21
  %65 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %64, i32 0, i32 9
  store ptr @USART_DMAError, ptr %65, align 8, !tbaa !26
  store ptr %6, ptr %9, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %66, i32 0, i32 15
  %68 = load ptr, ptr %67, align 8, !tbaa !21
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !27
  %74 = getelementptr inbounds %struct.USART_TypeDef, ptr %73, i32 0, i32 10
  %75 = ptrtoint ptr %74 to i32
  %76 = load i16, ptr %7, align 2, !tbaa !9
  %77 = zext i16 %76 to i32
  %78 = call i32 @HAL_DMA_Start_IT(ptr noundef %68, i32 noundef %70, i32 noundef %75, i32 noundef %77)
  store i32 %78, ptr %8, align 4, !tbaa !11
  br label %79

79:                                               ; preds = %53, %35
  %80 = load i32, ptr %8, align 4, !tbaa !11
  %81 = icmp eq i32 %80, 0
  br i1 %81, label %82, label %100

82:                                               ; preds = %79
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !27
  %86 = getelementptr inbounds %struct.USART_TypeDef, ptr %85, i32 0, i32 8
  store volatile i32 64, ptr %86, align 4, !tbaa !28
  br label %87

87:                                               ; preds = %82
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %88, i32 0, i32 17
  store i32 0, ptr %89, align 8, !tbaa !16
  br label %90

90:                                               ; preds = %87
  br label %91

91:                                               ; preds = %90
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !27
  %95 = getelementptr inbounds %struct.USART_TypeDef, ptr %94, i32 0, i32 2
  %96 = load volatile i32, ptr %95, align 4, !tbaa !29
  %97 = zext i32 %96 to i64
  %98 = or i64 %97, 128
  %99 = trunc i64 %98 to i32
  store volatile i32 %99, ptr %95, align 4, !tbaa !29
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %111

100:                                              ; preds = %79
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %101, i32 0, i32 19
  store volatile i32 16, ptr %102, align 8, !tbaa !20
  br label %103

103:                                              ; preds = %100
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %104, i32 0, i32 17
  store i32 0, ptr %105, align 8, !tbaa !16
  br label %106

106:                                              ; preds = %103
  br label %107

107:                                              ; preds = %106
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.__USART_HandleTypeDef, ptr %108, i32 0, i32 18
  store volatile i32 1, ptr %109, align 4, !tbaa !13
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %111

110:                                              ; preds = %3
  store i32 2, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %111

111:                                              ; preds = %110, %107, %91, %29, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %112 = load i32, ptr %4, align 4
  ret i32 %112
}

; Function Attrs: nounwind uwtable
declare hidden void @USART_DMATransmitCplt(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @USART_DMATxHalfCplt(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @USART_DMAError(ptr noundef) #1

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

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 132}
!14 = !{!"__USART_HandleTypeDef", !6, i64 0, !15, i64 8, !6, i64 48, !10, i64 56, !10, i64 58, !6, i64 64, !10, i64 72, !10, i64 74, !10, i64 76, !10, i64 78, !10, i64 80, !12, i64 84, !12, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !12, i64 128, !12, i64 132, !12, i64 136}
!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}
!16 = !{!14, !12, i64 128}
!17 = !{!14, !6, i64 48}
!18 = !{!14, !10, i64 56}
!19 = !{!14, !10, i64 58}
!20 = !{!14, !12, i64 136}
!21 = !{!14, !6, i64 112}
!22 = !{!23, !6, i64 72}
!23 = !{!"__DMA_HandleTypeDef", !6, i64 0, !24, i64 8, !12, i64 56, !12, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !12, i64 120, !12, i64 124, !12, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !6, i64 160, !6, i64 168, !12, i64 176}
!24 = !{!"", !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}
!25 = !{!23, !6, i64 80}
!26 = !{!23, !6, i64 104}
!27 = !{!14, !6, i64 0}
!28 = !{!24, !12, i64 32}
!29 = !{!24, !12, 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
define dso_local range(i32 0, 3) i32 @HAL_USART_Transmit_DMA(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 132
  %5 = load volatile i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %39

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 %39, label %11

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

15:                                               ; preds = %11
  store i32 1, ptr %12, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %1, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %0, i64 56
  store i16 %2, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %0, i64 58
  store volatile i16 %2, ptr %18, align 2, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %0, i64 136
  store volatile i32 0, ptr %19, align 8, !tbaa !17
  store volatile i32 18, ptr %4, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 112
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %.critedge, label %22

22:                                               ; preds = %15
  %23 = getelementptr inbounds i8, ptr %21, i64 72
  store ptr @USART_DMATransmitCplt, ptr %23, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %21, i64 80
  store ptr @USART_DMATxHalfCplt, ptr %24, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %21, i64 104
  store ptr @USART_DMAError, ptr %25, align 8, !tbaa !23
  %26 = ptrtoint ptr %1 to i64
  %.0.extract.trunc = trunc i64 %26 to i32
  %27 = load ptr, ptr %0, align 8, !tbaa !24
  %28 = getelementptr inbounds i8, ptr %27, i64 40
  %29 = ptrtoint ptr %28 to i64
  %30 = trunc i64 %29 to i32
  %31 = tail call i32 @HAL_DMA_Start_IT(ptr noundef nonnull %21, i32 noundef %.0.extract.trunc, i32 noundef %30, i32 noundef %9) #2
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %.critedge, label %38

.critedge:                                        ; preds = %15, %22
  %33 = load ptr, ptr %0, align 8, !tbaa !24
  %34 = getelementptr inbounds i8, ptr %33, i64 32
  store volatile i32 64, ptr %34, align 4, !tbaa !25
  store i32 0, ptr %12, align 8, !tbaa !13
  %35 = getelementptr inbounds i8, ptr %33, i64 8
  %36 = load volatile i32, ptr %35, align 4, !tbaa !26
  %37 = or i32 %36, 128
  store volatile i32 %37, ptr %35, align 4, !tbaa !26
  br label %39

38:                                               ; preds = %22
  store volatile i32 16, ptr %19, align 8, !tbaa !17
  store i32 0, ptr %12, align 8, !tbaa !13
  store volatile i32 1, ptr %4, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %3, %11, %7, %38, %.critedge
  %.0 = phi i32 [ 0, %.critedge ], [ 1, %38 ], [ 1, %7 ], [ 2, %11 ], [ 2, %3 ]
  ret i32 %.0
}

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

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

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

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

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 132}
!6 = !{!"__USART_HandleTypeDef", !7, i64 0, !10, i64 8, !7, i64 48, !12, i64 56, !12, i64 58, !7, i64 64, !12, i64 72, !12, i64 74, !12, i64 76, !12, i64 78, !12, i64 80, !11, i64 84, !11, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !11, i64 132, !11, i64 136}
!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 = !{!"short", !8, i64 0}
!13 = !{!6, !11, i64 128}
!14 = !{!6, !7, i64 48}
!15 = !{!6, !12, i64 56}
!16 = !{!6, !12, i64 58}
!17 = !{!6, !11, i64 136}
!18 = !{!6, !7, i64 112}
!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 = !{!6, !7, i64 0}
!25 = !{!21, !11, i64 32}
!26 = !{!21, !11, i64 8}


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