#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 M_PI;
double M_PI_2;
double atan(double);
double atan2(double y, double x) {
  if (y == 0.0) {
    if (x >= 0.0) {
      return 0.0;
    } else {
      return M_PI;
    }
  } else if (y > 0.0) {
    if (x == 0.0) {
      return M_PI_2;
    } else if (x > 0.0) {
      return atan(y / x);
    } else {
      return M_PI - atan(y / x);
    }
  } else {
    if (x == 0.0) {
      return M_PI + M_PI_2;
    } else if (x > 0.0) {
      return 2 * M_PI - atan(y / x);
    } else {
      return M_PI + atan(y / x);
    }
  }
}


x86 assembly (clang, -O0):
<atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116e <atan2+0x5e>
jp     116e <atan2+0x5e>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1159 <atan2+0x49>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d7 <atan2+0x1c7>
mov    0x2e88(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d7 <atan2+0x1c7>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    120d <atan2+0xfd>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ad <atan2+0x9d>
jp     11ad <atan2+0x9d>
mov    0x2e41(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d7 <atan2+0x1c7>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d8 <atan2+0xc8>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12d7 <atan2+0x1c7>
mov    0x2e09(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d7 <atan2+0x1c7>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1245 <atan2+0x135>
jp     1245 <atan2+0x135>
mov    0x2dbc(%rip),%rax
movsd  (%rax),%xmm0
mov    0x2da9(%rip),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d7 <atan2+0x1c7>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12a7 <atan2+0x197>
mov    0x2d8a(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d7 <atan2+0x1c7>
mov    0x2d3a(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2>:
sub    $0x18,%rsp
movapd %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    113e <atan2+0x2e>
jp     113e <atan2+0x2e>
ucomisd %xmm1,%xmm2
jae    11f4 <atan2+0xe4>
mov    0x2eb3(%rip),%rax
movsd  (%rax),%xmm1
jmp    11f4 <atan2+0xe4>
xorpd  %xmm1,%xmm1
jbe    115c <atan2+0x4c>
ucomisd %xmm1,%xmm2
jne    117c <atan2+0x6c>
jp     117c <atan2+0x6c>
mov    0x2e8d(%rip),%rax
movsd  (%rax),%xmm1
jmp    11f4 <atan2+0xe4>
mov    0x2e85(%rip),%rax
ucomisd %xmm1,%xmm2
jne    118b <atan2+0x7b>
jp     118b <atan2+0x7b>
movsd  (%rax),%xmm1
mov    0x2e6a(%rip),%rax
addsd  (%rax),%xmm1
jmp    11f4 <atan2+0xe4>
jbe    11c4 <atan2+0xb4>
divsd  %xmm2,%xmm0
add    $0x18,%rsp
jmp    1030 <atan@plt>
movsd  (%rax),%xmm1
movsd  %xmm1,0x8(%rsp)
divsd  %xmm2,%xmm0
movsd  %xmm2,0x10(%rsp)
call   1030 <atan@plt>
movsd  0x10(%rsp),%xmm1
ucomisd 0xe4e(%rip),%xmm1
jbe    11ea <atan2+0xda>
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
jmp    11f4 <atan2+0xe4>
mov    0x2e1d(%rip),%rax
movsd  (%rax),%xmm1
movsd  %xmm1,0x8(%rsp)
divsd  %xmm2,%xmm0
call   1030 <atan@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
jmp    11f4 <atan2+0xe4>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@M_PI_2 = global double 0.000000e+00
define double @atan2(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load double, double* %5
%10 = fcmp oge double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %8
store double 0.000000e+00, double* %3
br label %62
12: ; preds = %8
%13 = load double, double* @M_PI
store double %13, double* %3
br label %62
14: ; preds = %2
%15 = load double, double* %4
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load double, double* %5
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load double, double* @M_PI_2
store double %21, double* %3
br label %62
22: ; preds = %17
%23 = load double, double* %5
%24 = fcmp ogt double %23, 0.000000e+00
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load double, double* %4
%27 = load double, double* %5
%28 = fdiv double %26, %27
%29 = call double @atan(double %28)
store double %29, double* %3
br label %62
30: ; preds = %22
%31 = load double, double* @M_PI
%32 = load double, double* %4
%33 = load double, double* %5
%34 = fdiv double %32, %33
%35 = call double @atan(double %34)
%36 = fsub double %31, %35
store double %36, double* %3
br label %62
37: ; preds = %14
%38 = load double, double* %5
%39 = fcmp oeq double %38, 0.000000e+00
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load double, double* @M_PI
%42 = load double, double* @M_PI_2
%43 = fadd double %41, %42
store double %43, double* %3
br label %62
44: ; preds = %37
%45 = load double, double* %5
%46 = fcmp ogt double %45, 0.000000e+00
br i1 %46, label %47, label %55
47: ; preds = %44
%48 = load double, double* @M_PI
%49 = load double, double* %4
%50 = load double, double* %5
%51 = fdiv double %49, %50
%52 = call double @atan(double %51)
%53 = fneg double %52
%54 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %48, double %53)
store double %54, double* %3
br label %62
55: ; preds = %44
%56 = load double, double* @M_PI
%57 = load double, double* %4
%58 = load double, double* %5
%59 = fdiv double %57, %58
%60 = call double @atan(double %59)
%61 = fadd double %56, %60
store double %61, double* %3
br label %62
62: ; preds = %55, %47, %40, %30, %25, %20, %12, %11
%63 = load double, double* %3
ret double %63
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@M_PI_2 = global double 0.000000e+00
define double @atan2(double %0, double %1) {
%3 = fcmp oeq double %0, 0.000000e+00
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = fcmp ult double %1, 0.000000e+00
br i1 %5, label %6, label %39
6: ; preds = %4
%7 = load double, double* @M_PI
br label %39
8: ; preds = %2
%9 = fcmp ogt double %0, 0.000000e+00
%10 = fcmp oeq double %1, 0.000000e+00
br i1 %9, label %11, label %24
11: ; preds = %8
br i1 %10, label %12, label %14
12: ; preds = %11
%13 = load double, double* @M_PI_2
br label %39
14: ; preds = %11
%15 = fcmp ogt double %1, 0.000000e+00
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = fdiv double %0, %1
%18 = tail call double @atan(double %17)
br label %39
19: ; preds = %14
%20 = load double, double* @M_PI
%21 = fdiv double %0, %1
%22 = tail call double @atan(double %21)
%23 = fsub double %20, %22
br label %39
24: ; preds = %8
br i1 %10, label %25, label %29
25: ; preds = %24
%26 = load double, double* @M_PI
%27 = load double, double* @M_PI_2
%28 = fadd double %26, %27
br label %39
29: ; preds = %24
%30 = fcmp ogt double %1, 0.000000e+00
%31 = load double, double* @M_PI
%32 = fdiv double %0, %1
%33 = tail call double @atan(double %32)
br i1 %30, label %34, label %37
34: ; preds = %29
%35 = fneg double %33
%36 = tail call double @llvm.fmuladd.f64(double %31, double 2.000000e+00, double %35)
br label %39
37: ; preds = %29
%38 = fadd double %31, %33
br label %39
39: ; preds = %4, %37, %34, %25, %19, %16, %12, %6
%40 = phi double [ %7, %6 ], [ %13, %12 ], [ %18, %16 ], [ %23, %19 ], [ %28, %25 ], [ %36, %34 ], [ %38, %37 ], [ 0.000000e+00, %4 ]
ret double %40
}