#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, int);
double atan2(double v, double u) {
  double au, av, f;
  av = v < 0.0 ? -v : v;
  au = u < 0.0 ? -u : u;
  if (u != 0.0) {
    if (av > au) {
      if ((f = au / av) == 0.0)
        f = 1.57079632679489662;
      else
        f = _atan(f, 2);
    } else {
      if ((f = av / au) == 0.0)
        f = 0.0;
      else
        f = _atan(f, 0);
    }
  } else {
    if (v != 0)
      f = 1.57079632679489662;
    else {
      f = 0.0;
    }
  }
  if (u < 0.0)
    f = 3.14159265358979324 - f;
  return (v < 0.0 ? -f : f);
}


x86 assembly (clang, -O0):
<atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1156 <atan2+0x46>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1160 <atan2+0x50>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    119e <atan2+0x8e>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11a8 <atan2+0x98>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11cf <atan2+0xbf>
jp     11cf <atan2+0xbf>
jmp    1276 <atan2+0x166>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    122c <atan2+0x11c>
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1213 <atan2+0x103>
jp     1213 <atan2+0x103>
movsd  0xdf7(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1227 <atan2+0x117>
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <_atan@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    1271 <atan2+0x161>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    125b <atan2+0x14b>
jp     125b <atan2+0x14b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    126c <atan2+0x15c>
movsd  -0x28(%rbp),%xmm0
xor    %edi,%edi
call   1030 <_atan@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    1271 <atan2+0x161>
jmp    12b2 <atan2+0x1a2>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1293 <atan2+0x183>
jp     1293 <atan2+0x183>
jmp    12a5 <atan2+0x195>
movsd  0xd65(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12ad <atan2+0x19d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12b2 <atan2+0x1a2>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    12d2 <atan2+0x1c2>
movsd  0xd40(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1306 <atan2+0x1f6>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1310 <atan2+0x200>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2>:
sub    $0x28,%rsp
movapd %xmm0,%xmm4
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    1124 <atan2+0x14>
jnp    1182 <atan2+0x72>
movapd 0xed4(%rip),%xmm3
movapd %xmm4,%xmm5
xorpd  %xmm3,%xmm5
movapd %xmm4,%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm5
andnpd %xmm4,%xmm0
orpd   %xmm5,%xmm0
xorpd  %xmm1,%xmm3
movapd %xmm1,%xmm5
cmpltsd %xmm2,%xmm5
andpd  %xmm5,%xmm3
andnpd %xmm1,%xmm5
orpd   %xmm3,%xmm5
ucomisd %xmm5,%xmm0
jbe    1195 <atan2+0x85>
divsd  %xmm0,%xmm5
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm5
jne    11a9 <atan2+0x99>
jp     11a9 <atan2+0x99>
movsd  0xe90(%rip),%xmm3
jmp    11d1 <atan2+0xc1>
cmpneqsd %xmm4,%xmm2
movsd  0xe81(%rip),%xmm3
andpd  %xmm2,%xmm3
jmp    11d1 <atan2+0xc1>
divsd  %xmm5,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jne    11a5 <atan2+0x95>
jnp    11d1 <atan2+0xc1>
xor    %edi,%edi
jmp    11b2 <atan2+0xa2>
movapd %xmm5,%xmm0
mov    $0x2,%edi
movapd %xmm4,0x10(%rsp)
movapd %xmm1,(%rsp)
call   1030 <_atan@plt>
movapd (%rsp),%xmm1
movapd 0x10(%rsp),%xmm4
movapd %xmm0,%xmm3
movsd  0xe3f(%rip),%xmm0
subsd  %xmm3,%xmm0
xorpd  %xmm2,%xmm2
cmpltsd %xmm2,%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm3,%xmm1
orpd   %xmm0,%xmm1
movapd 0xe06(%rip),%xmm0
xorpd  %xmm1,%xmm0
cmpltsd %xmm2,%xmm4
movapd %xmm4,%xmm2
andnpd %xmm1,%xmm2
andpd  %xmm0,%xmm4
orpd   %xmm2,%xmm4
movapd %xmm4,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @atan2(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
store double %1, double* %4
%8 = load double, double* %3
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load double, double* %3
%12 = fneg double %11
br label %15
13: ; preds = %2
%14 = load double, double* %3
br label %15
15: ; preds = %13, %10
%16 = phi double [ %12, %10 ], [ %14, %13 ]
store double %16, double* %6
%17 = load double, double* %4
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load double, double* %4
%21 = fneg double %20
br label %24
22: ; preds = %15
%23 = load double, double* %4
br label %24
24: ; preds = %22, %19
%25 = phi double [ %21, %19 ], [ %23, %22 ]
store double %25, double* %5
%26 = load double, double* %4
%27 = fcmp une double %26, 0.000000e+00
br i1 %27, label %28, label %53
28: ; preds = %24
%29 = load double, double* %6
%30 = load double, double* %5
%31 = fcmp ogt double %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load double, double* %5
%34 = load double, double* %6
%35 = fdiv double %33, %34
store double %35, double* %7
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %37, label %38
37: ; preds = %32
store double 0x3FF921FB54442D18, double* %7
br label %41
38: ; preds = %32
%39 = load double, double* %7
%40 = call double @_atan(double %39, i32 2)
store double %40, double* %7
br label %41
41: ; preds = %38, %37
br label %52
42: ; preds = %28
%43 = load double, double* %6
%44 = load double, double* %5
%45 = fdiv double %43, %44
store double %45, double* %7
%46 = fcmp oeq double %45, 0.000000e+00
br i1 %46, label %47, label %48
47: ; preds = %42
store double 0.000000e+00, double* %7
br label %51
48: ; preds = %42
%49 = load double, double* %7
%50 = call double @_atan(double %49, i32 0)
store double %50, double* %7
br label %51
51: ; preds = %48, %47
br label %52
52: ; preds = %51, %41
br label %59
53: ; preds = %24
%54 = load double, double* %3
%55 = fcmp une double %54, 0.000000e+00
br i1 %55, label %56, label %57
56: ; preds = %53
store double 0x3FF921FB54442D18, double* %7
br label %58
57: ; preds = %53
store double 0.000000e+00, double* %7
br label %58
58: ; preds = %57, %56
br label %59
59: ; preds = %58, %52
%60 = load double, double* %4
%61 = fcmp olt double %60, 0.000000e+00
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load double, double* %7
%64 = fsub double 0x400921FB54442D18, %63
store double %64, double* %7
br label %65
65: ; preds = %62, %59
%66 = load double, double* %3
%67 = fcmp olt double %66, 0.000000e+00
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load double, double* %7
%70 = fneg double %69
br label %73
71: ; preds = %65
%72 = load double, double* %7
br label %73
73: ; preds = %71, %68
%74 = phi double [ %70, %68 ], [ %72, %71 ]
ret double %74
}

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