; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/sdio/stm32 (sdio)

; 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.sdio_t = type { %struct.SD_HandleTypeDef, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, %struct.sdio_private_t }
%struct.SD_HandleTypeDef = type { ptr, %struct.SDMMC_InitTypeDef, i32, ptr, i32, ptr, i32, i32, i32, i32, %struct.HAL_SD_CardInfoTypeDef, [4 x i32], [4 x i32] }
%struct.SDMMC_InitTypeDef = type { i32, i32, i32, i32, i32 }
%struct.HAL_SD_CardInfoTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.sdio_private_t = type { i32, %struct.HAL_SD_CardInfoTypeDef, i32, i32, ptr, ptr }

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @sdio_read_blocks(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %17, label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %4
  store i32 22, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %95

18:                                               ; preds = %14
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sdio_t, ptr %19, i32 0, i32 10
  %21 = getelementptr inbounds %struct.sdio_private_t, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.sdio_t, ptr %23, i32 0, i32 8
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = mul i32 %25, 1000
  %27 = udiv i32 %26, 1000
  %28 = call i64 @xQueueSemaphoreTake(ptr noundef %22, i32 noundef %27)
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %18
  store i32 116, ptr %10, align 4, !tbaa !9
  br label %85

31:                                               ; preds = %18
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.sdio_t, ptr %32, i32 0, i32 10
  %34 = getelementptr inbounds %struct.sdio_private_t, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = call i64 @xQueueSemaphoreTake(ptr noundef %35, i32 noundef 0)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.sdio_t, ptr %37, i32 0, i32 10
  %39 = getelementptr inbounds %struct.sdio_private_t, ptr %38, i32 0, i32 2
  store i32 2, ptr %39, align 8, !tbaa !19
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.sdio_t, ptr %41, i32 0, i32 8
  %43 = load i32, ptr %42, align 8, !tbaa !17
  %44 = call i32 @sdio_check_status_with_timeout(ptr noundef %40, i32 noundef %43)
  store i32 %44, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %31
  br label %85

48:                                               ; preds = %31
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.sdio_t, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = call i32 @HAL_SD_ReadBlocks_DMA(ptr noundef %50, ptr noundef %51, i32 noundef %52, i32 noundef %53)
  store i32 %54, ptr %10, align 4, !tbaa !9
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %48
  br label %85

58:                                               ; preds = %48
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.sdio_t, ptr %59, i32 0, i32 10
  %61 = getelementptr inbounds %struct.sdio_private_t, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.sdio_t, ptr %63, i32 0, i32 8
  %65 = load i32, ptr %64, align 8, !tbaa !17
  %66 = mul i32 %65, 1000
  %67 = udiv i32 %66, 1000
  %68 = call i64 @xQueueSemaphoreTake(ptr noundef %62, i32 noundef %67)
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %71, label %70

70:                                               ; preds = %58
  store i32 116, ptr %10, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %70, %58
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.sdio_t, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %73, i32 0, i32 9
  %75 = load volatile i32, ptr %74, align 4, !tbaa !20
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %84

77:                                               ; preds = %71
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.sdio_t, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %79, i32 0, i32 9
  %81 = load volatile i32, ptr %80, align 4, !tbaa !20
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = or i32 %82, %81
  store i32 %83, ptr %10, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %77, %71
  br label %85

85:                                               ; preds = %84, %57, %47, %30
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.sdio_t, ptr %86, i32 0, i32 10
  %88 = getelementptr inbounds %struct.sdio_private_t, ptr %87, i32 0, i32 2
  store i32 0, ptr %88, align 8, !tbaa !19
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.sdio_t, ptr %89, i32 0, i32 10
  %91 = getelementptr inbounds %struct.sdio_private_t, ptr %90, i32 0, i32 5
  %92 = load ptr, ptr %91, align 8, !tbaa !11
  %93 = call i64 @xQueueGenericSend(ptr noundef %92, ptr noundef null, i32 noundef 0, i64 noundef 0)
  %94 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %94, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %95

95:                                               ; preds = %85, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %96 = load i32, ptr %5, align 4
  ret i32 %96
}

declare i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) #2

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

