; 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.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.USART_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_IRDA_DMAStop(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %4, i32 0, i32 12
  %6 = load volatile i32, ptr %5, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 33
  br i1 %7, label %8, label %50

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = getelementptr inbounds %struct.USART_TypeDef, ptr %11, i32 0, i32 2
  %13 = load volatile i32, ptr %12, align 4, !tbaa !15
  %14 = zext i32 %13 to i64
  %15 = and i64 %14, 128
  %16 = icmp eq i64 %15, 128
  br i1 %16, label %17, label %49

17:                                               ; preds = %8
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = getelementptr inbounds %struct.USART_TypeDef, ptr %20, i32 0, i32 2
  %22 = load volatile i32, ptr %21, align 4, !tbaa !15
  %23 = zext i32 %22 to i64
  %24 = and i64 %23, -129
  %25 = trunc i64 %24 to i32
  store volatile i32 %25, ptr %21, align 4, !tbaa !15
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %26, i32 0, i32 9
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %47

30:                                               ; preds = %17
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %31, i32 0, i32 9
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = call i32 @HAL_DMA_Abort(ptr noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %46

36:                                               ; preds = %30
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %37, i32 0, i32 9
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = call i32 @HAL_DMA_GetError(ptr noundef %39)
  %41 = icmp eq i32 %40, 32
  br i1 %41, label %42, label %45

42:                                               ; preds = %36
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %43, i32 0, i32 14
  store volatile i32 16, ptr %44, align 4, !tbaa !18
  store i32 3, ptr %2, align 4
  br label %98

45:                                               ; preds = %36
  br label %46

46:                                               ; preds = %45, %30
  br label %47

47:                                               ; preds = %46, %17
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  call void @IRDA_EndTxTransfer(ptr noundef %48)
  br label %49

49:                                               ; preds = %47, %8
  br label %50

50:                                               ; preds = %49, %1
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %51, i32 0, i32 13
  %53 = load volatile i32, ptr %52, align 8, !tbaa !19
  %54 = icmp eq i32 %53, 34
  br i1 %54, label %55, label %97

55:                                               ; preds = %50
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !14
  %59 = getelementptr inbounds %struct.USART_TypeDef, ptr %58, i32 0, i32 2
  %60 = load volatile i32, ptr %59, align 4, !tbaa !15
  %61 = zext i32 %60 to i64
  %62 = and i64 %61, 64
  %63 = icmp eq i64 %62, 64
  br i1 %63, label %64, label %96

64:                                               ; preds = %55
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !14
  %68 = getelementptr inbounds %struct.USART_TypeDef, ptr %67, i32 0, i32 2
  %69 = load volatile i32, ptr %68, align 4, !tbaa !15
  %70 = zext i32 %69 to i64
  %71 = and i64 %70, -65
  %72 = trunc i64 %71 to i32
  store volatile i32 %72, ptr %68, align 4, !tbaa !15
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %73, i32 0, i32 10
  %75 = load ptr, ptr %74, align 8, !tbaa !20
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %94

77:                                               ; preds = %64
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %78, i32 0, i32 10
  %80 = load ptr, ptr %79, align 8, !tbaa !20
  %81 = call i32 @HAL_DMA_Abort(ptr noundef %80)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %93

83:                                               ; preds = %77
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %84, i32 0, i32 10
  %86 = load ptr, ptr %85, align 8, !tbaa !20
  %87 = call i32 @HAL_DMA_GetError(ptr noundef %86)
  %88 = icmp eq i32 %87, 32
  br i1 %88, label %89, label %92

89:                                               ; preds = %83
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %90, i32 0, i32 14
  store volatile i32 16, ptr %91, align 4, !tbaa !18
  store i32 3, ptr %2, align 4
  br label %98

92:                                               ; preds = %83
  br label %93

93:                                               ; preds = %92, %77
  br label %94

94:                                               ; preds = %93, %64
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  call void @IRDA_EndRxTransfer(ptr noundef %95)
  br label %96

96:                                               ; preds = %94, %55
  br label %97

97:                                               ; preds = %96, %50
  store i32 0, ptr %2, align 4
  br label %98

98:                                               ; preds = %97, %89, %42
  %99 = load i32, ptr %2, align 4
  ret i32 %99
}

declare i32 @HAL_DMA_Abort(ptr noundef) #1

declare i32 @HAL_DMA_GetError(ptr noundef) #1

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

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


; 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_IRDA_DMAStop(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 84
  %3 = load volatile i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 33
  br i1 %4, label %5, label %24

5:                                                ; preds = %1
  %6 = load ptr, ptr %0, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load volatile i32, ptr %7, align 4, !tbaa !14
  %9 = and i32 %8, 128
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %24, label %10

10:                                               ; preds = %5
  %11 = load volatile i32, ptr %7, align 4, !tbaa !14
  %12 = and i32 %11, -129
  store volatile i32 %12, ptr %7, align 4, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %.not18 = icmp eq ptr %14, null
  br i1 %.not18, label %23, label %15

15:                                               ; preds = %10
  %16 = tail call i32 @HAL_DMA_Abort(ptr noundef nonnull %14) #2
  %.not19 = icmp eq i32 %16, 0
  br i1 %.not19, label %23, label %17

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

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %0, i64 92
  store volatile i32 16, ptr %22, align 4, !tbaa !17
  br label %47

23:                                               ; preds = %15, %17, %10
  tail call void @IRDA_EndTxTransfer(ptr noundef nonnull %0)
  br label %24

24:                                               ; preds = %5, %23, %1
  %25 = getelementptr inbounds i8, ptr %0, i64 88
  %26 = load volatile i32, ptr %25, align 8, !tbaa !18
  %27 = icmp eq i32 %26, 34
  br i1 %27, label %28, label %47

28:                                               ; preds = %24
  %29 = load ptr, ptr %0, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = load volatile i32, ptr %30, align 4, !tbaa !14
  %32 = and i32 %31, 64
  %.not20 = icmp eq i32 %32, 0
  br i1 %.not20, label %47, label %33

33:                                               ; preds = %28
  %34 = load volatile i32, ptr %30, align 4, !tbaa !14
  %35 = and i32 %34, -65
  store volatile i32 %35, ptr %30, align 4, !tbaa !14
  %36 = getelementptr inbounds i8, ptr %0, i64 72
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %.not21 = icmp eq ptr %37, null
  br i1 %.not21, label %46, label %38

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

40:                                               ; preds = %38
  %41 = load ptr, ptr %36, align 8, !tbaa !19
  %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 92
  store volatile i32 16, ptr %45, align 4, !tbaa !17
  br label %47

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

47:                                               ; preds = %24, %46, %28, %44, %21
  %.0 = phi i32 [ 3, %21 ], [ 3, %44 ], [ 0, %28 ], [ 0, %46 ], [ 0, %24 ]
  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 @IRDA_EndTxTransfer(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @IRDA_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 84}
!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, !7, i64 0}
!14 = !{!15, !11, i64 8}
!15 = !{!"", !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}
!16 = !{!6, !7, i64 64}
!17 = !{!6, !11, i64 92}
!18 = !{!6, !11, i64 88}
!19 = !{!6, !7, i64 72}


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