#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 */
int /*<<< orphan*/ EDOM;
double atan(double);
int /*<<< orphan*/ errno;
double atan2(double arg1, double arg2) {
  if (arg1 == 0.0 && arg2 == 0.0) {
    errno = EDOM;
    return 0.0;
  }
  if (arg1 + arg2 == arg1) {
    if (arg1 >= 0)
      return 1.5707963267948966192313217;
    return -1.5707963267948966192313217;
  }
  arg1 = atan(arg1 / arg2);
  if (arg2 < 0) {
    if (arg1 <= 0)
      return arg1 + 3.1415926535897932384626434;
    ;
    return arg1 - 3.1415926535897932384626434;
    ;
  }
  return arg1;
}


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
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1171 <atan2+0x61>
jp     1171 <atan2+0x61>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1171 <atan2+0x61>
jp     1171 <atan2+0x61>
mov    0x2e8f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e76(%rip),%rax
mov    %ecx,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <atan2+0x11e>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11c2 <atan2+0xb2>
jp     11c2 <atan2+0xb2>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b0 <atan2+0xa0>
movsd  0xe6a(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <atan2+0x11e>
movsd  0xe50(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <atan2+0x11e>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1224 <atan2+0x114>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1209 <atan2+0xf9>
movsd  0xe06(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <atan2+0x11e>
movsd  -0x10(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <atan2+0x11e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2>:
push   %rax
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    113d <atan2+0x2d>
jp     113d <atan2+0x2d>
ucomisd %xmm2,%xmm1
jne    113d <atan2+0x2d>
jp     113d <atan2+0x2d>
mov    0x2ebc(%rip),%rax
mov    (%rax),%eax
mov    0x2ea3(%rip),%rcx
mov    %eax,(%rcx)
xorpd  %xmm0,%xmm0
pop    %rax
ret
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jne    1168 <atan2+0x58>
jp     1168 <atan2+0x58>
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
setb   %al
lea    0xeaf(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
pop    %rax
ret
divsd  %xmm1,%xmm0
movsd  %xmm1,(%rsp)
call   1030 <atan@plt>
xorpd  %xmm1,%xmm1
ucomisd (%rsp),%xmm1
jbe    118f <atan2+0x7f>
ucomisd %xmm0,%xmm1
jae    1191 <atan2+0x81>
addsd  0xe79(%rip),%xmm0
pop    %rax
ret
addsd  0xe67(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@EDOM = global i32 0
@errno = global i32 0
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 %13
8: ; preds = %2
%9 = load double, double* %5
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* @EDOM
store i32 %12, i32* @errno
store double 0.000000e+00, double* %3
br label %42
13: ; preds = %8, %2
%14 = load double, double* %4
%15 = load double, double* %5
%16 = fadd double %14, %15
%17 = load double, double* %4
%18 = fcmp oeq double %16, %17
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load double, double* %4
%21 = fcmp oge double %20, 0.000000e+00
br i1 %21, label %22, label %23
22: ; preds = %19
store double 0x3FF921FB54442D18, double* %3
br label %42
23: ; preds = %19
store double 0xBFF921FB54442D18, double* %3
br label %42
24: ; preds = %13
%25 = load double, double* %4
%26 = load double, double* %5
%27 = fdiv double %25, %26
%28 = call double @atan(double %27)
store double %28, double* %4
%29 = load double, double* %5
%30 = fcmp olt double %29, 0.000000e+00
br i1 %30, label %31, label %40
31: ; preds = %24
%32 = load double, double* %4
%33 = fcmp ole double %32, 0.000000e+00
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load double, double* %4
%36 = fadd double %35, 0x400921FB54442D18
store double %36, double* %3
br label %42
37: ; preds = %31
%38 = load double, double* %4
%39 = fsub double %38, 0x400921FB54442D18
store double %39, double* %3
br label %42
40: ; preds = %24
%41 = load double, double* %4
store double %41, double* %3
br label %42
42: ; preds = %40, %37, %34, %23, %22, %11
%43 = load double, double* %3
ret double %43
}

LLVM IR (-O2):
@EDOM = global i32 0
@errno = global i32 0
define double @atan2(double %0, double %1) {
%3 = fcmp oeq double %0, 0.000000e+00
%4 = fcmp oeq double %1, 0.000000e+00
%5 = and i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EDOM
store i32 %7, i32* @errno
br label %24
8: ; preds = %2
%9 = fadd double %0, %1
%10 = fcmp oeq double %9, %0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = fcmp ult double %0, 0.000000e+00
%13 = select i1 %12, double 0xBFF921FB54442D18, double 0x3FF921FB54442D18
br label %24
14: ; preds = %8
%15 = fdiv double %0, %1
%16 = tail call double @atan(double %15)
%17 = fcmp olt double %1, 0.000000e+00
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = fcmp ugt double %16, 0.000000e+00
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = fadd double %16, 0x400921FB54442D18
br label %24
22: ; preds = %18
%23 = fadd double %16, 0xC00921FB54442D18
br label %24
24: ; preds = %14, %11, %22, %20, %6
%25 = phi double [ 0.000000e+00, %6 ], [ %21, %20 ], [ %23, %22 ], [ %13, %11 ], [ %16, %14 ]
ret double %25
}