; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/CMSIS/DSP/Source/MatrixFunctions (arm_mat_scale_f32)

; 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.arm_matrix_instance_f32 = type { i16, i16, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_mat_scale_f32(ptr noundef %0, float noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca float, 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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.arm_matrix_instance_f32, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.arm_matrix_instance_f32, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.arm_matrix_instance_f32, ptr %18, i32 0, i32 0
  %20 = load i16, ptr %19, align 8, !tbaa !14
  %21 = zext i16 %20 to i32
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.arm_matrix_instance_f32, ptr %22, i32 0, i32 1
  %24 = load i16, ptr %23, align 2, !tbaa !15
  %25 = zext i16 %24 to i32
  %26 = mul i32 %21, %25
  store i32 %26, ptr %9, align 4, !tbaa !16
  %27 = load i32, ptr %9, align 4, !tbaa !16
  store i32 %27, ptr %10, align 4, !tbaa !16
  br label %28

28:                                               ; preds = %31, %3
  %29 = load i32, ptr %10, align 4, !tbaa !16
  %30 = icmp ugt i32 %29, 0
  br i1 %30, label %31, label %41

31:                                               ; preds = %28
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds float, ptr %32, i32 1
  store ptr %33, ptr %7, align 8, !tbaa !5
  %34 = load float, ptr %32, align 4, !tbaa !9
  %35 = load float, ptr %5, align 4, !tbaa !9
  %36 = fmul float %34, %35
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds float, ptr %37, i32 1
  store ptr %38, ptr %8, align 8, !tbaa !5
  store float %36, ptr %37, align 4, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !16
  %40 = add i32 %39, -1
  store i32 %40, ptr %10, align 4, !tbaa !16
  br label %28, !llvm.loop !18

41:                                               ; preds = %28
  store i32 0, ptr %11, align 4, !tbaa !16
  %42 = load i32, ptr %11, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 %42
}

; 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 = !{!"float", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"", !13, i64 0, !13, i64 2, !6, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!12, !13, i64 2}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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 nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @arm_mat_scale_f32(ptr nocapture noundef readonly %0, float noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load i16, ptr %0, align 8, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = getelementptr inbounds i8, ptr %0, i64 2
  %7 = load i16, ptr %6, align 2, !tbaa !11
  %8 = zext i16 %7 to i32
  %9 = mul nuw i32 %8, %5
  %.not12 = icmp eq i32 %9, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = zext i16 %4 to i64
  %15 = zext i16 %7 to i64
  %16 = mul nuw nsw i64 %14, %15
  %min.iters.check = icmp ult i64 %16, 8
  %17 = ptrtoint ptr %13 to i64
  %18 = ptrtoint ptr %11 to i64
  %19 = sub i64 %18, %17
  %diff.check = icmp ult i64 %19, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %.lr.ph.preheader27, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %16, 4294967288
  %20 = shl nuw nsw i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %13, i64 %20
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end16 = sub i32 %9, %.cast
  %21 = shl nuw nsw i64 %n.vec, 2
  %ind.end18 = getelementptr i8, ptr %11, i64 %21
  %broadcast.splatinsert = insertelement <4 x float> poison, float %1, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %13, i64 %offset.idx
  %offset.idx21 = shl i64 %index, 2
  %next.gep22 = getelementptr i8, ptr %11, i64 %offset.idx21
  %22 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <4 x float>, ptr %next.gep, align 4, !tbaa !13
  %wide.load24 = load <4 x float>, ptr %22, align 4, !tbaa !13
  %23 = fmul <4 x float> %wide.load, %broadcast.splat
  %24 = fmul <4 x float> %wide.load24, %broadcast.splat
  %25 = getelementptr i8, ptr %next.gep22, i64 16
  store <4 x float> %23, ptr %next.gep22, align 4, !tbaa !13
  store <4 x float> %24, ptr %25, align 4, !tbaa !13
  %index.next = add nuw i64 %index, 8
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %16, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader27

.lr.ph.preheader27:                               ; preds = %middle.block, %.lr.ph.preheader
  %.015.ph = phi ptr [ %13, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01014.ph = phi i32 [ %9, %.lr.ph.preheader ], [ %ind.end16, %middle.block ]
  %.01113.ph = phi ptr [ %11, %.lr.ph.preheader ], [ %ind.end18, %middle.block ]
  %27 = add i32 %.01014.ph, -1
  %xtraiter = and i32 %.01014.ph, 3
  %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.preheader27, %.lr.ph.prol
  %.015.prol = phi ptr [ %28, %.lr.ph.prol ], [ %.015.ph, %.lr.ph.preheader27 ]
  %.01014.prol = phi i32 [ %32, %.lr.ph.prol ], [ %.01014.ph, %.lr.ph.preheader27 ]
  %.01113.prol = phi ptr [ %31, %.lr.ph.prol ], [ %.01113.ph, %.lr.ph.preheader27 ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader27 ]
  %28 = getelementptr inbounds i8, ptr %.015.prol, i64 4
  %29 = load float, ptr %.015.prol, align 4, !tbaa !13
  %30 = fmul float %29, %1
  %31 = getelementptr inbounds i8, ptr %.01113.prol, i64 4
  store float %30, ptr %.01113.prol, align 4, !tbaa !13
  %32 = add i32 %.01014.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 !19

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader27
  %.015.unr = phi ptr [ %.015.ph, %.lr.ph.preheader27 ], [ %28, %.lr.ph.prol ]
  %.01014.unr = phi i32 [ %.01014.ph, %.lr.ph.preheader27 ], [ %32, %.lr.ph.prol ]
  %.01113.unr = phi ptr [ %.01113.ph, %.lr.ph.preheader27 ], [ %31, %.lr.ph.prol ]
  %33 = icmp ult i32 %27, 3
  br i1 %33, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.015 = phi ptr [ %46, %.lr.ph ], [ %.015.unr, %.lr.ph.prol.loopexit ]
  %.01014 = phi i32 [ %50, %.lr.ph ], [ %.01014.unr, %.lr.ph.prol.loopexit ]
  %.01113 = phi ptr [ %49, %.lr.ph ], [ %.01113.unr, %.lr.ph.prol.loopexit ]
  %34 = getelementptr inbounds i8, ptr %.015, i64 4
  %35 = load float, ptr %.015, align 4, !tbaa !13
  %36 = fmul float %35, %1
  %37 = getelementptr inbounds i8, ptr %.01113, i64 4
  store float %36, ptr %.01113, align 4, !tbaa !13
  %38 = getelementptr inbounds i8, ptr %.015, i64 8
  %39 = load float, ptr %34, align 4, !tbaa !13
  %40 = fmul float %39, %1
  %41 = getelementptr inbounds i8, ptr %.01113, i64 8
  store float %40, ptr %37, align 4, !tbaa !13
  %42 = getelementptr inbounds i8, ptr %.015, i64 12
  %43 = load float, ptr %38, align 4, !tbaa !13
  %44 = fmul float %43, %1
  %45 = getelementptr inbounds i8, ptr %.01113, i64 12
  store float %44, ptr %41, align 4, !tbaa !13
  %46 = getelementptr inbounds i8, ptr %.015, i64 16
  %47 = load float, ptr %42, align 4, !tbaa !13
  %48 = fmul float %47, %1
  %49 = getelementptr inbounds i8, ptr %.01113, i64 16
  store float %48, ptr %45, align 4, !tbaa !13
  %50 = add i32 %.01014, -4
  %.not.3 = icmp eq i32 %50, 0
  br i1 %.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !21

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %3
  ret i32 0
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 2, !10, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 2}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.unroll.disable"}
!21 = distinct !{!21, !16, !17}


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