double atan2(x, y)
double x, y;
{
  double v;
  if (fabs(y) >= fabs(x)) {
    v = atan(x / y);
    if (y < 0.0)
      if (x >= 0.0)
        v += 3.14159265358979;
      else
        v -= 3.14159265358979;
    return v;
  }
  v = -atan(y / x);
  if (y < 0.)
    v -= 1.57079632679489;
  else
    v += 1.57079632679489;
  return v;
}


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
movaps 0xed2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
movaps 0xec2(%rip),%xmm2
pand   %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     11c1 <atan2+0xb1>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11b2 <atan2+0xa2>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1197 <atan2+0x87>
movsd  0xe90(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11ad <atan2+0x9d>
movsd  -0x20(%rbp),%xmm0
movsd  0xe74(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b2 <atan2+0xa2>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1231 <atan2+0x121>
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <atan@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1215 <atan2+0x105>
movsd  -0x20(%rbp),%xmm0
movsd  0xe09(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1227 <atan2+0x117>
movsd  0xdf3(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2>:
push   %rbx
sub    $0x20,%rsp
movapd 0xee3(%rip),%xmm2
movapd %xmm1,%xmm3
andpd  %xmm2,%xmm3
andpd  %xmm0,%xmm2
ucomisd %xmm2,%xmm3
jae    115f <atan2+0x4f>
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
ucomisd %xmm1,%xmm2
seta   %bl
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <atan@plt>
movapd %xmm0,%xmm1
lea    0xebc(%rip),%rax
movsd  (%rax,%rbx,8),%xmm0
subsd  %xmm1,%xmm0
jmp    119c <atan2+0x8c>
movapd %xmm0,(%rsp)
divsd  %xmm1,%xmm0
movapd %xmm1,0x10(%rsp)
call   1030 <atan@plt>
xorpd  %xmm1,%xmm1
ucomisd 0x10(%rsp),%xmm1
jbe    119c <atan2+0x8c>
movapd (%rsp),%xmm2
ucomisd %xmm1,%xmm2
jae    1194 <atan2+0x84>
addsd  0xe96(%rip),%xmm0
jmp    119c <atan2+0x8c>
addsd  0xe84(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
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 = call double @llvm.fabs.f64(double %7)
%9 = load double, double* %4
%10 = call double @llvm.fabs.f64(double %9)
%11 = fcmp oge double %8, %10
br i1 %11, label %12, label %31
12: ; preds = %2
%13 = load double, double* %4
%14 = load double, double* %5
%15 = fdiv double %13, %14
%16 = call double @atan(double %15)
store double %16, double* %6
%17 = load double, double* %5
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %29
19: ; preds = %12
%20 = load double, double* %4
%21 = fcmp oge double %20, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load double, double* %6
%24 = fadd double %23, 0x400921FB54442D11
store double %24, double* %6
br label %28
25: ; preds = %19
%26 = load double, double* %6
%27 = fsub double %26, 0x400921FB54442D11
store double %27, double* %6
br label %28
28: ; preds = %25, %22
br label %29
29: ; preds = %28, %12
%30 = load double, double* %6
store double %30, double* %3
br label %47
31: ; preds = %2
%32 = load double, double* %5
%33 = load double, double* %4
%34 = fdiv double %32, %33
%35 = call double @atan(double %34)
%36 = fneg double %35
store double %36, double* %6
%37 = load double, double* %5
%38 = fcmp olt double %37, 0.000000e+00
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load double, double* %6
%41 = fsub double %40, 0x3FF921FB54442CFA
store double %41, double* %6
br label %45
42: ; preds = %31
%43 = load double, double* %6
%44 = fadd double %43, 0x3FF921FB54442CFA
store double %44, double* %6
br label %45
45: ; preds = %42, %39
%46 = load double, double* %6
store double %46, double* %3
br label %47
47: ; preds = %45, %29
%48 = load double, double* %3
ret double %48
}

LLVM IR (-O2):
define double @atan2(double %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %1)
%4 = tail call double @llvm.fabs.f64(double %0)
%5 = fcmp ult double %3, %4
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = fdiv double %0, %1
%8 = tail call double @atan(double %7)
%9 = fcmp olt double %1, 0.000000e+00
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = fcmp ult double %0, 0.000000e+00
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = fadd double %8, 0x400921FB54442D11
br label %22
14: ; preds = %10
%15 = fadd double %8, 0xC00921FB54442D11
br label %22
16: ; preds = %2
%17 = fdiv double %1, %0
%18 = tail call double @atan(double %17)
%19 = fcmp olt double %1, 0.000000e+00
%20 = select i1 %19, double 0xBFF921FB54442CFA, double 0x3FF921FB54442CFA
%21 = fsub double %20, %18
br label %22
22: ; preds = %6, %14, %12, %16
%23 = phi double [ %21, %16 ], [ %13, %12 ], [ %15, %14 ], [ %8, %6 ]
ret double %23
}