#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 ieee_tan(double x) {
  double y[2], z = 0.0;
  int n, ix;
  ix = *(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):
<ieee_tan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     1171 <ieee_tan+0x51>
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_tan@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11c7 <ieee_tan+0xa7>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     1192 <ieee_tan+0x72>
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c7 <ieee_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):
<ieee_tan>:
movq   %xmm0,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     113e <ieee_tan+0x1e>
xorps  %xmm1,%xmm1
mov    $0x1,%edi
jmp    1030 <__kernel_tan@plt>
cmp    $0x7ff00000,%eax
jb     114a <ieee_tan+0x2a>
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 @ieee_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 = load i32, i32* %8
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = and i32 %10, 2147483647
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp sle i32 %12, 1072243195
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load double, double* %3
%16 = load double, double* %5
%17 = call double @__kernel_tan(double %15, double %16, i32 1)
store double %17, double* %2
br label %38
18: ; preds = %1
%19 = load i32, i32* %7
%20 = icmp sge i32 %19, 2146435072
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fsub double %22, %23
store double %24, double* %2
br label %38
25: ; preds = %18
%26 = load double, double* %3
%27 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%28 = call i32 @__ieee754_rem_pio2(double %26, double* %27)
store i32 %28, i32* %6
%29 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%30 = load double, double* %29
%31 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%32 = load double, double* %31
%33 = load i32, i32* %6
%34 = and i32 %33, 1
%35 = shl i32 %34, 1
%36 = sub nsw i32 1, %35
%37 = call double @__kernel_tan(double %30, double %32, i32 %36)
store double %37, double* %2
br label %38
38: ; preds = %25, %21, %14
%39 = load double, double* %2
ret double %39
}

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