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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_mat_scale_q31(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.arm_matrix_instance_q31, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  store ptr %19, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.arm_matrix_instance_q31, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  store ptr %22, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.arm_matrix_instance_q31, ptr %25, i32 0, i32 0
  %27 = load i16, ptr %26, align 8, !tbaa !14
  %28 = zext i16 %27 to i32
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.arm_matrix_instance_q31, ptr %29, i32 0, i32 1
  %31 = load i16, ptr %30, align 2, !tbaa !15
  %32 = zext i16 %31 to i32
  %33 = mul i32 %28, %32
  store i32 %33, ptr %11, align 4, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %34, ptr %12, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %61, %4
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = icmp ugt i32 %36, 0
  br i1 %37, label %38, label %67

38:                                               ; preds = %35
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %39, i32 1
  store ptr %40, ptr %9, align 8, !tbaa !5
  %41 = load i32, ptr %39, align 4, !tbaa !9
  store i32 %41, ptr %15, align 4, !tbaa !9
  %42 = load i32, ptr %15, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = mul nsw i64 %43, %45
  %47 = ashr i64 %46, 32
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %15, align 4, !tbaa !9
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = load i32, ptr %14, align 4, !tbaa !9
  %51 = shl i32 %49, %50
  store i32 %51, ptr %16, align 4, !tbaa !9
  %52 = load i32, ptr %15, align 4, !tbaa !9
  %53 = load i32, ptr %16, align 4, !tbaa !9
  %54 = load i32, ptr %14, align 4, !tbaa !9
  %55 = ashr i32 %53, %54
  %56 = icmp ne i32 %52, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %38
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = ashr i32 %58, 31
  %60 = xor i32 2147483647, %59
  store i32 %60, ptr %16, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %57, %38
  %62 = load i32, ptr %16, align 4, !tbaa !9
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds i32, ptr %63, i32 1
  store ptr %64, ptr %10, align 8, !tbaa !5
  store i32 %62, ptr %63, align 4, !tbaa !9
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = add i32 %65, -1
  store i32 %66, ptr %12, align 4, !tbaa !9
  br label %35, !llvm.loop !16

67:                                               ; preds = %35
  store i32 0, ptr %13, align 4, !tbaa !9
  %68 = load i32, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i32 %68
}

