double atan2(double arg1, double arg2) {
  double satan(double);
  if ((arg1 + arg2) == arg1) {
    if (arg1 >= 0.) {
      return (1.57079632679489e0);
    } else {
      return (-1.57079632679489e0);
    }
  } else if (arg2 < 0.) {
    if (arg1 >= 0.) {
      return (1.57079632679489e0 + 1.57079632679489e0 - satan(-arg1 / arg2));
    } else {
      return (-1.57079632679489e0 - 1.57079632679489e0 + satan(arg1 / arg2));
    }
  } else if (arg1 > 0) {
    return (satan(arg1 / arg2));
  } else {
    return (-satan(-arg1 / arg2));
  }
}


x86 assembly (clang, -O0):
<atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1173 <atan2+0x63>
jp     1173 <atan2+0x63>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1161 <atan2+0x51>
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1267 <atan2+0x157>
movsd  0xea7(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1267 <atan2+0x157>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11fa <atan2+0xea>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d2 <atan2+0xc2>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <satan@plt>
movaps %xmm0,%xmm1
movsd  0xe44(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1267 <atan2+0x157>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <satan@plt>
movaps %xmm0,%xmm1
movsd  0xe14(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1267 <atan2+0x157>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1225 <atan2+0x115>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <satan@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1267 <atan2+0x157>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <satan@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2>:
push   %rax
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jne    113c <atan2+0x2c>
jp     113c <atan2+0x2c>
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
setb   %al
lea    0xedb(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
pop    %rax
ret
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
jbe    115f <atan2+0x4f>
ucomisd %xmm2,%xmm0
jae    116f <atan2+0x5f>
divsd  %xmm1,%xmm0
call   1030 <satan@plt>
addsd  0xecb(%rip),%xmm0
pop    %rax
ret
ucomisd %xmm2,%xmm0
jbe    1192 <atan2+0x82>
divsd  %xmm1,%xmm0
pop    %rax
jmp    1030 <satan@plt>
xorpd  0xe89(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1030 <satan@plt>
movapd %xmm0,%xmm1
movsd  0xe94(%rip),%xmm0
subsd  %xmm1,%xmm0
pop    %rax
ret
xorpd  0xe66(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1030 <satan@plt>
xorpd  0xe55(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
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 = load double, double* %5
%8 = fadd double %6, %7
%9 = load double, double* %4
%10 = fcmp oeq double %8, %9
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load double, double* %4
%13 = fcmp oge double %12, 0.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %11
store double 0x3FF921FB54442CFA, double* %3
br label %50
15: ; preds = %11
store double 0xBFF921FB54442CFA, double* %3
br label %50
16: ; preds = %2
%17 = load double, double* %5
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = load double, double* %4
%21 = fcmp oge double %20, 0.000000e+00
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load double, double* %4
%24 = fneg double %23
%25 = load double, double* %5
%26 = fdiv double %24, %25
%27 = call double @satan(double %26)
%28 = fsub double 0x400921FB54442CFA, %27
store double %28, double* %3
br label %50
29: ; preds = %19
%30 = load double, double* %4
%31 = load double, double* %5
%32 = fdiv double %30, %31
%33 = call double @satan(double %32)
%34 = fadd double 0xC00921FB54442CFA, %33
store double %34, double* %3
br label %50
35: ; preds = %16
%36 = load double, double* %4
%37 = fcmp ogt double %36, 0.000000e+00
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load double, double* %4
%40 = load double, double* %5
%41 = fdiv double %39, %40
%42 = call double @satan(double %41)
store double %42, double* %3
br label %50
43: ; preds = %35
%44 = load double, double* %4
%45 = fneg double %44
%46 = load double, double* %5
%47 = fdiv double %45, %46
%48 = call double @satan(double %47)
%49 = fneg double %48
store double %49, double* %3
br label %50
50: ; preds = %43, %38, %29, %22, %15, %14
%51 = load double, double* %3
ret double %51
}

LLVM IR (-O2):
define double @atan2(double %0, double %1) {
%3 = fadd double %0, %1
%4 = fcmp oeq double %3, %0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = fcmp ult double %0, 0.000000e+00
%7 = select i1 %6, double 0xBFF921FB54442CFA, double 0x3FF921FB54442CFA
br label %31
8: ; preds = %2
%9 = fcmp olt double %1, 0.000000e+00
br i1 %9, label %10, label %21
10: ; preds = %8
%11 = fcmp ult double %0, 0.000000e+00
br i1 %11, label %17, label %12
12: ; preds = %10
%13 = fneg double %0
%14 = fdiv double %13, %1
%15 = tail call double @satan(double %14)
%16 = fsub double 0x400921FB54442CFA, %15
br label %31
17: ; preds = %10
%18 = fdiv double %0, %1
%19 = tail call double @satan(double %18)
%20 = fadd double %19, 0xC00921FB54442CFA
br label %31
21: ; preds = %8
%22 = fcmp ogt double %0, 0.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = fdiv double %0, %1
%25 = tail call double @satan(double %24)
br label %31
26: ; preds = %21
%27 = fneg double %0
%28 = fdiv double %27, %1
%29 = tail call double @satan(double %28)
%30 = fneg double %29
br label %31
31: ; preds = %5, %26, %23, %17, %12
%32 = phi double [ %16, %12 ], [ %20, %17 ], [ %25, %23 ], [ %30, %26 ], [ %7, %5 ]
ret double %32
}