#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 atan(double);
double atan2(double y, double x) {
  if (!x && y > 0)
    return 3.14159265358979323846 / 2;
  else if (!x && y > 0)
    return -3.14159265358979323846 / 2;
  double z = atan(y / x);
  if (z < 0)
    return z + 2 * 3.14159265358979323846;
  else
    return z;
}


x86 assembly (clang, -O0):
<atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115e <atan2+0x4e>
jp     115e <atan2+0x4e>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    115e <atan2+0x4e>
movsd  0xeac(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e2 <atan2+0xd2>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119a <atan2+0x8a>
jp     119a <atan2+0x8a>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    119a <atan2+0x8a>
movsd  0xe78(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e2 <atan2+0xd2>
jmp    119f <atan2+0x8f>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11d8 <atan2+0xc8>
movsd  0xe47(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e2 <atan2+0xd2>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2>:
push   %rax
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jbe    112d <atan2+0x1d>
ucomisd %xmm2,%xmm1
jne    112d <atan2+0x1d>
jp     112d <atan2+0x1d>
movsd  0xed5(%rip),%xmm0
pop    %rax
ret
divsd  %xmm1,%xmm0
call   1030 <atan@plt>
movapd %xmm0,%xmm1
movsd  0xec6(%rip),%xmm2
addsd  %xmm0,%xmm2
cmpltsd 0xec1(%rip),%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @atan2(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
%7 = load double, double* %5
%8 = fcmp une double %7, 0.000000e+00
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load double, double* %4
%11 = fcmp ogt double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %9
store double 0x3FF921FB54442D18, double* %3
br label %33
13: ; preds = %9, %2
%14 = load double, double* %5
%15 = fcmp une double %14, 0.000000e+00
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load double, double* %4
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %16
store double 0xBFF921FB54442D18, double* %3
br label %33
20: ; preds = %16, %13
br label %21
21: ; preds = %20
%22 = load double, double* %4
%23 = load double, double* %5
%24 = fdiv double %22, %23
%25 = call double @atan(double %24)
store double %25, double* %6
%26 = load double, double* %6
%27 = fcmp olt double %26, 0.000000e+00
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load double, double* %6
%30 = fadd double %29, 0x401921FB54442D18
store double %30, double* %3
br label %33
31: ; preds = %21
%32 = load double, double* %6
store double %32, double* %3
br label %33
33: ; preds = %31, %28, %19, %12
%34 = load double, double* %3
ret double %34
}

LLVM IR (-O2):
define double @atan2(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
%4 = fcmp ogt double %0, 0.000000e+00
%5 = and i1 %4, %3
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = fdiv double %0, %1
%8 = tail call double @atan(double %7)
%9 = fcmp olt double %8, 0.000000e+00
%10 = fadd double %8, 0x401921FB54442D18
%11 = select i1 %9, double %10, double %8
br label %12
12: ; preds = %2, %6
%13 = phi double [ %11, %6 ], [ 0x3FF921FB54442D18, %2 ]
ret double %13
}