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

; 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.MMC_HandleTypeDef = type { ptr, %struct.SDMMC_InitTypeDef, i32, ptr, i32, ptr, i32, i32, i32, i32, %struct.HAL_MMC_CardInfoTypeDef, [4 x i32], [4 x i32], [128 x i32] }
%struct.SDMMC_InitTypeDef = type { i32, i32, i32, i32, i32 }
%struct.HAL_MMC_CardInfoTypeDef = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.SDMMC_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, i32, i32, i32, [8 x i32], i32, [222 x 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

declare i32 @SDMMC_CmdStopTransfer(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_MMC_AbortCallback(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @HAL_MMC_GetCardState(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_MMC_Abort_IT(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 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.SDMMC_TypeDef, ptr %8, i32 0, i32 15
  %10 = load volatile i32, ptr %9, align 4, !tbaa !14
  %11 = zext i32 %10 to i64
  %12 = and i64 %11, -315
  %13 = trunc i64 %12 to i32
  store volatile i32 %13, ptr %9, align 4, !tbaa !14
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.SDMMC_TypeDef, ptr %16, i32 0, i32 18
  store volatile i32 0, ptr %17, align 4, !tbaa !16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.SDMMC_TypeDef, ptr %20, i32 0, i32 14
  store volatile i32 534777855, ptr %21, align 4, !tbaa !17
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i32 @HAL_MMC_GetCardState(ptr noundef %22)
  store i32 %23, ptr %4, align 4, !tbaa !18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %24, i32 0, i32 8
  store volatile i32 1, ptr %25, align 8, !tbaa !19
  %26 = load i32, ptr %4, align 4, !tbaa !18
  %27 = icmp eq i32 %26, 6
  br i1 %27, label %31, label %28

28:                                               ; preds = %1
  %29 = load i32, ptr %4, align 4, !tbaa !18
  %30 = icmp eq i32 %29, 5
  br i1 %30, label %31, label %38

31:                                               ; preds = %28, %1
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = call i32 @SDMMC_CmdStopTransfer(ptr noundef %34)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %36, i32 0, i32 9
  store volatile i32 %35, ptr %37, align 4, !tbaa !20
  br label %38

38:                                               ; preds = %31, %28
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %39, i32 0, i32 9
  %41 = load volatile i32, ptr %40, align 4, !tbaa !20
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %38
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %47

44:                                               ; preds = %38
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  call void @HAL_MMC_AbortCallback(ptr noundef %45)
  br label %46

46:                                               ; preds = %44
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %47

47:                                               ; preds = %46, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %48 = load i32, ptr %2, align 4
  ret i32 %48
}

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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !12, i64 28, !6, i64 32, !12, i64 40, !6, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !13, i64 72, !7, i64 100, !7, i64 116, !7, i64 132}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24}
!14 = !{!15, !12, i64 60}
!15 = !{!"", !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, !7, i64 68, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92, !7, i64 96, !12, i64 128, !7, i64 132, !12, i64 1020}
!16 = !{!15, !12, i64 80}
!17 = !{!15, !12, i64 56}
!18 = !{!12, !12, i64 0}
!19 = !{!10, !12, i64 64}
!20 = !{!10, !12, i64 68}


; 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 @SDMMC_CmdStopTransfer(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_MMC_AbortCallback(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @HAL_MMC_GetCardState(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_MMC_Abort_IT(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 60
  %4 = load volatile i32, ptr %3, align 4, !tbaa !13
  %5 = and i32 %4, -315
  store volatile i32 %5, ptr %3, align 4, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %2, i64 80
  store volatile i32 0, ptr %6, align 4, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %2, i64 56
  store volatile i32 534777855, ptr %7, align 4, !tbaa !16
  %8 = tail call i32 @HAL_MMC_GetCardState(ptr noundef nonnull %0)
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  store volatile i32 1, ptr %9, align 8, !tbaa !17
  %10 = add i32 %8, -5
  %or.cond = icmp ult i32 %10, 2
  br i1 %or.cond, label %11, label %15

11:                                               ; preds = %1
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = tail call i32 @SDMMC_CmdStopTransfer(ptr noundef %12) #2
  %14 = getelementptr inbounds i8, ptr %0, i64 68
  store volatile i32 %13, ptr %14, align 4, !tbaa !18
  br label %15

15:                                               ; preds = %1, %11
  %16 = getelementptr inbounds i8, ptr %0, i64 68
  %17 = load volatile i32, ptr %16, align 4, !tbaa !18
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %19

18:                                               ; preds = %15
  tail call void @HAL_MMC_AbortCallback(ptr noundef nonnull %0)
  br label %19

19:                                               ; preds = %15, %18
  %.0 = phi i32 [ 0, %18 ], [ 1, %15 ]
  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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 28, !7, i64 32, !11, i64 40, !7, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !12, i64 72, !8, i64 100, !8, i64 116, !8, i64 132}
!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 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!13 = !{!14, !11, i64 60}
!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, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !8, i64 68, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !8, i64 96, !11, i64 128, !8, i64 132, !11, i64 1020}
!15 = !{!14, !11, i64 80}
!16 = !{!14, !11, i64 56}
!17 = !{!6, !11, i64 64}
!18 = !{!6, !11, i64 68}


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