; 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.__I2S_HandleTypeDef = type { ptr, %struct.I2S_InitTypeDef, ptr, i16, i16, ptr, i16, i16, ptr, ptr, ptr, ptr, i32, i32, i32 }
%struct.I2S_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.SPI_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, [3 x 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_I2S_DMAStop(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %4, i32 0, i32 0
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds %struct.SPI_TypeDef, ptr %6, i32 0, i32 2
  %8 = load volatile i32, ptr %7, align 4, !tbaa !15
  %9 = zext i32 %8 to i64
  %10 = and i64 %9, -32769
  %11 = trunc i64 %10 to i32
  store volatile i32 %11, ptr %7, align 4, !tbaa !15
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.SPI_TypeDef, ptr %14, i32 0, i32 2
  %16 = load volatile i32, ptr %15, align 4, !tbaa !15
  %17 = zext i32 %16 to i64
  %18 = and i64 %17, -16385
  %19 = trunc i64 %18 to i32
  store volatile i32 %19, ptr %15, align 4, !tbaa !15
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %20, i32 0, i32 10
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %38

24:                                               ; preds = %1
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %25, i32 0, i32 10
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = call i32 @HAL_DMA_Abort(ptr noundef %27)
  %29 = icmp ne i32 0, %28
  br i1 %29, label %30, label %37

30:                                               ; preds = %24
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %31, i32 0, i32 14
  %33 = load volatile i32, ptr %32, align 8, !tbaa !18
  %34 = zext i32 %33 to i64
  %35 = or i64 %34, 8
  %36 = trunc i64 %35 to i32
  store volatile i32 %36, ptr %32, align 8, !tbaa !18
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %30, %24
  br label %38

38:                                               ; preds = %37, %1
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %39, i32 0, i32 11
  %41 = load ptr, ptr %40, align 8, !tbaa !19
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %57

43:                                               ; preds = %38
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %44, i32 0, i32 11
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  %47 = call i32 @HAL_DMA_Abort(ptr noundef %46)
  %48 = icmp ne i32 0, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %43
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %50, i32 0, i32 14
  %52 = load volatile i32, ptr %51, align 8, !tbaa !18
  %53 = zext i32 %52 to i64
  %54 = or i64 %53, 8
  %55 = trunc i64 %54 to i32
  store volatile i32 %55, ptr %51, align 8, !tbaa !18
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %49, %43
  br label %57

57:                                               ; preds = %56, %38
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.SPI_TypeDef, ptr %60, i32 0, i32 0
  %62 = load volatile i32, ptr %61, align 4, !tbaa !20
  %63 = zext i32 %62 to i64
  %64 = and i64 %63, -2
  %65 = trunc i64 %64 to i32
  store volatile i32 %65, ptr %61, align 4, !tbaa !20
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.__I2S_HandleTypeDef, ptr %66, i32 0, i32 13
  store volatile i32 1, ptr %67, align 4, !tbaa !21
  %68 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %68
}

declare i32 @HAL_DMA_Abort(ptr 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"__I2S_HandleTypeDef", !6, i64 0, !13, i64 8, !6, i64 48, !14, i64 56, !14, i64 58, !6, i64 64, !14, i64 72, !14, i64 74, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !10, i64 112, !10, i64 116, !10, i64 120}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 36, !10, i64 48, !7, i64 52, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80}
!17 = !{!12, !6, i64 96}
!18 = !{!12, !10, i64 120}
!19 = !{!12, !6, i64 104}
!20 = !{!16, !10, i64 0}
!21 = !{!12, !10, i64 116}


; 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, 2) i32 @HAL_I2S_DMAStop(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  %4 = load volatile i32, ptr %3, align 4, !tbaa !13
  %5 = and i32 %4, -32769
  store volatile i32 %5, ptr %3, align 4, !tbaa !13
  %6 = load volatile i32, ptr %3, align 4, !tbaa !13
  %7 = and i32 %6, -16385
  store volatile i32 %7, ptr %3, align 4, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 96
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %16, label %10

10:                                               ; preds = %1
  %11 = tail call i32 @HAL_DMA_Abort(ptr noundef nonnull %9) #2
  %.not12 = icmp eq i32 %11, 0
  br i1 %.not12, label %16, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %0, i64 120
  %14 = load volatile i32, ptr %13, align 8, !tbaa !16
  %15 = or i32 %14, 8
  store volatile i32 %15, ptr %13, align 8, !tbaa !16
  br label %16

16:                                               ; preds = %10, %12, %1
  %.0 = phi i32 [ 1, %12 ], [ 0, %10 ], [ 0, %1 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 104
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %.not13 = icmp eq ptr %18, null
  br i1 %.not13, label %25, label %19

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

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %0, i64 120
  %23 = load volatile i32, ptr %22, align 8, !tbaa !16
  %24 = or i32 %23, 8
  store volatile i32 %24, ptr %22, align 8, !tbaa !16
  br label %25

25:                                               ; preds = %19, %21, %16
  %.1 = phi i32 [ 1, %21 ], [ %.0, %19 ], [ %.0, %16 ]
  %26 = load ptr, ptr %0, align 8, !tbaa !5
  %27 = load volatile i32, ptr %26, align 4, !tbaa !18
  %28 = and i32 %27, -2
  store volatile i32 %28, ptr %26, align 4, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %0, i64 116
  store volatile i32 1, ptr %29, align 4, !tbaa !19
  ret i32 %.1
}

declare i32 @HAL_DMA_Abort(ptr 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, !7, i64 0}
!6 = !{!"__I2S_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, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !11, i64 112, !11, i64 116, !11, i64 120}
!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, i64 36}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!14, !11, i64 8}
!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, !8, i64 36, !11, i64 48, !8, i64 52, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80}
!15 = !{!6, !7, i64 96}
!16 = !{!6, !11, i64 120}
!17 = !{!6, !7, i64 104}
!18 = !{!14, !11, i64 0}
!19 = !{!6, !11, i64 116}


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