; 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, !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 = 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 nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @arm_mat_scale_q31(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = add nsw i32 %2, 1
  %6 = load i16, ptr %0, align 8, !tbaa !5
  %7 = zext i16 %6 to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 2
  %9 = load i16, ptr %8, align 2, !tbaa !11
  %10 = zext i16 %9 to i32
  %11 = mul nuw i32 %10, %7
  %.not24 = icmp eq i32 %11, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %12 = getelementptr inbounds i8, ptr %3, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = sext i32 %1 to i64
  %17 = zext i16 %6 to i64
  %18 = zext i16 %9 to i64
  %19 = mul nuw nsw i64 %17, %18
  %min.iters.check = icmp ult i64 %19, 4
  %20 = ptrtoint ptr %15 to i64
  %21 = ptrtoint ptr %13 to i64
  %22 = sub i64 %21, %20
  %diff.check = icmp ult i64 %22, 16
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %19, 4294967292
  %23 = shl nuw nsw i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %15, i64 %23
  %24 = shl nuw nsw i64 %n.vec, 2
  %ind.end28 = getelementptr i8, ptr %13, i64 %24
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end30 = sub i32 %11, %.cast
  %broadcast.splatinsert = insertelement <4 x i64> poison, i64 %16, i64 0
  %broadcast.splat = shufflevector <4 x i64> %broadcast.splatinsert, <4 x i64> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert34 = insertelement <4 x i32> poison, i32 %5, i64 0
  %broadcast.splat35 = shufflevector <4 x i32> %broadcast.splatinsert34, <4 x i32> 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 %15, i64 %offset.idx
  %offset.idx32 = shl i64 %index, 2
  %next.gep33 = getelementptr i8, ptr %13, i64 %offset.idx32
  %wide.load = load <4 x i32>, ptr %next.gep, align 4, !tbaa !13
  %25 = sext <4 x i32> %wide.load to <4 x i64>
  %26 = mul nsw <4 x i64> %broadcast.splat, %25
  %27 = lshr <4 x i64> %26, <i64 32, i64 32, i64 32, i64 32>
  %28 = trunc nuw <4 x i64> %27 to <4 x i32>
  %29 = shl <4 x i32> %28, %broadcast.splat35
  %30 = ashr exact <4 x i32> %29, %broadcast.splat35
  %31 = icmp eq <4 x i32> %30, %28
  %32 = icmp sgt <4 x i64> %26, <i64 -1, i64 -1, i64 -1, i64 -1>
  %33 = select <4 x i1> %32, <4 x i32> <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>, <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
  %34 = select <4 x i1> %31, <4 x i32> %29, <4 x i32> %33
  store <4 x i32> %34, ptr %next.gep33, align 4, !tbaa !13
  %index.next = add nuw i64 %index, 4
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %19, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.01927.ph = phi ptr [ %15, %.lr.ph ], [ %ind.end, %middle.block ]
  %.02026.ph = phi ptr [ %13, %.lr.ph ], [ %ind.end28, %middle.block ]
  %.02125.ph = phi i32 [ %11, %.lr.ph ], [ %ind.end30, %middle.block ]
  %xtraiter = and i32 %.02125.ph, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %36 = getelementptr inbounds i8, ptr %.01927.ph, i64 4
  %37 = load i32, ptr %.01927.ph, align 4, !tbaa !13
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %38, %16
  %40 = lshr i64 %39, 32
  %41 = trunc nuw i64 %40 to i32
  %42 = shl i32 %41, %5
  %43 = ashr exact i32 %42, %5
  %.not23.prol = icmp eq i32 %43, %41
  %44 = icmp sgt i64 %39, -1
  %45 = select i1 %44, i32 2147483647, i32 -2147483648
  %.0.prol = select i1 %.not23.prol, i32 %42, i32 %45
  %46 = getelementptr inbounds i8, ptr %.02026.ph, i64 4
  store i32 %.0.prol, ptr %.02026.ph, align 4, !tbaa !13
  %47 = add nsw i32 %.02125.ph, -1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.01927.unr = phi ptr [ %.01927.ph, %scalar.ph.preheader ], [ %36, %scalar.ph.prol ]
  %.02026.unr = phi ptr [ %.02026.ph, %scalar.ph.preheader ], [ %46, %scalar.ph.prol ]
  %.02125.unr = phi i32 [ %.02125.ph, %scalar.ph.preheader ], [ %47, %scalar.ph.prol ]
  %48 = icmp eq i32 %.02125.ph, 1
  br i1 %48, label %._crit_edge, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.01927 = phi ptr [ %60, %scalar.ph ], [ %.01927.unr, %scalar.ph.prol.loopexit ]
  %.02026 = phi ptr [ %70, %scalar.ph ], [ %.02026.unr, %scalar.ph.prol.loopexit ]
  %.02125 = phi i32 [ %71, %scalar.ph ], [ %.02125.unr, %scalar.ph.prol.loopexit ]
  %49 = getelementptr inbounds i8, ptr %.01927, i64 4
  %50 = load i32, ptr %.01927, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = mul nsw i64 %51, %16
  %53 = lshr i64 %52, 32
  %54 = trunc nuw i64 %53 to i32
  %55 = shl i32 %54, %5
  %56 = ashr exact i32 %55, %5
  %.not23 = icmp eq i32 %56, %54
  %57 = icmp sgt i64 %52, -1
  %58 = select i1 %57, i32 2147483647, i32 -2147483648
  %.0 = select i1 %.not23, i32 %55, i32 %58
  %59 = getelementptr inbounds i8, ptr %.02026, i64 4
  store i32 %.0, ptr %.02026, align 4, !tbaa !13
  %60 = getelementptr inbounds i8, ptr %.01927, i64 8
  %61 = load i32, ptr %49, align 4, !tbaa !13
  %62 = sext i32 %61 to i64
  %63 = mul nsw i64 %62, %16
  %64 = lshr i64 %63, 32
  %65 = trunc nuw i64 %64 to i32
  %66 = shl i32 %65, %5
  %67 = ashr exact i32 %66, %5
  %.not23.1 = icmp eq i32 %67, %65
  %68 = icmp sgt i64 %63, -1
  %69 = select i1 %68, i32 2147483647, i32 -2147483648
  %.0.1 = select i1 %.not23.1, i32 %66, i32 %69
  %70 = getelementptr inbounds i8, ptr %.02026, i64 8
  store i32 %.0.1, ptr %59, align 4, !tbaa !13
  %71 = add i32 %.02125, -2
  %.not.1 = icmp eq i32 %71, 0
  br i1 %.not.1, label %._crit_edge, label %scalar.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %4
  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 = !{!"int", !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, !16, !17}


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