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

; 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.SDRAM_HandleTypeDef = type { ptr, %struct.FMC_SDRAM_InitTypeDef, i32, i32, ptr }
%struct.FMC_SDRAM_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.__MDMA_HandleTypeDef = type { ptr, %struct.MDMA_InitTypeDef, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct.MDMA_InitTypeDef = type { i32, 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

; 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_SDRAM_Read_DMA(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %13, i32 0, i32 2
  %15 = load volatile i32, ptr %14, align 8, !tbaa !11
  store i32 %15, ptr %11, align 4, !tbaa !9
  %16 = load i32, ptr %11, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  store i32 2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

19:                                               ; preds = %4
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %25, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 4
  br i1 %24, label %25, label %72

25:                                               ; preds = %22, %19
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  store i32 2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

32:                                               ; preds = %26
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %33, i32 0, i32 3
  store i32 1, ptr %34, align 4, !tbaa !14
  br label %35

35:                                               ; preds = %32
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %38, i32 0, i32 2
  store volatile i32 2, ptr %39, align 8, !tbaa !11
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %45, i32 0, i32 5
  store ptr @SDRAM_DMACplt, ptr %46, align 8, !tbaa !16
  br label %52

47:                                               ; preds = %37
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %50, i32 0, i32 5
  store ptr @SDRAM_DMACpltProt, ptr %51, align 8, !tbaa !16
  br label %52

52:                                               ; preds = %47, %42
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = getelementptr inbounds %struct.__MDMA_HandleTypeDef, ptr %55, i32 0, i32 9
  store ptr @SDRAM_DMAError, ptr %56, align 8, !tbaa !19
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = ptrtoint ptr %60 to i32
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = ptrtoint ptr %62 to i32
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = mul i32 %64, 4
  %66 = call i32 @HAL_MDMA_Start_IT(ptr noundef %59, i32 noundef %61, i32 noundef %63, i32 noundef %65, i32 noundef 1)
  store i32 %66, ptr %10, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %52
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %68, i32 0, i32 3
  store i32 0, ptr %69, align 4, !tbaa !14
  br label %70

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  br label %73

72:                                               ; preds = %22
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %75, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

76:                                               ; preds = %74, %72, %31, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %77 = load i32, ptr %5, align 4
  ret i32 %77
}

; Function Attrs: nounwind uwtable
declare hidden void @SDRAM_DMACplt(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @SDRAM_DMACpltProt(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @SDRAM_DMAError(ptr noundef) #1

declare i32 @HAL_MDMA_Start_IT(ptr noundef, i32 noundef, i32 noundef, i32 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"", !6, i64 0, !13, i64 8, !10, i64 48, !10, i64 52, !6, i64 56}
!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, !10, i64 32, !10, i64 36}
!14 = !{!12, !10, i64 52}
!15 = !{!12, !6, i64 56}
!16 = !{!17, !6, i64 80}
!17 = !{!"__MDMA_HandleTypeDef", !6, i64 0, !18, i64 8, !10, i64 64, !10, i64 68, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !10, i64 148}
!18 = !{!"", !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, !10, i64 52}
!19 = !{!17, !6, i64 112}


; 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 @HAL_SDRAM_Read_DMA(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load volatile i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %25, label %8

8:                                                ; preds = %4
  %9 = icmp eq i32 %6, 1
  switch i32 %6, label %25 [
    i32 4, label %10
    i32 1, label %10
  ]

10:                                               ; preds = %8, %8
  %11 = getelementptr inbounds i8, ptr %0, i64 52
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %25, label %14

14:                                               ; preds = %10
  store i32 1, ptr %11, align 4, !tbaa !12
  store volatile i32 2, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %16, i64 80
  %SDRAM_DMACplt.SDRAM_DMACpltProt = select i1 %9, ptr @SDRAM_DMACplt, ptr @SDRAM_DMACpltProt
  store ptr %SDRAM_DMACplt.SDRAM_DMACpltProt, ptr %17, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %16, i64 112
  store ptr @SDRAM_DMAError, ptr %18, align 8, !tbaa !17
  %19 = ptrtoint ptr %1 to i64
  %20 = trunc i64 %19 to i32
  %21 = ptrtoint ptr %2 to i64
  %22 = trunc i64 %21 to i32
  %23 = shl i32 %3, 2
  %24 = tail call i32 @HAL_MDMA_Start_IT(ptr noundef nonnull %16, i32 noundef %20, i32 noundef %22, i32 noundef %23, i32 noundef 1) #2
  store i32 0, ptr %11, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %8, %10, %4, %14
  %.0 = phi i32 [ %24, %14 ], [ 2, %4 ], [ 2, %10 ], [ 1, %8 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @SDRAM_DMACplt(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @SDRAM_DMACpltProt(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @SDRAM_DMAError(ptr noundef) #0

declare i32 @HAL_MDMA_Start_IT(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 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, !11, i64 48}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 48, !11, i64 52, !7, i64 56}
!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, i64 32, !11, i64 36}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 52}
!13 = !{!6, !7, i64 56}
!14 = !{!15, !7, i64 80}
!15 = !{!"__MDMA_HandleTypeDef", !7, i64 0, !16, i64 8, !11, i64 64, !11, i64 68, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !11, i64 144, !11, i64 148}
!16 = !{!"", !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}
!17 = !{!15, !7, i64 112}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass