#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 */
int /*<<< orphan*/ abs(float);
int /*<<< orphan*/ atan(int /*<<< orphan*/);
int radiansToDegrees(int /*<<< orphan*/);
int sgn(float);
int atan2(float x, float y) {
  if (x == 0)
    return 90 * sgn(y);
  if (y == 0 && x < 0)
    return 180;
  int phi = radiansToDegrees(atan(abs(y / x)));
  if (x < 0)
    phi = 180 - phi;
  return phi * sgn(y);
}


x86 assembly (clang, -O0):
<atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    117e <atan2+0x3e>
jp     117e <atan2+0x3e>
movss  -0xc(%rbp),%xmm0
call   1060 <sgn@plt>
imul   $0x5a,%eax,%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <atan2+0xc1>
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11ae <atan2+0x6e>
jp     11ae <atan2+0x6e>
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    11ae <atan2+0x6e>
movl   $0xb4,-0x4(%rbp)
jmp    1201 <atan2+0xc1>
movss  -0xc(%rbp),%xmm0
divss  -0x8(%rbp),%xmm0
call   1030 <abs@plt>
mov    %eax,%edi
call   1050 <atan@plt>
mov    %eax,%edi
call   1040 <radiansToDegrees@plt>
mov    %eax,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    11e6 <atan2+0xa6>
mov    $0xb4,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
call   1060 <sgn@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2>:
push   %rbx
sub    $0x10,%rsp
movaps %xmm0,%xmm2
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm2
jne    1163 <atan2+0x23>
jp     1163 <atan2+0x23>
movaps %xmm1,%xmm0
call   1060 <sgn@plt>
mov    %eax,%ebx
mov    $0x5a,%eax
jmp    11ba <atan2+0x7a>
ucomiss %xmm2,%xmm0
jbe    1177 <atan2+0x37>
mov    $0xb4,%eax
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    1177 <atan2+0x37>
jnp    11bd <atan2+0x7d>
movaps %xmm1,%xmm0
divss  %xmm2,%xmm0
movss  %xmm1,0xc(%rsp)
movss  %xmm2,0x8(%rsp)
call   1030 <abs@plt>
mov    %eax,%edi
call   1050 <atan@plt>
mov    %eax,%edi
call   1040 <radiansToDegrees@plt>
mov    $0xb4,%ebx
sub    %eax,%ebx
xorps  %xmm0,%xmm0
ucomiss 0x8(%rsp),%xmm0
cmovbe %eax,%ebx
movss  0xc(%rsp),%xmm0
call   1060 <sgn@plt>
imul   %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @atan2(float %0, float %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca i32
store float %0, float* %4
store float %1, float* %5
%7 = load float, float* %4
%8 = fcmp oeq float %7, 0.000000e+00
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load float, float* %5
%11 = call i32 @sgn(float %10)
%12 = mul nsw i32 90, %11
store i32 %12, i32* %3
br label %37
13: ; preds = %2
%14 = load float, float* %5
%15 = fcmp oeq float %14, 0.000000e+00
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load float, float* %4
%18 = fcmp olt float %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 180, i32* %3
br label %37
20: ; preds = %16, %13
%21 = load float, float* %5
%22 = load float, float* %4
%23 = fdiv float %21, %22
%24 = call i32 @abs(float %23)
%25 = call i32 @atan(i32 %24)
%26 = call i32 @radiansToDegrees(i32 %25)
store i32 %26, i32* %6
%27 = load float, float* %4
%28 = fcmp olt float %27, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32, i32* %6
%31 = sub nsw i32 180, %30
store i32 %31, i32* %6
br label %32
32: ; preds = %29, %20
%33 = load i32, i32* %6
%34 = load float, float* %5
%35 = call i32 @sgn(float %34)
%36 = mul nsw i32 %33, %35
store i32 %36, i32* %3
br label %37
37: ; preds = %32, %19, %9
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @atan2(float %0, float %1) {
%3 = fcmp oeq float %0, 0.000000e+00
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @sgn(float %1)
br label %18
6: ; preds = %2
%7 = fcmp oeq float %1, 0.000000e+00
%8 = fcmp olt float %0, 0.000000e+00
%9 = and i1 %8, %7
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = fdiv float %1, %0
%12 = tail call i32 @abs(float %11)
%13 = tail call i32 @atan(i32 %12)
%14 = tail call i32 @radiansToDegrees(i32 %13)
%15 = sub nsw i32 180, %14
%16 = select i1 %8, i32 %15, i32 %14
%17 = tail call i32 @sgn(float %1)
br label %18
18: ; preds = %4, %10
%19 = phi i32 [ %17, %10 ], [ 90, %4 ]
%20 = phi i32 [ %16, %10 ], [ %5, %4 ]
%21 = mul nsw i32 %20, %19
br label %22
22: ; preds = %18, %6
%23 = phi i32 [ 180, %6 ], [ %21, %18 ]
ret i32 %23
}