#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 atan2f(double, double);
double sqrtf(double);
void sms_RectToPolar(int sizeMag, double *pRect, double *pMag, double *pPhase) {
  int i, it2;
  double fReal, fImag;
  for (i = 0; i < sizeMag; i++) {
    it2 = i << 1;
    fReal = pRect[it2];
    fImag = pRect[it2 + 1];
    pMag[i] = sqrtf(fReal * fReal + fImag * fImag);
    if (pPhase)
      pPhase[i] = atan2f(fImag, fReal);
  }
}


x86 assembly (clang, -O0):
<sms_RectToPolar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e4 <sms_RectToPolar+0xc4>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrtf@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cmpq   $0x0,-0x20(%rbp)
je     11d1 <sms_RectToPolar+0xb1>
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1040 <atan2f@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11d6 <sms_RectToPolar+0xb6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113e <sms_RectToPolar+0x1e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sms_RectToPolar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11f0 <sms_RectToPolar+0xd0>
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,%r12d
add    %r12,%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    116a <sms_RectToPolar+0x4a>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rbp
movabs $0x200000000,%rax
add    %rax,%rbx
cmp    %rbp,%r12
je     11f0 <sms_RectToPolar+0xd0>
mov    %rbx,%rax
sar    $0x1d,%rax
movsd  0x0(%r13,%rax,1),%xmm1
lea    0x1(%rbp),%eax
cltq
movsd  0x0(%r13,%rax,8),%xmm3
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe60(%rip),%xmm0
jb     11b0 <sms_RectToPolar+0x90>
sqrtsd %xmm0,%xmm0
jmp    11cd <sms_RectToPolar+0xad>
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1030 <sqrtf@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm1
movsd  %xmm0,(%r14,%rbp,4)
test   %r15,%r15
je     1150 <sms_RectToPolar+0x30>
movapd %xmm3,%xmm0
call   1040 <atan2f@plt>
movsd  %xmm0,(%r15,%rbp,4)
jmp    1150 <sms_RectToPolar+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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