; 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.SRAM_HandleTypeDef = type { ptr, ptr, %struct.FMC_NORSRAM_InitTypeDef, i32, i32, ptr }
%struct.FMC_NORSRAM_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_SRAM_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.SRAM_HandleTypeDef, ptr %17, i32 0, i32 4
  %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, 1
  br i1 %21, label %25, label %22

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

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

26:                                               ; preds = %25
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SRAM_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 %14, align 4
  br label %66

32:                                               ; preds = %26
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SRAM_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.SRAM_HandleTypeDef, ptr %38, i32 0, i32 4
  store volatile i32 2, ptr %39, align 8, !tbaa !11
  %40 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %40, ptr %10, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %52, %37
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %55

44:                                               ; preds = %41
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load volatile i8, ptr %45, align 1, !tbaa !15
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  store i8 %46, ptr %47, align 1, !tbaa !15
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %12, align 8, !tbaa !5
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %11, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %44
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = add i32 %53, -1
  store i32 %54, ptr %10, align 4, !tbaa !9
  br label %41, !llvm.loop !16

55:                                               ; preds = %41
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %57, i32 0, i32 4
  store volatile i32 %56, ptr %58, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %55
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %60, i32 0, i32 3
  store i32 0, ptr %61, align 4, !tbaa !14
  br label %62

62:                                               ; preds = %59
  br label %63

63:                                               ; preds = %62
  br label %65

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

65:                                               ; preds = %63
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %66

66:                                               ; preds = %65, %64, %31
  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
  %67 = load i32, ptr %5, align 4
  ret i32 %67
}

; 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 80}
!12 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !10, i64 76, !10, i64 80, !6, i64 88}
!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, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56}
!14 = !{!12, !10, i64 76}
!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_SRAM_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 80
  %6 = load volatile i32, ptr %5, align 8, !tbaa !5
  switch i32 %6, label %42 [
    i32 4, label %7
    i32 1, label %7
  ]

7:                                                ; preds = %4, %4
  %8 = getelementptr inbounds i8, ptr %0, i64 76
  %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
  %.not22 = icmp eq i32 %3, 0
  br i1 %.not22, 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
  %.01925.prol = phi ptr [ %13, %.lr.ph.prol ], [ %2, %.lr.ph.preheader ]
  %.02024.prol = phi ptr [ %14, %.lr.ph.prol ], [ %1, %.lr.ph.preheader ]
  %.02123.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 %.02024.prol, align 1, !tbaa !13
  store i8 %12, ptr %.01925.prol, align 1, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %.01925.prol, i64 1
  %14 = getelementptr inbounds i8, ptr %.02024.prol, i64 1
  %15 = add i32 %.02123.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
  %.01925.unr = phi ptr [ %2, %.lr.ph.preheader ], [ %13, %.lr.ph.prol ]
  %.02024.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.02123.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
  %.01925 = phi ptr [ %39, %.lr.ph ], [ %.01925.unr, %.lr.ph.prol.loopexit ]
  %.02024 = phi ptr [ %40, %.lr.ph ], [ %.02024.unr, %.lr.ph.prol.loopexit ]
  %.02123 = phi i32 [ %41, %.lr.ph ], [ %.02123.unr, %.lr.ph.prol.loopexit ]
  %17 = load volatile i8, ptr %.02024, align 1, !tbaa !13
  store i8 %17, ptr %.01925, align 1, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %.01925, i64 1
  %19 = getelementptr inbounds i8, ptr %.02024, 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 %.01925, i64 2
  %22 = getelementptr inbounds i8, ptr %.02024, 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 %.01925, i64 3
  %25 = getelementptr inbounds i8, ptr %.02024, 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 %.01925, i64 4
  %28 = getelementptr inbounds i8, ptr %.02024, 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 %.01925, i64 5
  %31 = getelementptr inbounds i8, ptr %.02024, 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 %.01925, i64 6
  %34 = getelementptr inbounds i8, ptr %.02024, 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 %.01925, i64 7
  %37 = getelementptr inbounds i8, ptr %.02024, 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 %.01925, i64 8
  %40 = getelementptr inbounds i8, ptr %.02024, i64 8
  %41 = add i32 %.02123, -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

42:                                               ; preds = %4, %7, %._crit_edge
  %.0 = phi i32 [ 0, %._crit_edge ], [ 2, %7 ], [ 1, %4 ]
  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 80}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 76, !11, i64 80, !7, i64 88}
!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, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 76}
!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