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

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

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

33:                                               ; preds = %36, %4
  %34 = load i32, ptr %12, align 4, !tbaa !11
  %35 = icmp ugt i32 %34, 0
  br i1 %35, label %36, label %52

36:                                               ; preds = %33
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds i16, ptr %37, i32 1
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = load i16, ptr %37, align 2, !tbaa !9
  %40 = sext i16 %39 to i32
  %41 = load i16, ptr %6, align 2, !tbaa !9
  %42 = sext i16 %41 to i32
  %43 = mul nsw i32 %40, %42
  %44 = load i32, ptr %14, align 4, !tbaa !11
  %45 = ashr i32 %43, %44
  %46 = call i32 @__SSAT(i32 noundef %45, i32 noundef 16)
  %47 = trunc i32 %46 to i16
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds i16, ptr %48, i32 1
  store ptr %49, ptr %10, align 8, !tbaa !5
  store i16 %47, ptr %48, align 2, !tbaa !9
  %50 = load i32, ptr %12, align 4, !tbaa !11
  %51 = add i32 %50, -1
  store i32 %51, ptr %12, align 4, !tbaa !11
  br label %33, !llvm.loop !17

52:                                               ; preds = %33
  store i32 0, ptr %13, align 4, !tbaa !11
  %53 = load i32, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 %53
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @__SSAT(i32 noundef, i32 noundef) #2

; 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 = { alwaysinline 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 #3 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"", !10, i64 0, !10, i64 2, !6, i64 8}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 2}
!17 = distinct !{!17, !18}
!18 = !{!"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: nounwind uwtable
define dso_local noundef i32 @arm_mat_scale_q15(ptr nocapture noundef readonly %0, i16 noundef signext %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = sub nsw i32 15, %2
  %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
  %.not14 = icmp eq i32 %11, 0
  br i1 %.not14, 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 i16 %1 to i32
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %.017 = phi ptr [ %15, %.lr.ph ], [ %18, %17 ]
  %.01216 = phi ptr [ %13, %.lr.ph ], [ %25, %17 ]
  %.01315 = phi i32 [ %11, %.lr.ph ], [ %26, %17 ]
  %18 = getelementptr inbounds i8, ptr %.017, i64 2
  %19 = load i16, ptr %.017, align 2, !tbaa !13
  %20 = sext i16 %19 to i32
  %21 = mul nsw i32 %20, %16
  %22 = ashr i32 %21, %5
  %23 = tail call i32 @__SSAT(i32 noundef %22, i32 noundef 16)
  %24 = trunc i32 %23 to i16
  %25 = getelementptr inbounds i8, ptr %.01216, i64 2
  store i16 %24, ptr %.01216, align 2, !tbaa !13
  %26 = add i32 %.01315, -1
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %._crit_edge, label %17, !llvm.loop !14

._crit_edge:                                      ; preds = %17, %4
  ret i32 0
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @__SSAT(i32 noundef, i32 noundef) local_unnamed_addr #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 = { alwaysinline 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, !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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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