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

; 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.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.HAL_MMC_CardInfoTypeDef = type { i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_MMC_InitCard(ptr noundef %0) #0 {
  %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 = getelementptr inbounds %struct.SDMMC_InitTypeDef, ptr %5, i32 0, i32 4
  store i32 250, ptr %12, align 4, !tbaa !15
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = call i32 @SDMMC_Init(ptr noundef %15, ptr noundef byval(%struct.SDMMC_InitTypeDef) align 8 %5)
  store i32 %16, ptr %6, align 4, !tbaa !19
  %17 = load i32, ptr %6, align 4, !tbaa !19
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %20

19:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

20:                                               ; preds = %1
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = call i32 @SDMMC_PowerState_ON(ptr noundef %23)
  store i32 %24, ptr %6, align 4, !tbaa !19
  %25 = load i32, ptr %6, align 4, !tbaa !19
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %28

27:                                               ; preds = %20
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

28:                                               ; preds = %20
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call i32 @MMC_PowerON(ptr noundef %29)
  store i32 %30, ptr %4, align 4, !tbaa !19
  %31 = load i32, ptr %4, align 4, !tbaa !19
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %28
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %34, i32 0, i32 8
  store volatile i32 1, ptr %35, align 8, !tbaa !20
  %36 = load i32, ptr %4, align 4, !tbaa !19
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %37, i32 0, i32 9
  %39 = load volatile i32, ptr %38, align 4, !tbaa !21
  %40 = or i32 %39, %36
  store volatile i32 %40, ptr %38, align 4, !tbaa !21
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

41:                                               ; preds = %28
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call i32 @MMC_InitCard(ptr noundef %42)
  store i32 %43, ptr %4, align 4, !tbaa !19
  %44 = load i32, ptr %4, align 4, !tbaa !19
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %54

46:                                               ; preds = %41
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %47, i32 0, i32 8
  store volatile i32 1, ptr %48, align 8, !tbaa !20
  %49 = load i32, ptr %4, align 4, !tbaa !19
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.MMC_HandleTypeDef, ptr %50, i32 0, i32 9
  %52 = load volatile i32, ptr %51, align 4, !tbaa !21
  %53 = or i32 %52, %49
  store volatile i32 %53, ptr %51, align 4, !tbaa !21
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

54:                                               ; preds = %41
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

55:                                               ; preds = %54, %46, %33, %27, %19
  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
  %56 = load i32, ptr %2, align 4
  ret i32 %56
}

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

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

declare i32 @SDMMC_PowerState_ON(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @MMC_PowerON(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @MMC_InitCard(ptr noundef) #0

; 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, !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 = !{!10, !11, i64 16}
!16 = !{!17, !6, i64 0}
!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 100, !7, i64 116, !7, i64 132}
!18 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!19 = !{!11, !11, i64 0}
!20 = !{!17, !11, i64 64}
!21 = !{!17, !11, 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"

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_MMC_InitCard(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.SDMMC_InitTypeDef, align 8
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  store i32 250, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %0, align 8, !tbaa !10
  %5 = tail call i32 @SDMMC_Init(ptr noundef %4, ptr noundef nonnull byval(%struct.SDMMC_InitTypeDef) align 8 %2) #4
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %19, label %7

7:                                                ; preds = %1
  %8 = load ptr, ptr %0, align 8, !tbaa !10
  %9 = tail call i32 @SDMMC_PowerState_ON(ptr noundef %8) #4
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %19, label %11

11:                                               ; preds = %7
  %12 = tail call i32 @MMC_PowerON(ptr noundef nonnull %0)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %.sink.split

13:                                               ; preds = %11
  %14 = tail call i32 @MMC_InitCard(ptr noundef nonnull %0)
  %.not16 = icmp eq i32 %14, 0
  br i1 %.not16, label %19, label %.sink.split

.sink.split:                                      ; preds = %13, %11
  %.sink19 = phi i32 [ %12, %11 ], [ %14, %13 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 64
  store volatile i32 1, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 68
  %17 = load volatile i32, ptr %16, align 4, !tbaa !15
  %18 = or i32 %17, %.sink19
  store volatile i32 %18, ptr %16, align 4, !tbaa !15
  br label %19

19:                                               ; preds = %.sink.split, %13, %7, %1
  %.0 = phi i32 [ 1, %1 ], [ 1, %7 ], [ 0, %13 ], [ 1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #4
  ret i32 %.0
}

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

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

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

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

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

; 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 = { 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 = { mustprogress 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 = { 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, !7, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !6, i64 8, !7, i64 28, !12, i64 32, !7, i64 40, !12, i64 48, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !13, i64 72, !8, i64 100, !8, i64 116, !8, i64 132}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!14 = !{!11, !7, i64 64}
!15 = !{!11, !7, i64 68}


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