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

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

20:                                               ; preds = %4
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 2, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %60

27:                                               ; preds = %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %28, i32 0, i32 3
  store i32 1, ptr %29, align 4, !tbaa !14
  br label %30

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %33, i32 0, i32 4
  store volatile i32 2, ptr %34, align 8, !tbaa !11
  %35 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %35, ptr %10, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %47, %32
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %50

39:                                               ; preds = %36
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  store volatile i32 %41, ptr %42, align 4, !tbaa !9
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds i32, ptr %43, i32 1
  store ptr %44, ptr %12, align 8, !tbaa !5
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds i32, ptr %45, i32 1
  store ptr %46, ptr %11, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %39
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = add i32 %48, -1
  store i32 %49, ptr %10, align 4, !tbaa !9
  br label %36, !llvm.loop !15

50:                                               ; preds = %36
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %51, i32 0, i32 4
  store volatile i32 1, ptr %52, align 8, !tbaa !11
  br label %53

53:                                               ; preds = %50
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %54, i32 0, i32 3
  store i32 0, ptr %55, align 4, !tbaa !14
  br label %56

56:                                               ; preds = %53
  br label %57

57:                                               ; preds = %56
  br label %59

58:                                               ; preds = %4
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %60

59:                                               ; preds = %57
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %60

60:                                               ; preds = %59, %58, %26
  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
  %61 = load i32, ptr %5, align 4
  ret i32 %61
}

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 = { 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 = distinct !{!15, !16}
!16 = !{!"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_Write_32b(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %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
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %43

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

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

.lr.ph.preheader:                                 ; preds = %12
  %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
  %.021.prol = phi ptr [ %14, %.lr.ph.prol ], [ %2, %.lr.ph.preheader ]
  %.01520.prol = phi ptr [ %15, %.lr.ph.prol ], [ %1, %.lr.ph.preheader ]
  %.01619.prol = phi i32 [ %16, %.lr.ph.prol ], [ %3, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %13 = load i32, ptr %.021.prol, align 4, !tbaa !13
  store volatile i32 %13, ptr %.01520.prol, align 4, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %.021.prol, i64 4
  %15 = getelementptr inbounds i8, ptr %.01520.prol, i64 4
  %16 = add i32 %.01619.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
  %.021.unr = phi ptr [ %2, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.01520.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %15, %.lr.ph.prol ]
  %.01619.unr = phi i32 [ %3, %.lr.ph.preheader ], [ %16, %.lr.ph.prol ]
  %17 = icmp ult i32 %3, 8
  br i1 %17, label %._crit_edge, label %.lr.ph

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

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

43:                                               ; preds = %4, %8, %._crit_edge
  %.017 = phi i32 [ 0, %._crit_edge ], [ 2, %8 ], [ 1, %4 ]
  ret i32 %.017
}

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 = !{!11, !11, 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