; 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.IRDA_HandleTypeDef = type { ptr, %struct.IRDA_InitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, ptr, ptr, i32, i32, i32, i32 }
%struct.IRDA_InitTypeDef = type { i32, i32, i32, i32, i8, i16, 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 @IRDA_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_IRDA_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.IRDA_HandleTypeDef, ptr %8, i32 0, i32 13
  %10 = load volatile i32, ptr %9, align 8, !tbaa !11
  %11 = icmp eq i32 %10, 32
  br i1 %11, label %12, label %112

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 %113

20:                                               ; preds = %15
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %22, i32 0, i32 11
  %24 = load i32, ptr %23, align 8, !tbaa !15
  %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 %113

27:                                               ; preds = %21
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %28, i32 0, i32 11
  store i32 1, ptr %29, align 8, !tbaa !15
  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.IRDA_HandleTypeDef, ptr %33, i32 0, i32 5
  store ptr %32, ptr %34, align 8, !tbaa !16
  %35 = load i16, ptr %7, align 2, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %36, i32 0, i32 6
  store i16 %35, ptr %37, align 8, !tbaa !17
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %38, i32 0, i32 14
  store volatile i32 0, ptr %39, align 4, !tbaa !18
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %40, i32 0, i32 13
  store volatile i32 34, ptr %41, align 8, !tbaa !11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %42, i32 0, i32 10
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %44, i32 0, i32 5
  store ptr @IRDA_DMAReceiveCplt, ptr %45, align 8, !tbaa !20
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %46, i32 0, i32 10
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %48, i32 0, i32 6
  store ptr @IRDA_DMAReceiveHalfCplt, ptr %49, align 8, !tbaa !23
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %50, i32 0, i32 10
  %52 = load ptr, ptr %51, align 8, !tbaa !19
  %53 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %52, i32 0, i32 9
  store ptr @IRDA_DMAError, ptr %53, align 8, !tbaa !24
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %54, i32 0, i32 10
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %56, i32 0, i32 10
  store ptr null, ptr %57, align 8, !tbaa !25
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %58, i32 0, i32 10
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !26
  %64 = getelementptr inbounds %struct.USART_TypeDef, ptr %63, i32 0, i32 9
  %65 = ptrtoint ptr %64 to i32
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %66, i32 0, i32 5
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = ptrtoint ptr %68 to i32
  %70 = load i16, ptr %7, align 2, !tbaa !9
  %71 = zext i16 %70 to i32
  %72 = call i32 @HAL_DMA_Start_IT(ptr noundef %60, i32 noundef %65, i32 noundef %69, i32 noundef %71)
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %103

74:                                               ; preds = %31
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %76, i32 0, i32 11
  store i32 0, ptr %77, align 8, !tbaa !15
  br label %78

78:                                               ; preds = %75
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !26
  %82 = getelementptr inbounds %struct.USART_TypeDef, ptr %81, i32 0, i32 0
  %83 = load volatile i32, ptr %82, align 4, !tbaa !27
  %84 = zext i32 %83 to i64
  %85 = or i64 %84, 256
  %86 = trunc i64 %85 to i32
  store volatile i32 %86, ptr %82, align 4, !tbaa !27
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !26
  %90 = getelementptr inbounds %struct.USART_TypeDef, ptr %89, i32 0, i32 2
  %91 = load volatile i32, ptr %90, align 4, !tbaa !28
  %92 = zext i32 %91 to i64
  %93 = or i64 %92, 1
  %94 = trunc i64 %93 to i32
  store volatile i32 %94, ptr %90, align 4, !tbaa !28
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !26
  %98 = getelementptr inbounds %struct.USART_TypeDef, ptr %97, i32 0, i32 2
  %99 = load volatile i32, ptr %98, align 4, !tbaa !28
  %100 = zext i32 %99 to i64
  %101 = or i64 %100, 64
  %102 = trunc i64 %101 to i32
  store volatile i32 %102, ptr %98, align 4, !tbaa !28
  store i32 0, ptr %4, align 4
  br label %113

103:                                              ; preds = %31
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %104, i32 0, i32 14
  store volatile i32 16, ptr %105, align 4, !tbaa !18
  br label %106

106:                                              ; preds = %103
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %107, i32 0, i32 11
  store i32 0, ptr %108, align 8, !tbaa !15
  br label %109

109:                                              ; preds = %106
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %110, i32 0, i32 13
  store volatile i32 32, ptr %111, align 8, !tbaa !11
  store i32 1, ptr %4, align 4
  br label %113

112:                                              ; preds = %3
  store i32 2, ptr %4, align 4
  br label %113

113:                                              ; preds = %112, %109, %78, %26, %19
  %114 = load i32, ptr %4, align 4
  ret i32 %114
}

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

