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

; 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 }
%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 }

declare i32 @HAL_DMA_Abort(ptr noundef) #0

declare i32 @HAL_DMA_GetError(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_IRDA_AbortTransmit(ptr noundef %0) #1 {
  %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 0
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.USART_TypeDef, ptr %6, i32 0, i32 0
  %8 = load volatile i32, ptr %7, align 4, !tbaa !14
  %9 = zext i32 %8 to i64
  %10 = and i64 %9, -193
  %11 = trunc i64 %10 to i32
  store volatile i32 %11, ptr %7, align 4, !tbaa !14
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.USART_TypeDef, ptr %14, i32 0, i32 2
  %16 = load volatile i32, ptr %15, align 4, !tbaa !16
  %17 = zext i32 %16 to i64
  %18 = and i64 %17, 128
  %19 = icmp eq i64 %18, 128
  br i1 %19, label %20, label %55

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

33:                                               ; preds = %20
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %34, i32 0, i32 9
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %36, i32 0, i32 10
  store ptr null, ptr %37, align 8, !tbaa !18
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %38, i32 0, i32 9
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = call i32 @HAL_DMA_Abort(ptr noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %33
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %44, i32 0, i32 9
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %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.IRDA_HandleTypeDef, ptr %50, i32 0, i32 14
  store volatile i32 16, ptr %51, align 4, !tbaa !20
  store i32 3, ptr %2, align 4
  br label %60

52:                                               ; preds = %43
  br label %53

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

54:                                               ; preds = %53, %20
  br label %55

55:                                               ; preds = %54, %1
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %56, i32 0, i32 4
  store volatile i16 0, ptr %57, align 2, !tbaa !21
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %58, i32 0, i32 12
  store volatile i32 32, ptr %59, align 4, !tbaa !22
  store i32 0, ptr %2, align 4
  br label %60

60:                                               ; preds = %55, %49
  %61 = load i32, ptr %2, align 4
  ret i32 %61
}

attributes #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 = { 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" }

!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, !6, i64 0}
!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 = !{!15, !12, i64 0}
!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, !12, i64 36, !12, i64 40, !12, i64 44}
!16 = !{!15, !12, i64 8}
!17 = !{!10, !6, i64 64}
!18 = !{!19, !6, i64 112}
!19 = !{!"__DMA_HandleTypeDef", !6, i64 0, !15, 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}
!20 = !{!10, !12, i64 92}
!21 = !{!10, !13, i64 42}
!22 = !{!10, !12, i64 84}


; 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"

declare i32 @HAL_DMA_Abort(ptr noundef) local_unnamed_addr #0

declare i32 @HAL_DMA_GetError(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_IRDA_AbortTransmit(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = load volatile i32, ptr %2, align 4, !tbaa !13
  %4 = and i32 %3, -193
  store volatile i32 %4, ptr %2, align 4, !tbaa !13
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  %6 = load volatile i32, ptr %5, align 4, !tbaa !15
  %7 = and i32 %6, 128
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %20, label %8

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

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %12, i64 112
  store ptr null, ptr %14, align 8, !tbaa !17
  %15 = tail call i32 @HAL_DMA_Abort(ptr noundef nonnull %12) #2
  %.not12 = icmp eq i32 %15, 0
  br i1 %.not12, label %20, label %16

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

20:                                               ; preds = %8, %16, %13, %1
  %21 = getelementptr inbounds i8, ptr %0, i64 42
  store volatile i16 0, ptr %21, align 2, !tbaa !19
  br label %22

22:                                               ; preds = %16, %20
  %.sink14 = phi i64 [ 84, %20 ], [ 92, %16 ]
  %.sink = phi i32 [ 32, %20 ], [ 16, %16 ]
  %.0 = phi i32 [ 0, %20 ], [ 3, %16 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 %.sink14
  store volatile i32 %.sink, ptr %23, align 4, !tbaa !20
  ret i32 %.0
}

attributes #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 = { 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 = { 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, !7, i64 0}
!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 = !{!14, !11, i64 0}
!14 = !{!"", !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}
!15 = !{!14, !11, i64 8}
!16 = !{!6, !7, i64 64}
!17 = !{!18, !7, i64 112}
!18 = !{!"__DMA_HandleTypeDef", !7, i64 0, !14, 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}
!19 = !{!6, !12, i64 42}
!20 = !{!11, !11, i64 0}


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