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

; 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.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_UART_DMAStop(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %7, i32 0, i32 18
  %9 = load volatile i32, ptr %8, align 4, !tbaa !9
  store i32 %9, ptr %4, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %10, i32 0, i32 19
  %12 = load volatile i32, ptr %11, align 8, !tbaa !16
  store i32 %12, ptr %5, align 4, !tbaa !15
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds %struct.USART_TypeDef, ptr %15, i32 0, i32 2
  %17 = load volatile i32, ptr %16, align 4, !tbaa !18
  %18 = zext i32 %17 to i64
  %19 = and i64 %18, 128
  %20 = icmp eq i64 %19, 128
  br i1 %20, label %21, label %56

21:                                               ; preds = %1
  %22 = load i32, ptr %4, align 4, !tbaa !15
  %23 = icmp eq i32 %22, 33
  br i1 %23, label %24, label %56

24:                                               ; preds = %21
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds %struct.USART_TypeDef, ptr %27, i32 0, i32 2
  %29 = load volatile i32, ptr %28, align 4, !tbaa !18
  %30 = zext i32 %29 to i64
  %31 = and i64 %30, -129
  %32 = trunc i64 %31 to i32
  store volatile i32 %32, ptr %28, align 4, !tbaa !18
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %33, i32 0, i32 15
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %54

37:                                               ; preds = %24
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %38, i32 0, i32 15
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = call i32 @HAL_DMA_Abort(ptr noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %37
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %44, i32 0, i32 15
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  %47 = call i32 @HAL_DMA_GetError(ptr noundef %46)
  %48 = icmp eq i32 %47, 32
  br i1 %48, label %49, label %52

49:                                               ; preds = %43
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %50, i32 0, i32 20
  store volatile i32 16, ptr %51, align 4, !tbaa !21
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %101

52:                                               ; preds = %43
  br label %53

53:                                               ; preds = %52, %37
  br label %54

54:                                               ; preds = %53, %24
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  call void @UART_EndTxTransfer(ptr noundef %55)
  br label %56

56:                                               ; preds = %54, %21, %1
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !17
  %60 = getelementptr inbounds %struct.USART_TypeDef, ptr %59, i32 0, i32 2
  %61 = load volatile i32, ptr %60, align 4, !tbaa !18
  %62 = zext i32 %61 to i64
  %63 = and i64 %62, 64
  %64 = icmp eq i64 %63, 64
  br i1 %64, label %65, label %100

65:                                               ; preds = %56
  %66 = load i32, ptr %5, align 4, !tbaa !15
  %67 = icmp eq i32 %66, 34
  br i1 %67, label %68, label %100

68:                                               ; preds = %65
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = getelementptr inbounds %struct.USART_TypeDef, ptr %71, i32 0, i32 2
  %73 = load volatile i32, ptr %72, align 4, !tbaa !18
  %74 = zext i32 %73 to i64
  %75 = and i64 %74, -65
  %76 = trunc i64 %75 to i32
  store volatile i32 %76, ptr %72, align 4, !tbaa !18
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %77, i32 0, i32 16
  %79 = load ptr, ptr %78, align 8, !tbaa !22
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %98

81:                                               ; preds = %68
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %82, i32 0, i32 16
  %84 = load ptr, ptr %83, align 8, !tbaa !22
  %85 = call i32 @HAL_DMA_Abort(ptr noundef %84)
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %97

87:                                               ; preds = %81
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %88, i32 0, i32 16
  %90 = load ptr, ptr %89, align 8, !tbaa !22
  %91 = call i32 @HAL_DMA_GetError(ptr noundef %90)
  %92 = icmp eq i32 %91, 32
  br i1 %92, label %93, label %96

93:                                               ; preds = %87
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %94, i32 0, i32 20
  store volatile i32 16, ptr %95, align 4, !tbaa !21
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %101

96:                                               ; preds = %87
  br label %97

97:                                               ; preds = %96, %81
  br label %98

98:                                               ; preds = %97, %68
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  call void @UART_EndRxTransfer(ptr noundef %99)
  br label %100

100:                                              ; preds = %98, %65, %56
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %101

101:                                              ; preds = %100, %93, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %102 = load i32, ptr %2, align 4
  ret i32 %102
}

declare i32 @HAL_DMA_Abort(ptr noundef) #2

declare i32 @HAL_DMA_GetError(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @UART_EndRxTransfer(ptr 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, !12, i64 164}
!10 = !{!"__UART_HandleTypeDef", !6, i64 0, !11, i64 8, !13, i64 44, !6, i64 88, !14, i64 96, !14, i64 98, !6, i64 104, !14, i64 112, !14, i64 114, !14, i64 116, !12, i64 120, !14, i64 124, !14, i64 126, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172}
!11 = !{!"", !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 = !{!"int", !7, i64 0}
!13 = !{!"", !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}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 168}
!17 = !{!10, !6, i64 0}
!18 = !{!19, !12, i64 8}
!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, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!20 = !{!10, !6, i64 144}
!21 = !{!10, !12, i64 172}
!22 = !{!10, !6, i64 152}


; 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_UART_DMAStop(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 164
  %3 = load volatile i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 168
  %5 = load volatile i32, ptr %4, align 8, !tbaa !14
  %6 = load ptr, ptr %0, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load volatile i32, ptr %7, align 4, !tbaa !16
  %9 = and i32 %8, 128
  %10 = icmp ne i32 %9, 0
  %11 = icmp eq i32 %3, 33
  %or.cond = select i1 %10, i1 %11, i1 false
  br i1 %or.cond, label %12, label %26

12:                                               ; preds = %1
  %13 = load volatile i32, ptr %7, align 4, !tbaa !16
  %14 = and i32 %13, -129
  store volatile i32 %14, ptr %7, align 4, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 144
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %25, label %17

17:                                               ; preds = %12
  %18 = tail call i32 @HAL_DMA_Abort(ptr noundef nonnull %16) #2
  %.not23 = icmp eq i32 %18, 0
  br i1 %.not23, label %25, label %19

19:                                               ; preds = %17
  %20 = load ptr, ptr %15, align 8, !tbaa !18
  %21 = tail call i32 @HAL_DMA_GetError(ptr noundef %20) #2
  %22 = icmp eq i32 %21, 32
  br i1 %22, label %23, label %25

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %0, i64 172
  store volatile i32 16, ptr %24, align 4, !tbaa !19
  br label %47

25:                                               ; preds = %17, %19, %12
  tail call void @UART_EndTxTransfer(ptr noundef nonnull %0)
  %.pre = load ptr, ptr %0, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %25, %1
  %27 = phi ptr [ %.pre, %25 ], [ %6, %1 ]
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load volatile i32, ptr %28, align 4, !tbaa !16
  %30 = and i32 %29, 64
  %31 = icmp ne i32 %30, 0
  %32 = icmp eq i32 %5, 34
  %or.cond3 = select i1 %31, i1 %32, i1 false
  br i1 %or.cond3, label %33, label %47

33:                                               ; preds = %26
  %34 = load volatile i32, ptr %28, align 4, !tbaa !16
  %35 = and i32 %34, -65
  store volatile i32 %35, ptr %28, align 4, !tbaa !16
  %36 = getelementptr inbounds i8, ptr %0, i64 152
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  %.not24 = icmp eq ptr %37, null
  br i1 %.not24, label %46, label %38

38:                                               ; preds = %33
  %39 = tail call i32 @HAL_DMA_Abort(ptr noundef nonnull %37) #2
  %.not25 = icmp eq i32 %39, 0
  br i1 %.not25, label %46, label %40

40:                                               ; preds = %38
  %41 = load ptr, ptr %36, align 8, !tbaa !20
  %42 = tail call i32 @HAL_DMA_GetError(ptr noundef %41) #2
  %43 = icmp eq i32 %42, 32
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = getelementptr inbounds i8, ptr %0, i64 172
  store volatile i32 16, ptr %45, align 4, !tbaa !19
  br label %47

46:                                               ; preds = %38, %40, %33
  tail call void @UART_EndRxTransfer(ptr noundef nonnull %0)
  br label %47

47:                                               ; preds = %26, %46, %44, %23
  %.0 = phi i32 [ 3, %23 ], [ 3, %44 ], [ 0, %46 ], [ 0, %26 ]
  ret i32 %.0
}

declare i32 @HAL_DMA_Abort(ptr noundef) local_unnamed_addr #1

declare i32 @HAL_DMA_GetError(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden void @UART_EndRxTransfer(ptr 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 164}
!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 168}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !11, i64 8}
!17 = !{!"", !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}
!18 = !{!6, !7, i64 144}
!19 = !{!6, !11, i64 172}
!20 = !{!6, !7, i64 152}


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