; 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_CLUTLoading_Abort(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %11, i32 0, i32 9
  store ptr %12, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %15, i32 0, i32 0
  %17 = load volatile i32, ptr %16, align 4, !tbaa !14
  %18 = zext i32 %17 to i64
  %19 = or i64 %18, 4
  %20 = trunc i64 %19 to i32
  store volatile i32 %20, ptr %16, align 4, !tbaa !14
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %28

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %26, i32 0, i32 7
  store ptr %27, ptr %7, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %23, %2
  %29 = call i32 @HAL_GetTick()
  store i32 %29, ptr %6, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %53, %28
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load volatile i32, ptr %31, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = and i64 %33, 32
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %54

36:                                               ; preds = %30
  %37 = call i32 @HAL_GetTick()
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sub i32 %37, %38
  %40 = icmp ugt i32 %39, 1000
  br i1 %40, label %41, label %53

41:                                               ; preds = %36
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %42, i32 0, i32 7
  %44 = load volatile i32, ptr %43, align 8, !tbaa !16
  %45 = or i32 %44, 32
  store volatile i32 %45, ptr %43, align 8, !tbaa !16
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %46, i32 0, i32 6
  store volatile i32 3, ptr %47, align 4, !tbaa !17
  br label %48

48:                                               ; preds = %41
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %49, i32 0, i32 5
  store i32 0, ptr %50, align 8, !tbaa !18
  br label %51

51:                                               ; preds = %48
  br label %52

52:                                               ; preds = %51
  store i32 3, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %70

53:                                               ; preds = %36
  br label %30, !llvm.loop !19

54:                                               ; preds = %30
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.DMA2D_TypeDef, ptr %57, i32 0, i32 0
  %59 = load volatile i32, ptr %58, align 4, !tbaa !14
  %60 = zext i32 %59 to i64
  %61 = and i64 %60, -14593
  %62 = trunc i64 %61 to i32
  store volatile i32 %62, ptr %58, align 4, !tbaa !14
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %63, i32 0, i32 6
  store volatile i32 1, ptr %64, align 4, !tbaa !17
  br label %65

65:                                               ; preds = %54
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.__DMA2D_HandleTypeDef, ptr %66, i32 0, i32 5
  store i32 0, ptr %67, align 8, !tbaa !18
  br label %68

68:                                               ; preds = %65
  br label %69

69:                                               ; preds = %68
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %70

70:                                               ; preds = %69, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

; 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"__DMA2D_HandleTypeDef", !6, i64 0, !13, i64 8, !6, i64 32, !6, i64 40, !7, i64 48, !10, i64 104, !10, i64 108, !10, i64 112}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !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, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !7, i64 80, !7, i64 1024, !7, i64 2048}
!16 = !{!12, !10, i64 112}
!17 = !{!12, !10, i64 108}
!18 = !{!12, !10, 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_CLUTLoading_Abort(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = load volatile i32, ptr %3, align 4, !tbaa !12
  %5 = or i32 %4, 4
  store volatile i32 %5, ptr %3, align 4, !tbaa !12
  %6 = icmp eq i32 %1, 1
  %spec.select.v = select i1 %6, i64 28, i64 36
  %spec.select = getelementptr inbounds i8, ptr %3, i64 %spec.select.v
  %7 = tail call i32 @HAL_GetTick() #2
  br label %8

8:                                                ; preds = %11, %2
  %9 = load volatile i32, ptr %spec.select, align 4, !tbaa !14
  %10 = and i32 %9, 32
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %19, label %11

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

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

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

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

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 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !11, i64 112}
!18 = !{!6, !11, i64 108}
!19 = !{!6, !11, i64 104}


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