#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 */
float sqrtf(float);
void _ccv_atan2(float *x, float *y, float *angle, float *mag, int len) {
  int i = 0;
  float scale = (float)(180.0 / (3.141592653589793));
  for (; i < len; i++) {
    float xf = x[i], yf = y[i];
    float a, x2 = xf * xf, y2 = yf * yf;
    if (y2 <= x2)
      a = xf * yf / (x2 + 0.28f * y2 + (float)1e-6) +
          (float)(xf < 0    ? (3.141592653589793)
                  : yf >= 0 ? 0
                            : (3.141592653589793) * 2);
    else
      a = (float)(yf >= 0 ? (3.141592653589793) * 0.5
                          : (3.141592653589793) * 1.5) -
          xf * yf / (y2 + 0.28f * x2 + (float)1e-6);
    angle[i] = a * scale;
    mag[i] = sqrtf(x2 + y2);
  }
}


x86 assembly (clang, -O0):
<_ccv_atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movss  0xec5(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    130b <_ccv_atan2+0x1fb>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm0
mulss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x34(%rbp),%xmm0
mulss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x40(%rbp),%xmm1
movss  -0x3c(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     124f <_ccv_atan2+0x13f>
movss  -0x30(%rbp),%xmm0
mulss  -0x34(%rbp),%xmm0
movss  -0x3c(%rbp),%xmm2
movss  -0x40(%rbp),%xmm1
movss  0xe4b(%rip),%xmm3
mulss  %xmm3,%xmm1
addss  %xmm2,%xmm1
movss  0xe37(%rip),%xmm2
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x30(%rbp),%xmm0
jbe    11f9 <_ccv_atan2+0xe9>
movsd  0xe39(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1233 <_ccv_atan2+0x123>
movss  -0x34(%rbp),%xmm1
xorps  %xmm2,%xmm2
xorps  %xmm0,%xmm0
movsd  0xe14(%rip),%xmm3
movsd  %xmm3,-0x60(%rbp)
ucomiss %xmm2,%xmm1
movsd  %xmm0,-0x58(%rbp)
jae    1229 <_ccv_atan2+0x119>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movss  -0x44(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
cvtsd2ss %xmm1,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
jmp    12ca <_ccv_atan2+0x1ba>
movss  -0x34(%rbp),%xmm1
xorps  %xmm2,%xmm2
movsd  0xdb1(%rip),%xmm0
movsd  0xdb1(%rip),%xmm3
movsd  %xmm3,-0x70(%rbp)
ucomiss %xmm2,%xmm1
movsd  %xmm0,-0x68(%rbp)
jae    1284 <_ccv_atan2+0x174>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  -0x30(%rbp),%xmm1
mulss  -0x34(%rbp),%xmm1
movss  -0x40(%rbp),%xmm3
movss  -0x3c(%rbp),%xmm2
movss  0xd5f(%rip),%xmm4
mulss  %xmm4,%xmm2
addss  %xmm3,%xmm2
movss  0xd4b(%rip),%xmm3
addss  %xmm3,%xmm2
divss  %xmm2,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x38(%rbp),%xmm0
mulss  -0x2c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
movss  -0x3c(%rbp),%xmm0
addss  -0x40(%rbp),%xmm0
call   1030 <sqrtf@plt>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1140 <_ccv_atan2+0x30>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ccv_atan2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %r8d,%r8d
jle    125c <_ccv_atan2+0x14c>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %r8d,%ebx
xor    %ebp,%ebp
xorps  %xmm6,%xmm6
movss  0xec0(%rip),%xmm7
movss  0xebb(%rip),%xmm8
movss  0xebe(%rip),%xmm9
jmp    1195 <_ccv_atan2+0x85>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1030 <sqrtf@plt>
movss  0xea2(%rip),%xmm9
movss  0xe8d(%rip),%xmm8
movss  0xe81(%rip),%xmm7
xorps  %xmm6,%xmm6
movss  %xmm0,(%r14,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     125c <_ccv_atan2+0x14c>
movss  0x0(%r13,%rbp,4),%xmm1
movss  (%r12,%rbp,4),%xmm3
movaps %xmm1,%xmm0
mulss  %xmm1,%xmm0
movaps %xmm3,%xmm2
mulss  %xmm3,%xmm2
ucomiss %xmm2,%xmm0
jae    11f0 <_ccv_atan2+0xe0>
xor    %eax,%eax
ucomiss %xmm6,%xmm3
setae  %al
lea    0xe50(%rip),%rcx
movss  (%rcx,%rax,4),%xmm4
mulss  %xmm3,%xmm1
movaps %xmm0,%xmm3
mulss  %xmm7,%xmm3
addss  %xmm2,%xmm3
addss  %xmm8,%xmm3
divss  %xmm3,%xmm1
subss  %xmm1,%xmm4
movaps %xmm4,%xmm1
jmp    123b <_ccv_atan2+0x12b>
nopw   0x0(%rax,%rax,1)
movaps %xmm1,%xmm4
mulss  %xmm3,%xmm4
movaps %xmm2,%xmm5
mulss  %xmm7,%xmm5
addss  %xmm0,%xmm5
addss  %xmm8,%xmm5
divss  %xmm5,%xmm4
xorps  %xmm5,%xmm5
cmpless %xmm3,%xmm5
movss  0xded(%rip),%xmm3
andnps %xmm3,%xmm5
cmpltss %xmm6,%xmm1
movaps %xmm1,%xmm3
andnps %xmm5,%xmm3
movss  0xddb(%rip),%xmm5
andps  %xmm5,%xmm1
orps   %xmm3,%xmm1
addss  %xmm4,%xmm1
mulss  %xmm9,%xmm1
movss  %xmm1,(%r15,%rbp,4)
addss  %xmm2,%xmm0
ucomiss %xmm6,%xmm0
jb     1160 <_ccv_atan2+0x50>
sqrtss %xmm0,%xmm0
jmp    1182 <_ccv_atan2+0x72>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_ccv_atan2(float* %0, float* %1, float* %2, float* %3, i32 %4) {
%6 = alloca float*
%7 = alloca float*
%8 = alloca float*
%9 = alloca float*
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca float
store float* %0, float** %6
store float* %1, float** %7
store float* %2, float** %8
store float* %3, float** %9
store i32 %4, i32* %10
store i32 0, i32* %11
store float 0x404CA5DC20000000, float* %12
br label %18
18: ; preds = %94, %5
%19 = load i32, i32* %11
%20 = load i32, i32* %10
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %97
22: ; preds = %18
%23 = load float*, float** %6
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds float, float* %23, i64 %25
%27 = load float, float* %26
store float %27, float* %13
%28 = load float*, float** %7
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds float, float* %28, i64 %30
%32 = load float, float* %31
store float %32, float* %14
%33 = load float, float* %13
%34 = load float, float* %13
%35 = fmul float %33, %34
store float %35, float* %16
%36 = load float, float* %14
%37 = load float, float* %14
%38 = fmul float %36, %37
store float %38, float* %17
%39 = load float, float* %17
%40 = load float, float* %16
%41 = fcmp ole float %39, %40
br i1 %41, label %42, label %63
42: ; preds = %22
%43 = load float, float* %13
%44 = load float, float* %14
%45 = fmul float %43, %44
%46 = load float, float* %16
%47 = load float, float* %17
%48 = call float @llvm.fmuladd.f32(float 0x3FD1EB8520000000, float %47, float %46)
%49 = fadd float %48, 0x3EB0C6F7A0000000
%50 = fdiv float %45, %49
%51 = load float, float* %13
%52 = fcmp olt float %51, 0.000000e+00
br i1 %52, label %53, label %54
53: ; preds = %42
br label %59
54: ; preds = %42
%55 = load float, float* %14
%56 = fcmp oge float %55, 0.000000e+00
%57 = zext i1 %56 to i64
%58 = select i1 %56, double 0.000000e+00, double 0x401921FB54442D18
br label %59
59: ; preds = %54, %53
%60 = phi double [ 0x400921FB54442D18, %53 ], [ %58, %54 ]
%61 = fptrunc double %60 to float
%62 = fadd float %50, %61
store float %62, float* %15
br label %78
63: ; preds = %22
%64 = load float, float* %14
%65 = fcmp oge float %64, 0.000000e+00
%66 = zext i1 %65 to i64
%67 = select i1 %65, double 0x3FF921FB54442D18, double 0x4012D97C7F3321D2
%68 = fptrunc double %67 to float
%69 = load float, float* %13
%70 = load float, float* %14
%71 = fmul float %69, %70
%72 = load float, float* %17
%73 = load float, float* %16
%74 = call float @llvm.fmuladd.f32(float 0x3FD1EB8520000000, float %73, float %72)
%75 = fadd float %74, 0x3EB0C6F7A0000000
%76 = fdiv float %71, %75
%77 = fsub float %68, %76
store float %77, float* %15
br label %78
78: ; preds = %63, %59
%79 = load float, float* %15
%80 = load float, float* %12
%81 = fmul float %79, %80
%82 = load float*, float** %8
%83 = load i32, i32* %11
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds float, float* %82, i64 %84
store float %81, float* %85
%86 = load float, float* %16
%87 = load float, float* %17
%88 = fadd float %86, %87
%89 = call float @sqrtf(float %88)
%90 = load float*, float** %9
%91 = load i32, i32* %11
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds float, float* %90, i64 %92
store float %89, float* %93
br label %94
94: ; preds = %78
%95 = load i32, i32* %11
%96 = add nsw i32 %95, 1
store i32 %96, i32* %11
br label %18
97: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @_ccv_atan2(float* nocapture %0, float* nocapture %1, float* nocapture writeonly %2, float* nocapture writeonly %3, i32 %4) {
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %45
7: ; preds = %5
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %7, %36
%10 = phi i64 [ 0, %7 ], [ %43, %36 ]
%11 = getelementptr inbounds float, float* %0, i64 %10
%12 = load float, float* %11
%13 = getelementptr inbounds float, float* %1, i64 %10
%14 = load float, float* %13
%15 = fmul float %12, %12
%16 = fmul float %14, %14
%17 = fcmp ugt float %16, %15
br i1 %17, label %28, label %18
18: ; preds = %9
%19 = fmul float %12, %14
%20 = tail call float @llvm.fmuladd.f32(float %16, float 0x3FD1EB8520000000, float %15)
%21 = fadd float %20, 0x3EB0C6F7A0000000
%22 = fdiv float %19, %21
%23 = fcmp olt float %12, 0.000000e+00
%24 = fcmp oge float %14, 0.000000e+00
%25 = select i1 %24, float 0.000000e+00, float 0x401921FB60000000
%26 = select i1 %23, float 0x400921FB60000000, float %25
%27 = fadd float %26, %22
br label %36
28: ; preds = %9
%29 = fcmp oge float %14, 0.000000e+00
%30 = select i1 %29, float 0x3FF921FB60000000, float 0x4012D97C80000000
%31 = fmul float %12, %14
%32 = tail call float @llvm.fmuladd.f32(float %15, float 0x3FD1EB8520000000, float %16)
%33 = fadd float %32, 0x3EB0C6F7A0000000
%34 = fdiv float %31, %33
%35 = fsub float %30, %34
br label %36
36: ; preds = %28, %18
%37 = phi float [ %27, %18 ], [ %35, %28 ]
%38 = fmul float %37, 0x404CA5DC20000000
%39 = getelementptr inbounds float, float* %2, i64 %10
store float %38, float* %39
%40 = fadd float %15, %16
%41 = tail call float @sqrtf(float %40)
%42 = getelementptr inbounds float, float* %3, i64 %10
store float %41, float* %42
%43 = add nuw nsw i64 %10, 1
%44 = icmp eq i64 %43, %8
br i1 %44, label %45, label %9
45: ; preds = %36, %5
ret void
}