; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/STM32_AI_AudioPreprocessing_Library/Src (window)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

12:                                               ; preds = %41, %5
  %13 = load i32, ptr %11, align 4, !tbaa !9
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp ult i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %44

17:                                               ; preds = %12
  %18 = load double, ptr %8, align 8, !tbaa !11
  %19 = load double, ptr %9, align 8, !tbaa !11
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = uitofp i32 %20 to double
  %22 = fmul double 0x401921FB54442D18, %21
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = uitofp i32 %23 to double
  %25 = fdiv double %22, %24
  %26 = call double @cos(double noundef %25) #4
  %27 = fneg double %19
  %28 = call double @llvm.fmuladd.f64(double %27, double %26, double %18)
  %29 = load double, ptr %10, align 8, !tbaa !11
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = uitofp i32 %30 to double
  %32 = fmul double 0x402921FB54442D18, %31
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = uitofp i32 %33 to double
  %35 = fdiv double %32, %34
  %36 = call double @cos(double noundef %35) #4
  %37 = call double @llvm.fmuladd.f64(double %29, double %36, double %28)
  %38 = fptrunc double %37 to float
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds float, ptr %39, i32 1
  store ptr %40, ptr %6, align 8, !tbaa !5
  store float %38, ptr %39, align 4, !tbaa !13
  br label %41

41:                                               ; preds = %17
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %11, align 4, !tbaa !9
  br label %12, !llvm.loop !15

44:                                               ; preds = %16
  ret void
}

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

; Function Attrs: nounwind
declare double @cos(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 nounwind memory(write) uwtable
define dso_local void @cosine_sum_window_create(ptr nocapture noundef writeonly %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %6 = uitofp i32 %1 to double
  %7 = fneg double %3
  br label %8

._crit_edge:                                      ; preds = %8, %5
  ret void

8:                                                ; preds = %.lr.ph, %8
  %.013 = phi i32 [ 0, %.lr.ph ], [ %20, %8 ]
  %.01012 = phi ptr [ %0, %.lr.ph ], [ %19, %8 ]
  %9 = uitofp i32 %.013 to double
  %10 = fmul double %9, 0x401921FB54442D18
  %11 = fdiv double %10, %6
  %12 = tail call double @cos(double noundef %11) #3
  %13 = tail call double @llvm.fmuladd.f64(double %7, double %12, double %2)
  %14 = fmul double %9, 0x402921FB54442D18
  %15 = fdiv double %14, %6
  %16 = tail call double @cos(double noundef %15) #3
  %17 = tail call double @llvm.fmuladd.f64(double %4, double %16, double %13)
  %18 = fptrunc double %17 to float
  %19 = getelementptr inbounds i8, ptr %.01012, i64 4
  store float %18, ptr %.01012, align 4, !tbaa !5
  %20 = add nuw i32 %.013, 1
  %exitcond.not = icmp eq i32 %20, %1
  br i1 %exitcond.not, label %._crit_edge, label %8, !llvm.loop !9
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nofree nounwind memory(write) 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 = { mustprogress nofree nounwind willreturn memory(write) "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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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