declare i32 @HAL_SD_ReadBlocks_DMA(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 264}
!12 = !{!"", !13, i64 0, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !10, i64 200, !10, i64 204, !16, i64 208}
!13 = !{!"", !6, i64 0, !14, i64 8, !10, i64 28, !6, i64 32, !10, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !15, i64 72, !7, i64 108, !7, i64 124}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!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}
!16 = !{!"", !10, i64 0, !15, i64 4, !10, i64 40, !10, i64 44, !6, i64 48, !6, i64 56}
!17 = !{!12, !10, i64 200}
!18 = !{!12, !6, i64 256}
!19 = !{!12, !10, i64 248}
!20 = !{!12, !10, 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @sdio_read_blocks(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %3, 0
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %40, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 264
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 200
  %11 = load i32, ptr %10, align 8, !tbaa !15
  %12 = mul i32 %11, 1000
  %13 = udiv i32 %12, 1000
  %14 = tail call i64 @xQueueSemaphoreTake(ptr noundef %9, i32 noundef %13) #2
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %36, label %16

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %0, i64 256
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = tail call i64 @xQueueSemaphoreTake(ptr noundef %18, i32 noundef 0) #2
  %20 = getelementptr inbounds i8, ptr %0, i64 248
  store i32 2, ptr %20, align 8, !tbaa !17
  %21 = load i32, ptr %10, align 8, !tbaa !15
  %22 = tail call i32 @sdio_check_status_with_timeout(ptr noundef nonnull %0, i32 noundef %21)
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %23, label %36

23:                                               ; preds = %16
  %24 = tail call i32 @HAL_SD_ReadBlocks_DMA(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, i32 noundef %3) #2
  %.not29 = icmp eq i32 %24, 0
  br i1 %.not29, label %25, label %36

25:                                               ; preds = %23
  %26 = load ptr, ptr %17, align 8, !tbaa !16
  %27 = load i32, ptr %10, align 8, !tbaa !15
  %28 = mul i32 %27, 1000
  %29 = udiv i32 %28, 1000
  %30 = tail call i64 @xQueueSemaphoreTake(ptr noundef %26, i32 noundef %29) #2
  %.not30 = icmp eq i64 %30, 0
  %spec.select = select i1 %.not30, i32 116, i32 0
  %31 = getelementptr inbounds i8, ptr %0, i64 68
  %32 = load volatile i32, ptr %31, align 4, !tbaa !18
  %.not31 = icmp eq i32 %32, 0
  br i1 %.not31, label %36, label %33

33:                                               ; preds = %25
  %34 = load volatile i32, ptr %31, align 4, !tbaa !18
  %35 = or i32 %34, %spec.select
  br label %36

36:                                               ; preds = %7, %25, %33, %23, %16
  %.1 = phi i32 [ %22, %16 ], [ %24, %23 ], [ %35, %33 ], [ %spec.select, %25 ], [ 116, %7 ]
  %37 = getelementptr inbounds i8, ptr %0, i64 248
  store i32 0, ptr %37, align 8, !tbaa !17
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = tail call i64 @xQueueGenericSend(ptr noundef %38, ptr noundef null, i32 noundef 0, i64 noundef 0) #2
  br label %40

40:                                               ; preds = %4, %36
  %.023 = phi i32 [ %.1, %36 ], [ 22, %4 ]
  ret i32 %.023
}

declare i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @sdio_check_status_with_timeout(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @HAL_SD_ReadBlocks_DMA(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 noundef) 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, !8, i64 264}
!6 = !{!"", !7, i64 0, !8, i64 144, !8, i64 152, !8, i64 160, !8, i64 168, !8, i64 176, !8, i64 184, !8, i64 192, !12, i64 200, !12, i64 204, !14, i64 208}
!7 = !{!"", !8, i64 0, !11, i64 8, !12, i64 28, !8, i64 32, !12, i64 40, !8, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !13, i64 72, !9, i64 108, !9, i64 124}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !9, i64 0}
!13 = !{!"", !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}
!14 = !{!"", !12, i64 0, !13, i64 4, !12, i64 40, !12, i64 44, !8, i64 48, !8, i64 56}
!15 = !{!6, !12, i64 200}
!16 = !{!6, !8, i64 256}
!17 = !{!6, !12, i64 248}
!18 = !{!6, !12, i64 68}


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