#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double atan2(double, double);
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sms_fft(int, double *);
int /*<<< orphan*/ sms_windowCentered(int, double *, double *, int, double *);
double sqrt(double);
int sms_spectrum(int sizeWindow, double *pWaveform, double *pWindow,
                 int sizeMag, double *pMag, double *pPhase,
                 double *pFftBuffer) {
  int i, it2;
  double fReal, fImag;
  int sizeFft = sizeMag << 1;
  memset(pFftBuffer, 0, sizeFft * sizeof(double));
  sms_windowCentered(sizeWindow, pWaveform, pWindow, sizeFft, pFftBuffer);
  sms_fft(sizeFft, pFftBuffer);
  for (i = 0; i < sizeMag; i++) {
    it2 = i << 1;
    fReal = pFftBuffer[it2];
    fImag = pFftBuffer[it2 + 1];
    pMag[i] = sqrt(fReal * fReal + fImag * fImag);
    pPhase[i] = atan2(-fImag, fReal);
  }
  return sizeFft;
}


x86 assembly (clang, -O0):
<sms_spectrum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    0x10(%rbp),%rdi
movslq -0x4c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x4c(%rbp),%ecx
mov    0x10(%rbp),%r8
call   1050 <sms_windowCentered@plt>
mov    -0x4c(%rbp),%edi
mov    0x10(%rbp),%rsi
call   1060 <sms_fft@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1267 <sms_spectrum+0x117>
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x40(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ba <sms_spectrum+0x6a>
mov    -0x4c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sms_spectrum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%ebp
mov    %rdx,(%rsp)
mov    %rsi,0x10(%rsp)
mov    %edi,%r13d
mov    0x60(%rsp),%r12
lea    0x0(%rbp,%rbp,1),%ebx
mov    %ecx,%edx
shl    $0x4,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r13d,%edi
mov    0x10(%rsp),%rsi
mov    (%rsp),%rdx
mov    %ebx,%ecx
mov    %r12,%r8
call   1050 <sms_windowCentered@plt>
mov    %ebx,0xc(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
call   1060 <sms_fft@plt>
test   %ebp,%ebp
jle    125f <sms_spectrum+0x10f>
mov    %ebp,%ebp
add    %rbp,%rbp
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    121e <sms_spectrum+0xce>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,(%rsp)
movapd %xmm3,0x10(%rsp)
call   1070 <sqrt@plt>
movapd 0x10(%rsp),%xmm3
movsd  (%rsp),%xmm1
movsd  %xmm0,(%r15,%r13,4)
xorpd  0xe07(%rip),%xmm3
movapd %xmm3,%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%r14,%r13,4)
add    $0x2,%r13
movabs $0x200000000,%rax
add    %rax,%rbx
cmp    %r13,%rbp
je     125f <sms_spectrum+0x10f>
mov    %rbx,%rax
sar    $0x1d,%rax
movsd  (%r12,%rax,1),%xmm1
lea    0x1(%r13),%eax
cltq
movsd  (%r12,%rax,8),%xmm3
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xdbd(%rip),%xmm0
jb     11d0 <sms_spectrum+0x80>
sqrtsd %xmm0,%xmm0
jmp    11eb <sms_spectrum+0x9b>
mov    0xc(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sms_spectrum(i32 %0, double* %1, double* %2, i32 %3, double* %4, double* %5, double* %6) {
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca i32
store i32 %0, i32* %8
store double* %1, double** %9
store double* %2, double** %10
store i32 %3, i32* %11
store double* %4, double** %12
store double* %5, double** %13
store double* %6, double** %14
%20 = load i32, i32* %11
%21 = shl i32 %20, 1
store i32 %21, i32* %19
%22 = load double*, double** %14
%23 = load i32, i32* %19
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i32 @memset(double* %22, i32 0, i32 %26)
%28 = load i32, i32* %8
%29 = load double*, double** %9
%30 = load double*, double** %10
%31 = load i32, i32* %19
%32 = load double*, double** %14
%33 = call i32 @sms_windowCentered(i32 %28, double* %29, double* %30, i32 %31, double* %32)
%34 = load i32, i32* %19
%35 = load double*, double** %14
%36 = call i32 @sms_fft(i32 %34, double* %35)
store i32 0, i32* %15
br label %37
37: ; preds = %74, %7
%38 = load i32, i32* %15
%39 = load i32, i32* %11
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %77
41: ; preds = %37
%42 = load i32, i32* %15
%43 = shl i32 %42, 1
store i32 %43, i32* %16
%44 = load double*, double** %14
%45 = load i32, i32* %16
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
store double %48, double* %17
%49 = load double*, double** %14
%50 = load i32, i32* %16
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %49, i64 %52
%54 = load double, double* %53
store double %54, double* %18
%55 = load double, double* %17
%56 = load double, double* %17
%57 = load double, double* %18
%58 = load double, double* %18
%59 = fmul double %57, %58
%60 = call double @llvm.fmuladd.f64(double %55, double %56, double %59)
%61 = call double @sqrt(double %60)
%62 = load double*, double** %12
%63 = load i32, i32* %15
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
store double %61, double* %65
%66 = load double, double* %18
%67 = fneg double %66
%68 = load double, double* %17
%69 = call double @atan2(double %67, double %68)
%70 = load double*, double** %13
%71 = load i32, i32* %15
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
store double %69, double* %73
br label %74
74: ; preds = %41
%75 = load i32, i32* %15
%76 = add nsw i32 %75, 1
store i32 %76, i32* %15
br label %37
77: ; preds = %37
%78 = load i32, i32* %19
ret i32 %78
}

LLVM IR (-O2):
define i32 @sms_spectrum(i32 %0, double* %1, double* %2, i32 %3, double* nocapture writeonly %4, double* nocapture writeonly %5, double* %6) {
%8 = shl i32 %3, 1
%9 = shl i32 %3, 4
%10 = tail call i32 @memset(double* %6, i32 0, i32 %9)
%11 = tail call i32 @sms_windowCentered(i32 %0, double* %1, double* %2, i32 %8, double* %6)
%12 = tail call i32 @sms_fft(i32 %8, double* %6)
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %37
14: ; preds = %7
%15 = zext i32 %3 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %35, %16 ]
%18 = shl i64 %17, 33
%19 = ashr exact i64 %18, 32
%20 = getelementptr inbounds double, double* %6, i64 %19
%21 = load double, double* %20
%22 = trunc i64 %17 to i32
%23 = shl i32 %22, 1
%24 = or i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %6, i64 %25
%27 = load double, double* %26
%28 = fmul double %27, %27
%29 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %28)
%30 = tail call double @sqrt(double %29)
%31 = getelementptr inbounds double, double* %4, i64 %17
store double %30, double* %31
%32 = fneg double %27
%33 = tail call double @atan2(double %32, double %21)
%34 = getelementptr inbounds double, double* %5, i64 %17
store double %33, double* %34
%35 = add nuw nsw i64 %17, 1
%36 = icmp eq i64 %35, %15
br i1 %36, label %37, label %16
37: ; preds = %16, %7
ret i32 %8
}