; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/CMSIS/DSP/Source/ComplexMathFunctions (arm_cmplx_mult_cmplx_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"

; Function Attrs: nounwind uwtable
define dso_local void @arm_cmplx_mult_cmplx_q15(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca i16, align 2
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #2
  %14 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %14, ptr %9, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %18, %4
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = icmp ugt i32 %16, 0
  br i1 %17, label %18, label %65

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i16, ptr %19, i32 1
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load i16, ptr %19, align 2, !tbaa !11
  store i16 %21, ptr %10, align 2, !tbaa !11
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i16, ptr %22, i32 1
  store ptr %23, ptr %5, align 8, !tbaa !5
  %24 = load i16, ptr %22, align 2, !tbaa !11
  store i16 %24, ptr %11, align 2, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds i16, ptr %25, i32 1
  store ptr %26, ptr %6, align 8, !tbaa !5
  %27 = load i16, ptr %25, align 2, !tbaa !11
  store i16 %27, ptr %12, align 2, !tbaa !11
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds i16, ptr %28, i32 1
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load i16, ptr %28, align 2, !tbaa !11
  store i16 %30, ptr %13, align 2, !tbaa !11
  %31 = load i16, ptr %10, align 2, !tbaa !11
  %32 = sext i16 %31 to i32
  %33 = load i16, ptr %12, align 2, !tbaa !11
  %34 = sext i16 %33 to i32
  %35 = mul nsw i32 %32, %34
  %36 = ashr i32 %35, 17
  %37 = load i16, ptr %11, align 2, !tbaa !11
  %38 = sext i16 %37 to i32
  %39 = load i16, ptr %13, align 2, !tbaa !11
  %40 = sext i16 %39 to i32
  %41 = mul nsw i32 %38, %40
  %42 = ashr i32 %41, 17
  %43 = sub nsw i32 %36, %42
  %44 = trunc i32 %43 to i16
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds i16, ptr %45, i32 1
  store ptr %46, ptr %7, align 8, !tbaa !5
  store i16 %44, ptr %45, align 2, !tbaa !11
  %47 = load i16, ptr %10, align 2, !tbaa !11
  %48 = sext i16 %47 to i32
  %49 = load i16, ptr %13, align 2, !tbaa !11
  %50 = sext i16 %49 to i32
  %51 = mul nsw i32 %48, %50
  %52 = ashr i32 %51, 17
  %53 = load i16, ptr %11, align 2, !tbaa !11
  %54 = sext i16 %53 to i32
  %55 = load i16, ptr %12, align 2, !tbaa !11
  %56 = sext i16 %55 to i32
  %57 = mul nsw i32 %54, %56
  %58 = ashr i32 %57, 17
  %59 = add nsw i32 %52, %58
  %60 = trunc i32 %59 to i16
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds i16, ptr %61, i32 1
  store ptr %62, ptr %7, align 8, !tbaa !5
  store i16 %60, ptr %61, align 2, !tbaa !11
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = add i32 %63, -1
  store i32 %64, ptr %9, align 4, !tbaa !9
  br label %15, !llvm.loop !13

65:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

; 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 void @arm_cmplx_mult_cmplx_q15(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not19 = icmp eq i32 %3, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %5 = zext i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 8
  br i1 %min.iters.check, label %.lr.ph.preheader43, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %6 = add i32 %3, -1
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = add nuw nsw i64 %8, 4
  %scevgep = getelementptr i8, ptr %2, i64 %9
  %scevgep24 = getelementptr i8, ptr %0, i64 %9
  %scevgep25 = getelementptr i8, ptr %1, i64 %9
  %bound0 = icmp ugt ptr %scevgep24, %2
  %bound1 = icmp ugt ptr %scevgep, %0
  %found.conflict = and i1 %bound0, %bound1
  %bound026 = icmp ugt ptr %scevgep25, %2
  %bound127 = icmp ugt ptr %scevgep, %1
  %found.conflict28 = and i1 %bound026, %bound127
  %conflict.rdx = or i1 %found.conflict, %found.conflict28
  br i1 %conflict.rdx, label %.lr.ph.preheader43, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %5, 4294967292
  %10 = shl nuw nsw i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %0, i64 %10
  %11 = shl nuw nsw i64 %n.vec, 2
  %ind.end29 = getelementptr i8, ptr %1, i64 %11
  %12 = shl nuw nsw i64 %n.vec, 2
  %ind.end31 = getelementptr i8, ptr %2, i64 %12
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end33 = sub i32 %3, %.cast
  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 %0, i64 %offset.idx
  %offset.idx35 = shl i64 %index, 2
  %next.gep36 = getelementptr i8, ptr %1, i64 %offset.idx35
  %offset.idx37 = shl i64 %index, 2
  %next.gep38 = getelementptr i8, ptr %2, i64 %offset.idx37
  %wide.vec = load <8 x i16>, ptr %next.gep, align 2, !tbaa !5
  %strided.vec = shufflevector <8 x i16> %wide.vec, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec39 = shufflevector <8 x i16> %wide.vec, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %wide.vec40 = load <8 x i16>, ptr %next.gep36, align 2, !tbaa !5
  %strided.vec41 = shufflevector <8 x i16> %wide.vec40, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec42 = shufflevector <8 x i16> %wide.vec40, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %13 = sext <4 x i16> %strided.vec to <4 x i32>
  %14 = sext <4 x i16> %strided.vec41 to <4 x i32>
  %15 = mul nsw <4 x i32> %14, %13
  %16 = ashr <4 x i32> %15, <i32 17, i32 17, i32 17, i32 17>
  %17 = sext <4 x i16> %strided.vec39 to <4 x i32>
  %18 = sext <4 x i16> %strided.vec42 to <4 x i32>
  %19 = mul nsw <4 x i32> %18, %17
  %20 = ashr <4 x i32> %19, <i32 17, i32 17, i32 17, i32 17>
  %21 = sub nsw <4 x i32> %16, %20
  %22 = mul nsw <4 x i32> %18, %13
  %23 = ashr <4 x i32> %22, <i32 17, i32 17, i32 17, i32 17>
  %24 = mul nsw <4 x i32> %14, %17
  %25 = ashr <4 x i32> %24, <i32 17, i32 17, i32 17, i32 17>
  %26 = add nsw <4 x i32> %23, %25
  %27 = shufflevector <4 x i32> %21, <4 x i32> %26, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>
  %interleaved.vec = trunc nsw <8 x i32> %27 to <8 x i16>
  store <8 x i16> %interleaved.vec, ptr %next.gep38, align 2, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !9

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

.lr.ph.preheader43:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.023.ph = phi ptr [ %0, %vector.memcheck ], [ %0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01622.ph = phi ptr [ %1, %vector.memcheck ], [ %1, %.lr.ph.preheader ], [ %ind.end29, %middle.block ]
  %.01721.ph = phi ptr [ %2, %vector.memcheck ], [ %2, %.lr.ph.preheader ], [ %ind.end31, %middle.block ]
  %.01820.ph = phi i32 [ %3, %vector.memcheck ], [ %3, %.lr.ph.preheader ], [ %ind.end33, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader43, %.lr.ph
  %.023 = phi ptr [ %31, %.lr.ph ], [ %.023.ph, %.lr.ph.preheader43 ]
  %.01622 = phi ptr [ %35, %.lr.ph ], [ %.01622.ph, %.lr.ph.preheader43 ]
  %.01721 = phi ptr [ %54, %.lr.ph ], [ %.01721.ph, %.lr.ph.preheader43 ]
  %.01820 = phi i32 [ %55, %.lr.ph ], [ %.01820.ph, %.lr.ph.preheader43 ]
  %29 = getelementptr inbounds i8, ptr %.023, i64 2
  %30 = load i16, ptr %.023, align 2, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.023, i64 4
  %32 = load i16, ptr %29, align 2, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.01622, i64 2
  %34 = load i16, ptr %.01622, align 2, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %.01622, i64 4
  %36 = load i16, ptr %33, align 2, !tbaa !5
  %37 = sext i16 %30 to i32
  %38 = sext i16 %34 to i32
  %39 = mul nsw i32 %38, %37
  %40 = ashr i32 %39, 17
  %41 = sext i16 %32 to i32
  %42 = sext i16 %36 to i32
  %43 = mul nsw i32 %42, %41
  %44 = ashr i32 %43, 17
  %45 = sub nsw i32 %40, %44
  %46 = trunc nsw i32 %45 to i16
  %47 = getelementptr inbounds i8, ptr %.01721, i64 2
  store i16 %46, ptr %.01721, align 2, !tbaa !5
  %48 = mul nsw i32 %42, %37
  %49 = ashr i32 %48, 17
  %50 = mul nsw i32 %38, %41
  %51 = ashr i32 %50, 17
  %52 = add nsw i32 %49, %51
  %53 = trunc nsw i32 %52 to i16
  %54 = getelementptr inbounds i8, ptr %.01721, i64 4
  store i16 %53, ptr %47, align 2, !tbaa !5
  %55 = add i32 %.01820, -1
  %.not = icmp eq i32 %55, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %4
  ret void
}

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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11}


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