#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 sqrtf(double);
void sms_spectrumRMS(int sizeMag, double *pInRect, double *pOutMag) {
  int i, it2;
  double fReal, fImag;
  for (i = 0; i < sizeMag; i++) {
    it2 = i << 1;
    fReal = pInRect[it2];
    fImag = pInRect[it2 + 1];
    pOutMag[i] = sqrtf(fReal * fReal + fImag * fImag);
  }
}


x86 assembly (clang, -O0):
<sms_spectrumRMS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a4 <sms_spectrumRMS+0x94>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrtf@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <sms_spectrumRMS+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sms_spectrumRMS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    118b <sms_spectrumRMS+0x7b>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%r15d
add    %r15,%r15
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
movabs $0x200000000,%r13
xor    %ebp,%ebp
jmp    115b <sms_spectrumRMS+0x4b>
nop
call   1030 <sqrtf@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%r14,%rbp,4)
add    $0x2,%rbp
add    %r13,%rbx
cmp    %rbp,%r15
je     118b <sms_spectrumRMS+0x7b>
mov    %rbx,%rax
sar    $0x1d,%rax
movsd  (%r12,%rax,1),%xmm0
lea    0x1(%rbp),%eax
cltq
movsd  (%r12,%rax,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1140 <sms_spectrumRMS+0x30>
sqrtsd %xmm0,%xmm0
jmp    1149 <sms_spectrumRMS+0x39>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sms_spectrumRMS(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store i32 0, i32* %7
br label %11
11: ; preds = %40, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %43
15: ; preds = %11
%16 = load i32, i32* %7
%17 = shl i32 %16, 1
store i32 %17, i32* %8
%18 = load double*, double** %5
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
store double %22, double* %9
%23 = load double*, double** %5
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %23, i64 %26
%28 = load double, double* %27
store double %28, double* %10
%29 = load double, double* %9
%30 = load double, double* %9
%31 = load double, double* %10
%32 = load double, double* %10
%33 = fmul double %31, %32
%34 = call double @llvm.fmuladd.f64(double %29, double %30, double %33)
%35 = call double @sqrtf(double %34)
%36 = load double*, double** %6
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
store double %35, double* %39
br label %40
40: ; preds = %15
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %11
43: ; preds = %11
ret void
}

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