#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 __arctan_sub(double);
double atan(double x) {
  int sign;
  sign = x >= 0 ? 1 : -1;
  x = x >= 0 ? x : -x;
  if (0.0 <= x && x <= 0.41421356) {
    return sign * __arctan_sub(x);
  } else if (0.41421356 < x && x <= 1.0) {
    double tmp;
    tmp = (1.0 - x) / (1.0 + x);
    return sign * (0.7853981 - __arctan_sub(tmp));
  } else if (1.0 <= x && x <= 2.41421356) {
    double tmp;
    tmp = (x - 1.0) / (x + 1.0);
    return sign * (0.7853981 + __arctan_sub(tmp));
  } else {
    double tmp;
    tmp = 1.0 / x;
    return sign * (1.5707963 - __arctan_sub(tmp));
  }
}


x86 assembly (clang, -O0):
<atan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
mov    $0xffffffff,%eax
mov    $0x1,%ecx
ucomisd %xmm1,%xmm0
cmovae %ecx,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     115a <atan+0x4a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    117b <atan+0x6b>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d4 <atan+0xc4>
movsd  0xe61(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11d4 <atan+0xc4>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <__arctan_sub@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1321 <atan+0x211>
movsd  -0x10(%rbp),%xmm0
movsd  0xe1f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1257 <atan+0x147>
movsd  0xe15(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1257 <atan+0x147>
movsd  0xe02(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xdf5(%rip),%xmm1
addsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <__arctan_sub@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  0xddb(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1321 <atan+0x211>
movsd  -0x10(%rbp),%xmm0
movsd  0xda4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12de <atan+0x1ce>
movsd  0xd9a(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     12de <atan+0x1ce>
movsd  -0x10(%rbp),%xmm0
movsd  0xd7a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xd6e(%rip),%xmm1
addsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <__arctan_sub@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  0xd54(%rip),%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1321 <atan+0x211>
movsd  0xd22(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <__arctan_sub@plt>
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
movsd  0xd04(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan>:
push   %rax
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
setae  %al
jae    1128 <atan+0x18>
xorpd  0xed8(%rip),%xmm0
add    %eax,%eax
add    $0xffffffff,%eax
ucomisd %xmm1,%xmm0
jb     1157 <atan+0x47>
movsd  0xed5(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     1157 <atan+0x47>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,(%rsp)
call   1030 <__arctan_sub@plt>
jmp    1222 <atan+0x112>
ucomisd 0xeb1(%rip),%xmm0
jbe    11a2 <atan+0x92>
movsd  0xeaf(%rip),%xmm2
ucomisd %xmm0,%xmm2
jb     11a2 <atan+0x92>
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
call   1030 <__arctan_sub@plt>
movapd %xmm0,%xmm1
movsd  0xe98(%rip),%xmm0
jmp    121e <atan+0x10e>
ucomisd 0xe6e(%rip),%xmm0
jb     11f1 <atan+0xe1>
movsd  0xe6c(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     11f1 <atan+0xe1>
movsd  0xe6e(%rip),%xmm1
addsd  %xmm0,%xmm1
addsd  0xe4a(%rip),%xmm0
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
call   1030 <__arctan_sub@plt>
addsd  0xe49(%rip),%xmm0
jmp    1222 <atan+0x112>
movsd  0xe1f(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
call   1030 <__arctan_sub@plt>
movapd %xmm0,%xmm1
movsd  0xe0a(%rip),%xmm0
subsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
pop    %rax
ret

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

LLVM IR (-O2):
define double @atan(double %0) {
%2 = fcmp oge double %0, 0.000000e+00
%3 = select i1 %2, i32 1, i32 -1
%4 = fneg double %0
%5 = select i1 %2, double %0, double %4
%6 = fcmp oge double %5, 0.000000e+00
%7 = fcmp ole double %5, 0x3FDA827997709F7A
%8 = and i1 %6, %7
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = sitofp i32 %3 to double
%11 = tail call double @__arctan_sub(double %5)
%12 = fmul double %11, %10
br label %43
13: ; preds = %1
%14 = fcmp ogt double %5, 0x3FDA827997709F7A
%15 = fcmp ole double %5, 1.000000e+00
%16 = and i1 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = fsub double 1.000000e+00, %5
%19 = fadd double %5, 1.000000e+00
%20 = fdiv double %18, %19
%21 = sitofp i32 %3 to double
%22 = tail call double @__arctan_sub(double %20)
%23 = fsub double 0x3FE921FB323AE5AF, %22
%24 = fmul double %23, %21
br label %43
25: ; preds = %13
%26 = fcmp oge double %5, 1.000000e+00
%27 = fcmp ole double %5, 0x4003504F32EE13EF
%28 = and i1 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = fadd double %5, -1.000000e+00
%31 = fadd double %5, 1.000000e+00
%32 = fdiv double %30, %31
%33 = sitofp i32 %3 to double
%34 = tail call double @__arctan_sub(double %32)
%35 = fadd double %34, 0x3FE921FB323AE5AF
%36 = fmul double %35, %33
br label %43
37: ; preds = %25
%38 = fdiv double 1.000000e+00, %5
%39 = sitofp i32 %3 to double
%40 = tail call double @__arctan_sub(double %38)
%41 = fsub double 0x3FF921FB4D12D84A, %40
%42 = fmul double %41, %39
br label %43
43: ; preds = %37, %29, %17, %9
%44 = phi double [ %12, %9 ], [ %24, %17 ], [ %36, %29 ], [ %42, %37 ]
ret double %44
}