; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_hal_sd)

; 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.SDMMC_InitTypeDef = type { i32, i32, i32, i32, i32 }
%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.HAL_SD_CardInfoTypeDef = type { i32, i32, 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: nounwind uwtable
define dso_local i32 @HAL_SD_InitCard(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.SDMMC_InitTypeDef, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 20, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 0
  store i32 0, ptr %8, align 4, !tbaa !9
  %9 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 1
  store i32 0, ptr %9, align 4, !tbaa !12
  %10 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 2
  store i32 0, ptr %10, align 4, !tbaa !13
  %11 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 3
  store i32 0, ptr %11, align 4, !tbaa !14
  %12 = call i32 @HAL_RCCEx_GetPeriphCLKFreq(i32 noundef 65536)
  store i32 %12, ptr %6, align 4, !tbaa !15
  %13 = load i32, ptr %6, align 4, !tbaa !15
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %1
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %16, i32 0, i32 8
  store volatile i32 1, ptr %17, align 8, !tbaa !16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %18, i32 0, i32 9
  store volatile i32 134217728, ptr %19, align 4, !tbaa !19
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

20:                                               ; preds = %1
  %21 = load i32, ptr %6, align 4, !tbaa !15
  %22 = udiv i32 %21, 800000
  %23 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 4
  store i32 %22, ptr %23, align 4, !tbaa !20
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !21
  %27 = call i32 @SDMMC_Init(ptr noundef %26, ptr noundef byval(%struct.SDMMC_InitTypeDef) align 8 %5)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  %31 = call i32 @SDMMC_PowerState_ON(ptr noundef %30)
  %32 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 4
  %33 = load i32, ptr %32, align 4, !tbaa !20
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %20
  %36 = load i32, ptr %6, align 4, !tbaa !15
  %37 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 4
  %38 = load i32, ptr %37, align 4, !tbaa !20
  %39 = mul i32 2, %38
  %40 = udiv i32 %36, %39
  store i32 %40, ptr %6, align 4, !tbaa !15
  br label %41

41:                                               ; preds = %35, %20
  %42 = load i32, ptr %6, align 4, !tbaa !15
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load i32, ptr %6, align 4, !tbaa !15
  %46 = udiv i32 74000, %45
  %47 = add i32 1, %46
  call void @HAL_Delay(i32 noundef %47)
  br label %48

48:                                               ; preds = %44, %41
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = call i32 @SD_PowerON(ptr noundef %49)
  store i32 %50, ptr %4, align 4, !tbaa !15
  %51 = load i32, ptr %4, align 4, !tbaa !15
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %61

53:                                               ; preds = %48
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %54, i32 0, i32 8
  store volatile i32 1, ptr %55, align 8, !tbaa !16
  %56 = load i32, ptr %4, align 4, !tbaa !15
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %57, i32 0, i32 9
  %59 = load volatile i32, ptr %58, align 4, !tbaa !19
  %60 = or i32 %59, %56
  store volatile i32 %60, ptr %58, align 4, !tbaa !19
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

61:                                               ; preds = %48
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = call i32 @SD_InitCard(ptr noundef %62)
  store i32 %63, ptr %4, align 4, !tbaa !15
  %64 = load i32, ptr %4, align 4, !tbaa !15
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %74

66:                                               ; preds = %61
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %67, i32 0, i32 8
  store volatile i32 1, ptr %68, align 8, !tbaa !16
  %69 = load i32, ptr %4, align 4, !tbaa !15
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %70, i32 0, i32 9
  %72 = load volatile i32, ptr %71, align 4, !tbaa !19
  %73 = or i32 %72, %69
  store volatile i32 %73, ptr %71, align 4, !tbaa !19
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

74:                                               ; preds = %61
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !21
  %78 = call i32 @SDMMC_CmdBlockLength(ptr noundef %77, i32 noundef 512)
  store i32 %78, ptr %4, align 4, !tbaa !15
  %79 = load i32, ptr %4, align 4, !tbaa !15
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %93

81:                                               ; preds = %74
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !21
  %85 = getelementptr inbounds %struct.SDMMC_TypeDef, ptr %84, i32 0, i32 14
  store volatile i32 534777855, ptr %85, align 4, !tbaa !22
  %86 = load i32, ptr %4, align 4, !tbaa !15
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %87, i32 0, i32 9
  %89 = load volatile i32, ptr %88, align 4, !tbaa !19
  %90 = or i32 %89, %86
  store volatile i32 %90, ptr %88, align 4, !tbaa !19
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.SD_HandleTypeDef, ptr %91, i32 0, i32 8
  store volatile i32 1, ptr %92, align 8, !tbaa !16
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

93:                                               ; preds = %74
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

94:                                               ; preds = %93, %81, %66, %53, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 20, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %95 = load i32, ptr %2, align 4
  ret i32 %95
}

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

declare i32 @HAL_RCCEx_GetPeriphCLKFreq(i32 noundef) #2

declare i32 @SDMMC_Init(ptr noundef, ptr noundef byval(%struct.SDMMC_InitTypeDef) align 8) #2

declare i32 @SDMMC_PowerState_ON(ptr noundef) #2

declare void @HAL_Delay(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @SD_PowerON(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @SD_InitCard(ptr noundef) #1

declare i32 @SDMMC_CmdBlockLength(ptr noundef, i32 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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 12}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 64}
!17 = !{!"", !6, i64 0, !10, i64 8, !11, i64 28, !6, i64 32, !11, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !18, i64 72, !7, i64 108, !7, i64 124}
!18 = !{!"", !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}
!19 = !{!17, !11, i64 68}
!20 = !{!10, !11, i64 16}
!21 = !{!17, !6, i64 0}
!22 = !{!23, !11, i64 56}
!23 = !{!"", !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, !7, i64 68, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !7, i64 96, !11, i64 128, !7, i64 132, !11, i64 1020}


; 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"

%struct.SDMMC_InitTypeDef = type { i32, i32, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_SD_InitCard(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.SDMMC_InitTypeDef, align 8
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  %3 = tail call i32 @HAL_RCCEx_GetPeriphCLKFreq(i32 noundef 65536) #4
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %8

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  store volatile i32 1, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 68
  store volatile i32 134217728, ptr %7, align 4, !tbaa !13
  br label %45

8:                                                ; preds = %1
  %9 = udiv i32 %3, 800000
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 %9, ptr %10, align 8, !tbaa !14
  %11 = load ptr, ptr %0, align 8, !tbaa !15
  %12 = tail call i32 @SDMMC_Init(ptr noundef %11, ptr noundef nonnull byval(%struct.SDMMC_InitTypeDef) align 8 %2) #4
  %13 = load ptr, ptr %0, align 8, !tbaa !15
  %14 = tail call i32 @SDMMC_PowerState_ON(ptr noundef %13) #4
  %15 = load i32, ptr %10, align 8, !tbaa !14
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %.thread, label %16

16:                                               ; preds = %8
  %17 = shl i32 %15, 1
  %18 = udiv i32 %3, %17
  %.not31 = icmp ugt i32 %17, %3
  br i1 %.not31, label %21, label %.thread

.thread:                                          ; preds = %8, %16
  %.037 = phi i32 [ %18, %16 ], [ %3, %8 ]
  %19 = udiv i32 74000, %.037
  %20 = add nuw nsw i32 %19, 1
  tail call void @HAL_Delay(i32 noundef %20) #4
  br label %21

21:                                               ; preds = %.thread, %16
  %22 = tail call i32 @SD_PowerON(ptr noundef nonnull %0)
  %.not32 = icmp eq i32 %22, 0
  br i1 %.not32, label %28, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %0, i64 64
  store volatile i32 1, ptr %24, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 68
  %26 = load volatile i32, ptr %25, align 4, !tbaa !13
  %27 = or i32 %26, %22
  store volatile i32 %27, ptr %25, align 4, !tbaa !13
  br label %45

28:                                               ; preds = %21
  %29 = tail call i32 @SD_InitCard(ptr noundef nonnull %0)
  %.not33 = icmp eq i32 %29, 0
  br i1 %.not33, label %35, label %30

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %0, i64 64
  store volatile i32 1, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %0, i64 68
  %33 = load volatile i32, ptr %32, align 4, !tbaa !13
  %34 = or i32 %33, %29
  store volatile i32 %34, ptr %32, align 4, !tbaa !13
  br label %45

35:                                               ; preds = %28
  %36 = load ptr, ptr %0, align 8, !tbaa !15
  %37 = tail call i32 @SDMMC_CmdBlockLength(ptr noundef %36, i32 noundef 512) #4
  %.not34 = icmp eq i32 %37, 0
  br i1 %.not34, label %45, label %38

38:                                               ; preds = %35
  %39 = load ptr, ptr %0, align 8, !tbaa !15
  %40 = getelementptr inbounds i8, ptr %39, i64 56
  store volatile i32 534777855, ptr %40, align 4, !tbaa !16
  %41 = getelementptr inbounds i8, ptr %0, i64 68
  %42 = load volatile i32, ptr %41, align 4, !tbaa !13
  %43 = or i32 %42, %37
  store volatile i32 %43, ptr %41, align 4, !tbaa !13
  %44 = getelementptr inbounds i8, ptr %0, i64 64
  store volatile i32 1, ptr %44, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %35, %38, %30, %23, %5
  %.025 = phi i32 [ 1, %5 ], [ 1, %23 ], [ 1, %30 ], [ 1, %38 ], [ 0, %35 ]
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #4
  ret i32 %.025
}

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

declare i32 @HAL_RCCEx_GetPeriphCLKFreq(i32 noundef) local_unnamed_addr #2

declare i32 @SDMMC_Init(ptr noundef, ptr noundef byval(%struct.SDMMC_InitTypeDef) align 8) local_unnamed_addr #2

declare i32 @SDMMC_PowerState_ON(ptr noundef) local_unnamed_addr #2

declare void @HAL_Delay(i32 noundef) local_unnamed_addr #2

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

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

declare i32 @SDMMC_CmdBlockLength(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 64}
!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 108, !8, i64 124}
!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, !11, i64 28, !11, i64 32}
!13 = !{!6, !11, i64 68}
!14 = !{!10, !11, i64 16}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !11, i64 56}
!17 = !{!"", !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}


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