; Function Attrs: nounwind uwtable
declare hidden void @IRDA_DMAReceiveHalfCplt(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 88}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 32, !10, i64 40, !10, i64 42, !6, i64 48, !10, i64 56, !10, i64 58, !10, i64 60, !6, i64 64, !6, i64 72, !14, i64 80, !14, i64 84, !14, i64 88, !14, i64 92}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !7, i64 16, !10, i64 18, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 80}
!16 = !{!12, !6, i64 48}
!17 = !{!12, !10, i64 56}
!18 = !{!12, !14, i64 92}
!19 = !{!12, !6, i64 72}
!20 = !{!21, !6, i64 72}
!21 = !{!"__DMA_HandleTypeDef", !6, i64 0, !22, 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}
!22 = !{!"", !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}
!23 = !{!21, !6, i64 80}
!24 = !{!21, !6, i64 104}
!25 = !{!21, !6, i64 112}
!26 = !{!12, !6, i64 0}
!27 = !{!22, !14, i64 0}
!28 = !{!22, !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 @IRDA_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_IRDA_Receive_DMA(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 88
  %5 = load volatile i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 32
  br i1 %6, label %7, label %43

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

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %43, 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 92
  store volatile i32 0, ptr %18, align 4, !tbaa !16
  store volatile i32 34, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 72
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %20, i64 72
  store ptr @IRDA_DMAReceiveCplt, ptr %21, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %20, i64 80
  store ptr @IRDA_DMAReceiveHalfCplt, ptr %22, align 8, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %20, i64 104
  store ptr @IRDA_DMAError, ptr %23, align 8, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %20, i64 112
  store ptr null, ptr %24, align 8, !tbaa !23
  %25 = load ptr, ptr %0, align 8, !tbaa !24
  %26 = getelementptr inbounds i8, ptr %25, i64 36
  %27 = ptrtoint ptr %26 to i64
  %28 = trunc i64 %27 to i32
  %29 = ptrtoint ptr %1 to i64
  %30 = trunc i64 %29 to i32
  %31 = tail call i32 @HAL_DMA_Start_IT(ptr noundef %20, i32 noundef %28, i32 noundef %30, i32 noundef %9) #2
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %42

33:                                               ; preds = %15
  store i32 0, ptr %12, align 8, !tbaa !13
  %34 = load ptr, ptr %0, align 8, !tbaa !24
  %35 = load volatile i32, ptr %34, align 4, !tbaa !25
  %36 = or i32 %35, 256
  store volatile i32 %36, ptr %34, align 4, !tbaa !25
  %37 = getelementptr inbounds i8, ptr %34, i64 8
  %38 = load volatile i32, ptr %37, align 4, !tbaa !26
  %39 = or i32 %38, 1
  store volatile i32 %39, ptr %37, align 4, !tbaa !26
  %40 = load volatile i32, ptr %37, align 4, !tbaa !26
  %41 = or i32 %40, 64
  store volatile i32 %41, ptr %37, align 4, !tbaa !26
  br label %43

42:                                               ; preds = %15
  store volatile i32 16, ptr %18, align 4, !tbaa !16
  store i32 0, ptr %12, align 8, !tbaa !13
  store volatile i32 32, ptr %4, align 8, !tbaa !5
  br label %43

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

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

; Function Attrs: nounwind uwtable
declare hidden void @IRDA_DMAReceiveHalfCplt(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 88}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 32, !12, i64 40, !12, i64 42, !7, i64 48, !12, i64 56, !12, i64 58, !12, i64 60, !7, i64 64, !7, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92}
!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, !8, i64 16, !12, i64 18, !11, i64 20}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !11, i64 80}
!14 = !{!6, !7, i64 48}
!15 = !{!6, !12, i64 56}
!16 = !{!6, !11, i64 92}
!17 = !{!6, !7, i64 72}
!18 = !{!19, !7, i64 72}
!19 = !{!"__DMA_HandleTypeDef", !7, i64 0, !20, 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}
!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 = !{!19, !7, i64 80}
!22 = !{!19, !7, i64 104}
!23 = !{!19, !7, i64 112}
!24 = !{!6, !7, i64 0}
!25 = !{!20, !11, i64 0}
!26 = !{!20, !11, i64 8}


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