; 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.QSPI_HandleTypeDef = type { ptr, %struct.QSPI_InitTypeDef, ptr, i32, i32, ptr, i32, i32, ptr, i32, i32, i32, i32 }
%struct.QSPI_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.QUADSPI_TypeDef = type { 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: nounwind uwtable
declare hidden i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; 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_QSPI_Abort(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = call i32 @HAL_GetTick()
  store i32 %5, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %6, i32 0, i32 10
  %8 = load volatile i32, ptr %7, align 4, !tbaa !11
  %9 = and i32 %8, 2
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %81

11:                                               ; preds = %1
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %13, i32 0, i32 9
  store volatile i32 0, ptr %14, align 8, !tbaa !14
  br label %15

15:                                               ; preds = %12
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %19, i32 0, i32 0
  %21 = load volatile i32, ptr %20, align 4, !tbaa !16
  %22 = zext i32 %21 to i64
  %23 = and i64 %22, 4
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %46

25:                                               ; preds = %16
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %28, i32 0, i32 0
  %30 = load volatile i32, ptr %29, align 4, !tbaa !16
  %31 = zext i32 %30 to i64
  %32 = and i64 %31, -5
  %33 = trunc i64 %32 to i32
  store volatile i32 %33, ptr %29, align 4, !tbaa !16
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %34, i32 0, i32 8
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = call i32 @HAL_MDMA_Abort(ptr noundef %36)
  store i32 %37, ptr %3, align 4, !tbaa !9
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %25
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %41, i32 0, i32 11
  %43 = load volatile i32, ptr %42, align 8, !tbaa !19
  %44 = or i32 %43, 4
  store volatile i32 %44, ptr %42, align 8, !tbaa !19
  br label %45

45:                                               ; preds = %40, %25
  br label %46

46:                                               ; preds = %45, %16
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %49, i32 0, i32 0
  %51 = load volatile i32, ptr %50, align 4, !tbaa !16
  %52 = zext i32 %51 to i64
  %53 = or i64 %52, 2
  %54 = trunc i64 %53 to i32
  store volatile i32 %54, ptr %50, align 4, !tbaa !16
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %57, i32 0, i32 12
  %59 = load i32, ptr %58, align 4, !tbaa !20
  %60 = call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef %55, i32 noundef 2, i32 noundef 1, i32 noundef %56, i32 noundef %59)
  store i32 %60, ptr %3, align 4, !tbaa !9
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %74

63:                                               ; preds = %46
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %66, i32 0, i32 3
  store volatile i32 2, ptr %67, align 4, !tbaa !21
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %70, i32 0, i32 12
  %72 = load i32, ptr %71, align 4, !tbaa !20
  %73 = call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef %68, i32 noundef 32, i32 noundef 0, i32 noundef %69, i32 noundef %72)
  store i32 %73, ptr %3, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %63, %46
  %75 = load i32, ptr %3, align 4, !tbaa !9
  %76 = icmp eq i32 %75, 0
  br i1 %76, label %77, label %80

77:                                               ; preds = %74
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %78, i32 0, i32 10
  store volatile i32 1, ptr %79, align 4, !tbaa !11
  br label %80

80:                                               ; preds = %77, %74
  br label %81

81:                                               ; preds = %80, %1
  %82 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %82
}

declare i32 @HAL_MDMA_Abort(ptr noundef) #1

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 84}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 40, !10, i64 48, !10, i64 52, !6, i64 56, !10, i64 64, !10, i64 68, !6, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92}
!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}
!14 = !{!12, !10, i64 80}
!15 = !{!12, !6, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !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}
!18 = !{!12, !6, i64 72}
!19 = !{!12, !10, i64 88}
!20 = !{!12, !10, i64 92}
!21 = !{!17, !10, i64 12}


; 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
declare hidden i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_QSPI_Abort(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @HAL_GetTick() #2
  %3 = getelementptr inbounds i8, ptr %0, i64 84
  %4 = load volatile i32, ptr %3, align 4, !tbaa !5
  %5 = and i32 %4, 2
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.thread, label %6

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  store volatile i32 0, ptr %7, align 8, !tbaa !12
  %8 = load ptr, ptr %0, align 8, !tbaa !13
  %9 = load volatile i32, ptr %8, align 4, !tbaa !14
  %10 = and i32 %9, 4
  %.not19 = icmp eq i32 %10, 0
  br i1 %.not19, label %21, label %11

11:                                               ; preds = %6
  %12 = load volatile i32, ptr %8, align 4, !tbaa !14
  %13 = and i32 %12, -5
  store volatile i32 %13, ptr %8, align 4, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 72
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = tail call i32 @HAL_MDMA_Abort(ptr noundef %15) #2
  %.not20 = icmp eq i32 %16, 0
  br i1 %.not20, label %21, label %17

17:                                               ; preds = %11
  %18 = getelementptr inbounds i8, ptr %0, i64 88
  %19 = load volatile i32, ptr %18, align 8, !tbaa !17
  %20 = or i32 %19, 4
  store volatile i32 %20, ptr %18, align 8, !tbaa !17
  br label %21

21:                                               ; preds = %11, %17, %6
  %22 = load ptr, ptr %0, align 8, !tbaa !13
  %23 = load volatile i32, ptr %22, align 4, !tbaa !14
  %24 = or i32 %23, 2
  store volatile i32 %24, ptr %22, align 4, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %0, i64 92
  %26 = load i32, ptr %25, align 4, !tbaa !18
  %27 = tail call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 2, i32 noundef 1, i32 noundef %2, i32 noundef %26)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %.thread

29:                                               ; preds = %21
  %30 = load ptr, ptr %0, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %30, i64 12
  store volatile i32 2, ptr %31, align 4, !tbaa !19
  %32 = load i32, ptr %25, align 4, !tbaa !18
  %33 = tail call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %2, i32 noundef %32)
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %.thread

35:                                               ; preds = %29
  store volatile i32 1, ptr %3, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %21, %29, %35, %1
  %.1 = phi i32 [ 0, %35 ], [ %33, %29 ], [ 0, %1 ], [ %27, %21 ]
  ret i32 %.1
}

declare i32 @HAL_MDMA_Abort(ptr noundef) local_unnamed_addr #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 84}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 40, !11, i64 48, !11, i64 52, !7, i64 56, !11, i64 64, !11, i64 68, !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, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 80}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"", !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}
!16 = !{!6, !7, i64 72}
!17 = !{!6, !11, i64 88}
!18 = !{!6, !11, i64 92}
!19 = !{!15, !11, i64 12}


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