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


x86 assembly (clang, -O0):
<tan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     1174 <tan+0x54>
movsd  -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
call   1030 <__kernel_tan@plt>
jmp    11cc <tan+0xac>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     1198 <tan+0x78>
movsd  -0x8(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    11cc <tan+0xac>
movsd  -0x8(%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
mov    -0x10(%rbp),%rsi
call   1030 <__kernel_tan@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tan>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   %xmm0,%rax
shr    $0x20,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     1152 <tan+0x32>
xorps  %xmm1,%xmm1
mov    $0x1,%edi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <__kernel_tan@plt>
cmp    $0x7ff00000,%eax
jb     1163 <tan+0x43>
subsd  %xmm0,%xmm0
movsd  %xmm0,(%rbx)
jmp    118a <tan+0x6a>
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
mov    %rbx,%rsi
call   1030 <__kernel_tan@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

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