#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 __ieee754_rem_pio2(double, double *);
double __kernel_tan(double, double, int);
double tan(double x) {
  double y[2], z = 0.0;
  int n, ix;
  ix = *(1 + (int *)&x);
  ix &= 0x7fffffff;
  if (ix <= 0x3fe921fb) {
    return __kernel_tan(x, z, 1);
  } else if (ix >= 0x7ff00000) {
    return x - x;
  } else {
    n = __ieee754_rem_pio2(x, y);
    return __kernel_tan(y[0], y[1], 1 - ((n & 1) << 1));
  }
}


x86 assembly (clang, -O0):
<tan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     1171 <tan+0x51>
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_tan@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11c7 <tan+0xa7>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     1192 <tan+0x72>
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c7 <tan+0xa7>
movsd  -0x10(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1040 <__ieee754_rem_pio2@plt>
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
shl    $0x1,%eax
mov    $0x1,%edi
sub    %eax,%edi
call   1030 <__kernel_tan@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tan>:
movq   %xmm0,%rax
shr    $0x20,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     1142 <tan+0x22>
xorps  %xmm1,%xmm1
mov    $0x1,%edi
jmp    1030 <__kernel_tan@plt>
cmp    $0x7ff00000,%eax
jb     114e <tan+0x2e>
subsd  %xmm0,%xmm0
ret
sub    $0x18,%rsp
mov    %rsp,%rdi
call   1040 <__ieee754_rem_pio2@plt>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
add    %eax,%eax
and    $0x2,%eax
mov    $0x1,%edi
sub    %eax,%edi
call   1030 <__kernel_tan@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @tan(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca [2 x double]
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double %0, double* %3
store double 0.000000e+00, double* %5
%8 = bitcast double* %3 to i32*
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = and i32 %11, 2147483647
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp sle i32 %13, 1072243195
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load double, double* %3
%17 = load double, double* %5
%18 = call double @__kernel_tan(double %16, double %17, i32 1)
store double %18, double* %2
br label %39
19: ; preds = %1
%20 = load i32, i32* %7
%21 = icmp sge i32 %20, 2146435072
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load double, double* %3
%24 = load double, double* %3
%25 = fsub double %23, %24
store double %25, double* %2
br label %39
26: ; preds = %19
%27 = load double, double* %3
%28 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%29 = call i32 @__ieee754_rem_pio2(double %27, double* %28)
store i32 %29, i32* %6
%30 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%31 = load double, double* %30
%32 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%33 = load double, double* %32
%34 = load i32, i32* %6
%35 = and i32 %34, 1
%36 = shl i32 %35, 1
%37 = sub nsw i32 1, %36
%38 = call double @__kernel_tan(double %31, double %33, i32 %37)
store double %38, double* %2
br label %39
39: ; preds = %26, %22, %15
%40 = load double, double* %2
ret double %40
}

LLVM IR (-O2):
define double @tan(double %0) {
%2 = alloca [2 x double]
%3 = bitcast [2 x double]* %2 to i8*
%4 = bitcast double %0 to i64
%5 = lshr i64 %4, 32
%6 = trunc i64 %5 to i32
%7 = and i32 %6, 2147483647
%8 = icmp ult i32 %7, 1072243196
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call double @__kernel_tan(double %0, double 0.000000e+00, i32 1)
br label %25
11: ; preds = %1
%12 = icmp ugt i32 %7, 2146435071
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = fsub double %0, %0
br label %25
15: ; preds = %11
%16 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%17 = call i32 @__ieee754_rem_pio2(double %0, double* %16)
%18 = load double, double* %16
%19 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%20 = load double, double* %19
%21 = shl i32 %17, 1
%22 = and i32 %21, 2
%23 = sub nsw i32 1, %22
%24 = call double @__kernel_tan(double %18, double %20, i32 %23)
br label %25
25: ; preds = %15, %13, %9
%26 = phi double [ %10, %9 ], [ %14, %13 ], [ %24, %15 ]
ret double %26
}