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

; 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.__MDMA_HandleTypeDef = type { ptr, %struct.MDMA_InitTypeDef, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct.MDMA_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.MDMA_Channel_TypeDef = type { i32, i32, 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

declare i32 @HAL_GetTick() #1

; 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_MDMA_Abort(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = call i32 @HAL_GetTick()
  store i32 %6, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %11, i32 0, i32 3
  %13 = load volatile i32, ptr %12, align 4, !tbaa !11
  %14 = icmp ne i32 2, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %16, i32 0, i32 14
  store volatile i32 128, ptr %17, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %19, i32 0, i32 2
  store i32 0, ptr %20, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

23:                                               ; preds = %10
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds %struct.MDMA_Channel_TypeDef, ptr %26, i32 0, i32 3
  %28 = load volatile i32, ptr %27, align 4, !tbaa !17
  %29 = and i32 %28, -63
  store volatile i32 %29, ptr %27, align 4, !tbaa !17
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds %struct.MDMA_Channel_TypeDef, ptr %32, i32 0, i32 3
  %34 = load volatile i32, ptr %33, align 4, !tbaa !17
  %35 = zext i32 %34 to i64
  %36 = and i64 %35, -2
  %37 = trunc i64 %36 to i32
  store volatile i32 %37, ptr %33, align 4, !tbaa !17
  br label %38

38:                                               ; preds = %64, %23
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = getelementptr inbounds %struct.MDMA_Channel_TypeDef, ptr %41, i32 0, i32 3
  %43 = load volatile i32, ptr %42, align 4, !tbaa !17
  %44 = zext i32 %43 to i64
  %45 = and i64 %44, 1
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %65

47:                                               ; preds = %38
  %48 = call i32 @HAL_GetTick()
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = sub i32 %48, %49
  %51 = icmp ugt i32 %50, 5
  br i1 %51, label %52, label %64

52:                                               ; preds = %47
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %53, i32 0, i32 14
  %55 = load volatile i32, ptr %54, align 4, !tbaa !14
  %56 = or i32 %55, 64
  store volatile i32 %56, ptr %54, align 4, !tbaa !14
  br label %57

57:                                               ; preds = %52
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %58, i32 0, i32 2
  store i32 0, ptr %59, align 8, !tbaa !15
  br label %60

60:                                               ; preds = %57
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %62, i32 0, i32 3
  store volatile i32 3, ptr %63, align 4, !tbaa !11
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

64:                                               ; preds = %47
  br label %38, !llvm.loop !18

65:                                               ; preds = %38
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = getelementptr inbounds %struct.MDMA_Channel_TypeDef, ptr %68, i32 0, i32 1
  store volatile i32 31, ptr %69, align 4, !tbaa !20
  br label %70

70:                                               ; preds = %65
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %71, i32 0, i32 2
  store i32 0, ptr %72, align 8, !tbaa !15
  br label %73

73:                                               ; preds = %70
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %75, i32 0, i32 3
  store volatile i32 1, ptr %76, align 4, !tbaa !11
  br label %77

77:                                               ; preds = %74
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

78:                                               ; preds = %77, %61, %22, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %79 = load i32, ptr %2, align 4
  ret i32 %79
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !10, i64 68}
!12 = !{!"__MDMA_HandleTypeDef", !6, i64 0, !13, i64 8, !10, i64 64, !10, i64 68, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !10, i64 148}
!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, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!14 = !{!12, !10, i64 148}
!15 = !{!12, !10, i64 64}
!16 = !{!12, !6, i64 0}
!17 = !{!13, !10, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!13, !10, i64 4}


; 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_GetTick() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_MDMA_Abort(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @HAL_GetTick() #2
  %3 = icmp eq ptr %0, null
  br i1 %3, label %34, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 68
  %6 = load volatile i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 2
  br i1 %.not, label %10, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 148
  store volatile i32 128, ptr %8, align 4, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 0, ptr %9, align 8, !tbaa !13
  br label %34

10:                                               ; preds = %4
  %11 = load ptr, ptr %0, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %11, i64 12
  %13 = load volatile i32, ptr %12, align 4, !tbaa !15
  %14 = and i32 %13, -63
  store volatile i32 %14, ptr %12, align 4, !tbaa !15
  %15 = load volatile i32, ptr %12, align 4, !tbaa !15
  %16 = and i32 %15, -2
  store volatile i32 %16, ptr %12, align 4, !tbaa !15
  br label %17

17:                                               ; preds = %22, %10
  %18 = load ptr, ptr %0, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %18, i64 12
  %20 = load volatile i32, ptr %19, align 4, !tbaa !15
  %21 = and i32 %20, 1
  %.not15 = icmp eq i32 %21, 0
  br i1 %.not15, label %31, label %22

22:                                               ; preds = %17
  %23 = tail call i32 @HAL_GetTick() #2
  %24 = sub i32 %23, %2
  %25 = icmp ugt i32 %24, 5
  br i1 %25, label %26, label %17, !llvm.loop !16

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %0, i64 148
  %28 = load volatile i32, ptr %27, align 4, !tbaa !12
  %29 = or i32 %28, 64
  store volatile i32 %29, ptr %27, align 4, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 0, ptr %30, align 8, !tbaa !13
  store volatile i32 3, ptr %5, align 4, !tbaa !5
  br label %34

31:                                               ; preds = %17
  %32 = getelementptr inbounds i8, ptr %18, i64 4
  store volatile i32 31, ptr %32, align 4, !tbaa !18
  %33 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 0, ptr %33, align 8, !tbaa !13
  store volatile i32 1, ptr %5, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %1, %31, %26, %7
  %.0 = phi i32 [ 1, %7 ], [ 1, %26 ], [ 0, %31 ], [ 1, %1 ]
  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, !11, i64 68}
!6 = !{!"__MDMA_HandleTypeDef", !7, i64 0, !10, i64 8, !11, i64 64, !11, i64 68, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !11, i64 144, !11, i64 148}
!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, i64 40, !11, i64 44, !11, i64 48, !11, i64 52}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 148}
!13 = !{!6, !11, i64 64}
!14 = !{!6, !7, i64 0}
!15 = !{!10, !11, i64 12}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !11, i64 4}


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