; 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.__DMA2D_HandleTypeDef = type { ptr, %struct.DMA2D_InitTypeDef, ptr, ptr, [2 x %struct.DMA2D_LayerCfgTypeDef], i32, i32, i32 }
%struct.DMA2D_InitTypeDef = type { i32, i32, i32, i32, i32 }
%struct.DMA2D_LayerCfgTypeDef = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.DMA2D_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [236 x i32], [256 x i32], [256 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_DMA2D_Abort(ptr noundef %0) #0 {
  %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 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %8, i32 0, i32 0
  %10 = load volatile i32, ptr %9, align 4, !tbaa !13
  %11 = zext i32 %10 to i64
  %12 = and i64 %11, -6
  %13 = or i64 %12, 4
  %14 = trunc i64 %13 to i32
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %17, i32 0, i32 0
  store volatile i32 %14, ptr %18, align 4, !tbaa !13
  %19 = call i32 @HAL_GetTick()
  store i32 %19, ptr %4, align 4, !tbaa !15
  br label %20

20:                                               ; preds = %46, %1
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %23, i32 0, i32 0
  %25 = load volatile i32, ptr %24, align 4, !tbaa !13
  %26 = zext i32 %25 to i64
  %27 = and i64 %26, 1
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %47

29:                                               ; preds = %20
  %30 = call i32 @HAL_GetTick()
  %31 = load i32, ptr %4, align 4, !tbaa !15
  %32 = sub i32 %30, %31
  %33 = icmp ugt i32 %32, 1000
  br i1 %33, label %34, label %46

34:                                               ; preds = %29
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %35, i32 0, i32 7
  %37 = load volatile i32, ptr %36, align 8, !tbaa !16
  %38 = or i32 %37, 32
  store volatile i32 %38, ptr %36, align 8, !tbaa !16
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %39, i32 0, i32 6
  store volatile i32 3, ptr %40, align 4, !tbaa !17
  br label %41

41:                                               ; preds = %34
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %42, i32 0, i32 5
  store i32 0, ptr %43, align 8, !tbaa !18
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  store i32 3, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %63

46:                                               ; preds = %29
  br label %20, !llvm.loop !19

47:                                               ; preds = %20
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %50, i32 0, i32 0
  %52 = load volatile i32, ptr %51, align 4, !tbaa !13
  %53 = zext i32 %52 to i64
  %54 = and i64 %53, -8961
  %55 = trunc i64 %54 to i32
  store volatile i32 %55, ptr %51, align 4, !tbaa !13
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %56, i32 0, i32 6
  store volatile i32 1, ptr %57, align 4, !tbaa !17
  br label %58

58:                                               ; preds = %47
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %59, i32 0, i32 5
  store i32 0, ptr %60, align 8, !tbaa !18
  br label %61

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %63

63:                                               ; preds = %62, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %64 = load i32, ptr %2, align 4
  ret i32 %64
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @HAL_GetTick() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"__DMA2D_HandleTypeDef", !6, i64 0, !11, i64 8, !6, i64 32, !6, i64 40, !7, i64 48, !12, i64 104, !12, i64 108, !12, i64 112}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !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, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !7, i64 80, !7, i64 1024, !7, i64 2048}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 112}
!17 = !{!10, !12, i64 108}
!18 = !{!10, !12, i64 104}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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_DMA2D_Abort(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = load volatile i32, ptr %2, align 4, !tbaa !12
  %4 = and i32 %3, -6
  %5 = or disjoint i32 %4, 4
  store volatile i32 %5, ptr %2, align 4, !tbaa !12
  %6 = tail call i32 @HAL_GetTick() #2
  br label %7

7:                                                ; preds = %11, %1
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = load volatile i32, ptr %8, align 4, !tbaa !12
  %10 = and i32 %9, 1
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %19, label %11

11:                                               ; preds = %7
  %12 = tail call i32 @HAL_GetTick() #2
  %13 = sub i32 %12, %6
  %14 = icmp ugt i32 %13, 1000
  br i1 %14, label %15, label %7, !llvm.loop !14

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 112
  %17 = load volatile i32, ptr %16, align 8, !tbaa !16
  %18 = or i32 %17, 32
  store volatile i32 %18, ptr %16, align 8, !tbaa !16
  br label %22

19:                                               ; preds = %7
  %20 = load volatile i32, ptr %8, align 4, !tbaa !12
  %21 = and i32 %20, -8961
  store volatile i32 %21, ptr %8, align 4, !tbaa !12
  br label %22

22:                                               ; preds = %19, %15
  %.sink = phi i32 [ 1, %19 ], [ 3, %15 ]
  %.0 = phi i32 [ 0, %19 ], [ 3, %15 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 108
  store volatile i32 %.sink, ptr %23, align 4, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %0, i64 104
  store i32 0, ptr %24, align 8, !tbaa !18
  ret i32 %.0
}

declare i32 @HAL_GetTick() 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 = !{!"__DMA2D_HandleTypeDef", !7, i64 0, !10, i64 8, !7, i64 32, !7, i64 40, !8, i64 48, !11, i64 104, !11, i64 108, !11, i64 112}
!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 = !{!"int", !8, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !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, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !8, i64 80, !8, i64 1024, !8, i64 2048}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !11, i64 112}
!17 = !{!6, !11, i64 108}
!18 = !{!6, !11, i64 104}


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