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

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

19:                                               ; preds = %22, %5
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = icmp ugt i32 %20, 0
  br i1 %21, label %22, label %69

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

69:                                               ; preds = %19
  %70 = load i64, ptr %12, align 8, !tbaa !11
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %70, ptr %71, align 8, !tbaa !11
  %72 = load i64, ptr %13, align 8, !tbaa !11
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 %72, ptr %73, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  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 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #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 = !{!"long", !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(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @arm_cmplx_dot_prod_q31(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %.not26 = icmp eq i32 %2, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.031 = phi ptr [ %8, %.lr.ph ], [ %0, %5 ]
  %.02230 = phi ptr [ %12, %.lr.ph ], [ %1, %5 ]
  %.02329 = phi i32 [ %30, %.lr.ph ], [ %2, %5 ]
  %.02428 = phi i64 [ %25, %.lr.ph ], [ 0, %5 ]
  %.02527 = phi i64 [ %29, %.lr.ph ], [ 0, %5 ]
  %6 = getelementptr inbounds i8, ptr %.031, i64 4
  %7 = load i32, ptr %.031, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %.031, i64 8
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %.02230, i64 4
  %11 = load i32, ptr %.02230, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.02230, i64 8
  %13 = load i32, ptr %10, align 4, !tbaa !5
  %14 = sext i32 %7 to i64
  %15 = sext i32 %11 to i64
  %16 = mul nsw i64 %15, %14
  %17 = ashr i64 %16, 14
  %18 = add nsw i64 %17, %.02428
  %19 = sext i32 %13 to i64
  %20 = mul nsw i64 %19, %14
  %21 = ashr i64 %20, 14
  %22 = sext i32 %9 to i64
  %23 = mul nsw i64 %19, %22
  %24 = ashr i64 %23, 14
  %25 = sub i64 %18, %24
  %26 = mul nsw i64 %15, %22
  %27 = ashr i64 %26, 14
  %28 = add i64 %27, %.02527
  %29 = add i64 %28, %21
  %30 = add i32 %.02329, -1
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.025.lcssa = phi i64 [ 0, %5 ], [ %29, %.lr.ph ]
  %.024.lcssa = phi i64 [ 0, %5 ], [ %25, %.lr.ph ]
  store i64 %.024.lcssa, ptr %3, align 8, !tbaa !11
  store i64 %.025.lcssa, ptr %4, align 8, !tbaa !11
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}


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