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

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

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

22:                                               ; preds = %4
  store i32 2, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %71

23:                                               ; preds = %4
  %24 = load i32, ptr %13, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %29, label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 4
  br i1 %28, label %29, label %68

29:                                               ; preds = %26, %23
  br label %30

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

35:                                               ; preds = %30
  store i32 2, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %71

36:                                               ; preds = %30
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %37, i32 0, i32 3
  store i32 1, ptr %38, align 4, !tbaa !14
  br label %39

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %42, i32 0, i32 2
  store volatile i32 2, ptr %43, align 8, !tbaa !11
  %44 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %44, ptr %10, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %56, %41
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %59

48:                                               ; preds = %45
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load volatile i8, ptr %49, align 1, !tbaa !15
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  store i8 %50, ptr %51, align 1, !tbaa !15
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i32 1
  store ptr %53, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %11, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %48
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = add i32 %57, -1
  store i32 %58, ptr %10, align 4, !tbaa !9
  br label %45, !llvm.loop !16

59:                                               ; preds = %45
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %61, i32 0, i32 2
  store volatile i32 %60, ptr %62, align 8, !tbaa !11
  br label %63

63:                                               ; preds = %59
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %64, i32 0, i32 3
  store i32 0, ptr %65, align 4, !tbaa !14
  br label %66

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  br label %69

68:                                               ; preds = %26
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %71

69:                                               ; preds = %67
  br label %70

70:                                               ; preds = %69
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %71

71:                                               ; preds = %70, %68, %35, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %72 = load i32, ptr %5, align 4
  ret i32 %72
}

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

; 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 = { 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 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_SDRAM_Read_8b(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %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
  switch i32 %6, label %.fold.split [
    i32 2, label %42
    i32 4, label %7
    i32 1, label %7
  ]

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

11:                                               ; preds = %7
  store i32 1, ptr %8, align 4, !tbaa !12
  store volatile i32 2, ptr %5, align 8, !tbaa !5
  %.not24 = icmp eq i32 %3, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %11
  %xtraiter = and i32 %3, 7
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.02027.prol = phi ptr [ %13, %.lr.ph.prol ], [ %2, %.lr.ph.preheader ]
  %.02126.prol = phi ptr [ %14, %.lr.ph.prol ], [ %1, %.lr.ph.preheader ]
  %.02225.prol = phi i32 [ %15, %.lr.ph.prol ], [ %3, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %12 = load volatile i8, ptr %.02126.prol, align 1, !tbaa !13
  store i8 %12, ptr %.02027.prol, align 1, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %.02027.prol, i64 1
  %14 = getelementptr inbounds i8, ptr %.02126.prol, i64 1
  %15 = add i32 %.02225.prol, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !14

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.02027.unr = phi ptr [ %2, %.lr.ph.preheader ], [ %13, %.lr.ph.prol ]
  %.02126.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.02225.unr = phi i32 [ %3, %.lr.ph.preheader ], [ %15, %.lr.ph.prol ]
  %16 = icmp ult i32 %3, 8
  br i1 %16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.02027 = phi ptr [ %39, %.lr.ph ], [ %.02027.unr, %.lr.ph.prol.loopexit ]
  %.02126 = phi ptr [ %40, %.lr.ph ], [ %.02126.unr, %.lr.ph.prol.loopexit ]
  %.02225 = phi i32 [ %41, %.lr.ph ], [ %.02225.unr, %.lr.ph.prol.loopexit ]
  %17 = load volatile i8, ptr %.02126, align 1, !tbaa !13
  store i8 %17, ptr %.02027, align 1, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %.02027, i64 1
  %19 = getelementptr inbounds i8, ptr %.02126, i64 1
  %20 = load volatile i8, ptr %19, align 1, !tbaa !13
  store i8 %20, ptr %18, align 1, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %.02027, i64 2
  %22 = getelementptr inbounds i8, ptr %.02126, i64 2
  %23 = load volatile i8, ptr %22, align 1, !tbaa !13
  store i8 %23, ptr %21, align 1, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %.02027, i64 3
  %25 = getelementptr inbounds i8, ptr %.02126, i64 3
  %26 = load volatile i8, ptr %25, align 1, !tbaa !13
  store i8 %26, ptr %24, align 1, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %.02027, i64 4
  %28 = getelementptr inbounds i8, ptr %.02126, i64 4
  %29 = load volatile i8, ptr %28, align 1, !tbaa !13
  store i8 %29, ptr %27, align 1, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %.02027, i64 5
  %31 = getelementptr inbounds i8, ptr %.02126, i64 5
  %32 = load volatile i8, ptr %31, align 1, !tbaa !13
  store i8 %32, ptr %30, align 1, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %.02027, i64 6
  %34 = getelementptr inbounds i8, ptr %.02126, i64 6
  %35 = load volatile i8, ptr %34, align 1, !tbaa !13
  store i8 %35, ptr %33, align 1, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %.02027, i64 7
  %37 = getelementptr inbounds i8, ptr %.02126, i64 7
  %38 = load volatile i8, ptr %37, align 1, !tbaa !13
  store i8 %38, ptr %36, align 1, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %.02027, i64 8
  %40 = getelementptr inbounds i8, ptr %.02126, i64 8
  %41 = add i32 %.02225, -8
  %.not.7 = icmp eq i32 %41, 0
  br i1 %.not.7, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %11
  store volatile i32 %6, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %42

.fold.split:                                      ; preds = %4
  br label %42

42:                                               ; preds = %4, %.fold.split, %7, %._crit_edge
  %.0 = phi i32 [ 0, %._crit_edge ], [ %6, %4 ], [ 2, %7 ], [ 1, %.fold.split ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse 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" }

!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 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass