double angleof(x, y)
double x, y;
{
  double theta;
  if (fabs(x) > 0.00001)
    theta = atan(y / x);
  else if (y >= 0.0)
    theta = 3.141592653 / 2;
  else
    theta = 1.5 * 3.141592653;
  if (x < -0.00001)
    theta = 3.141592653 + theta;
  if (theta > 2 * 3.141592653)
    theta -= 2 * 3.141592653;
  return theta;
}


x86 assembly (clang, -O0):
<angleof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xf02(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xec6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    115d <angleof+0x4d>
movsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    1193 <angleof+0x83>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1181 <angleof+0x71>
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    118e <angleof+0x7e>
movsd  0xe7f(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1193 <angleof+0x83>
movsd  0xe7d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11b8 <angleof+0xa8>
movsd  0xe72(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe63(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e5 <angleof+0xd5>
movsd  -0x18(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<angleof>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
movapd 0xee0(%rip),%xmm0
andpd  %xmm2,%xmm0
ucomisd 0xef4(%rip),%xmm0
jbe    1147 <angleof+0x37>
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
movapd %xmm2,(%rsp)
call   1030 <atan@plt>
movapd (%rsp),%xmm2
jmp    1160 <angleof+0x50>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
ucomisd %xmm0,%xmm1
setb   %al
lea    0xeb5(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  0xec0(%rip),%xmm1
addsd  %xmm0,%xmm1
cmpltsd 0xebb(%rip),%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movsd  0xeaf(%rip),%xmm1
addsd  %xmm2,%xmm1
movsd  0xeab(%rip),%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @angleof(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %3
%7 = call double @llvm.fabs.f64(double %6)
%8 = fcmp ogt double %7, 1.000000e-05
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load double, double* %4
%11 = load double, double* %3
%12 = fdiv double %10, %11
%13 = call double @atan(double %12)
store double %13, double* %5
br label %20
14: ; preds = %2
%15 = load double, double* %4
%16 = fcmp oge double %15, 0.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %14
store double 0x3FF921FB542FE938, double* %5
br label %19
18: ; preds = %14
store double 0x4012D97C7F23EEEA, double* %5
br label %19
19: ; preds = %18, %17
br label %20
20: ; preds = %19, %9
%21 = load double, double* %3
%22 = fcmp olt double %21, -1.000000e-05
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load double, double* %5
%25 = fadd double 0x400921FB542FE938, %24
store double %25, double* %5
br label %26
26: ; preds = %23, %20
%27 = load double, double* %5
%28 = fcmp ogt double %27, 0x401921FB542FE938
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load double, double* %5
%31 = fsub double %30, 0x401921FB542FE938
store double %31, double* %5
br label %32
32: ; preds = %29, %26
%33 = load double, double* %5
ret double %33
}

LLVM IR (-O2):
define double @angleof(double %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = fcmp ogt double %3, 1.000000e-05
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = fdiv double %1, %0
%7 = tail call double @atan(double %6)
br label %11
8: ; preds = %2
%9 = fcmp ult double %1, 0.000000e+00
%10 = select i1 %9, double 0x4012D97C7F23EEEA, double 0x3FF921FB542FE938
br label %11
11: ; preds = %8, %5
%12 = phi double [ %7, %5 ], [ %10, %8 ]
%13 = fcmp olt double %0, -1.000000e-05
%14 = fadd double %12, 0x400921FB542FE938
%15 = select i1 %13, double %14, double %12
%16 = fcmp ogt double %15, 0x401921FB542FE938
%17 = fadd double %15, 0xC01921FB542FE938
%18 = select i1 %16, double %17, double %15
ret double %18
}