#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*/ ERANGE;
float HUGE_VALF;
int /*<<< orphan*/ errno;
float modff(float, float *);
float tanf(float arg) {
  float sign, temp, e, x, xsq;
  int flag, i;
  flag = 0;
  sign = 1.;
  if (arg < 0.) {
    arg = -arg;
    sign = -1.;
  }
  arg = arg * 1.27323954473516;
  x = modff(arg, &e);
  i = e;
  switch (i % 4) {
  case 1:
    x = 1. - x;
    flag = 1;
    break;
  case 2:
    sign = -sign;
    flag = 1;
    break;
  case 3:
    x = 1. - x;
    sign = -sign;
    break;
  case 0:
    break;
  }
  xsq = x * x;
  temp = ((((0.338663864267717e-4 * xsq + 0.342255438724100e-1) * xsq +
            -0.155068565348327e+2) *
               xsq +
           0.105597090171495e+4) *
              xsq +
          -0.130682026475483e+5) *
         x;
  temp = temp /
         (((1.0 * xsq + -0.155503316403171e+3) * xsq + 0.476575136291648e+4) *
              xsq +
          -0.166389523894712e+5);
  if (flag == 1) {
    if (temp == 0.) {
      errno = ERANGE;
      if (sign > 0)
        return (HUGE_VALF);
      return (-HUGE_VALF);
    }
    temp = 1. / temp;
  }
  return (sign * temp);
}


x86 assembly (clang, -O0):
<tanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movl   $0x0,-0x20(%rbp)
movss  0xed4(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    116b <tanf+0x5b>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0xe9e(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8c(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
lea    -0x14(%rbp),%rdi
call   1030 <modff@plt>
movss  %xmm0,-0x18(%rbp)
cvttss2si -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x3,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     1267 <tanf+0x157>
mov    -0x30(%rbp),%rax
lea    0xe86(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe24(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    1267 <tanf+0x157>
movss  -0xc(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    1267 <tanf+0x157>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdd7(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1267 <tanf+0x157>
jmp    1267 <tanf+0x157>
movss  -0x18(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdc1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdbd(%rip),%xmm1
addsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd94(%rip),%xmm1
addsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd73(%rip),%xmm1
addsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd52(%rip),%xmm1
addsd  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xd16(%rip),%xmm2
addsd  %xmm2,%xmm1
movss  -0x1c(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xcf5(%rip),%xmm2
addsd  %xmm2,%xmm1
movss  -0x1c(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xcd4(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    13f3 <tanf+0x2e3>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    13d5 <tanf+0x2c5>
jp     13d5 <tanf+0x2c5>
mov    0x2c5e(%rip),%rax
mov    (%rax),%ecx
mov    0x2c45(%rip),%rax
mov    %ecx,(%rax)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    13b3 <tanf+0x2a3>
mov    0x2c4b(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1402 <tanf+0x2f2>
mov    0x2c36(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1402 <tanf+0x2f2>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xc2a(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tanf>:
sub    $0x28,%rsp
xorps  %xmm1,%xmm1
xor    %eax,%eax
ucomiss %xmm0,%xmm1
seta   %al
lea    0xeea(%rip),%rcx
jbe    112f <tanf+0x1f>
xorps  0xed1(%rip),%xmm0
movss  (%rcx,%rax,4),%xmm1
movaps %xmm1,0x10(%rsp)
cvtss2sd %xmm0,%xmm0
mulsd  0xed3(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xc(%rsp),%rdi
call   1030 <modff@plt>
cvttss2si 0xc(%rsp),%eax
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cmp    $0x3,%eax
je     1188 <tanf+0x78>
cmp    $0x2,%eax
je     11a7 <tanf+0x97>
cmp    $0x1,%eax
jne    11b7 <tanf+0xa7>
movss  0xee3(%rip),%xmm1
subss  %xmm0,%xmm1
mov    $0x1,%al
movaps %xmm1,%xmm0
jmp    11b9 <tanf+0xa9>
movss  0xed0(%rip),%xmm1
subss  %xmm0,%xmm1
movaps 0x10(%rsp),%xmm3
xorps  0xe60(%rip),%xmm3
xor    %eax,%eax
movaps %xmm1,%xmm0
jmp    11be <tanf+0xae>
movaps 0x10(%rsp),%xmm3
xorps  0xe4d(%rip),%xmm3
mov    $0x1,%al
jmp    11be <tanf+0xae>
xor    %eax,%eax
movaps 0x10(%rsp),%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulss  %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe4b(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe47(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe43(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe3f(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe3b(%rip),%xmm2
mulsd  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtsd2ss %xmm2,%xmm1
movsd  0xe30(%rip),%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe28(%rip),%xmm2
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm2
addsd  0xe20(%rip),%xmm2
divsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
test   %al,%al
je     128b <tanf+0x17b>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    127c <tanf+0x16c>
jp     127c <tanf+0x16c>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    0x2d6f(%rip),%rcx
mov    %eax,(%rcx)
ucomiss %xmm1,%xmm3
mov    0x2d83(%rip),%rax
movss  (%rax),%xmm3
ja     128f <tanf+0x17f>
xorps  0xd86(%rip),%xmm3
jmp    128f <tanf+0x17f>
movss  0xddc(%rip),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
mulss  %xmm0,%xmm3
movaps %xmm3,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VALF = global float 0.000000e+00
define float @tanf(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
store float %0, float* %3
store i32 0, i32* %9
store float 1.000000e+00, float* %4
%11 = load float, float* %3
%12 = fpext float %11 to double
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load float, float* %3
%16 = fneg float %15
store float %16, float* %3
store float -1.000000e+00, float* %4
br label %17
17: ; preds = %14, %1
%18 = load float, float* %3
%19 = fpext float %18 to double
%20 = fmul double %19, 0x3FF45F306DC9C877
%21 = fptrunc double %20 to float
store float %21, float* %3
%22 = load float, float* %3
%23 = call float @modff(float %22, float* %6)
store float %23, float* %7
%24 = load float, float* %6
%25 = fptosi float %24 to i32
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = srem i32 %26, 4
switch i32 %27, label %44 [
i32 1, label %28
i32 2, label %33
i32 3, label %36
i32 0, label %43
]
28: ; preds = %17
%29 = load float, float* %7
%30 = fpext float %29 to double
%31 = fsub double 1.000000e+00, %30
%32 = fptrunc double %31 to float
store float %32, float* %7
store i32 1, i32* %9
br label %44
33: ; preds = %17
%34 = load float, float* %4
%35 = fneg float %34
store float %35, float* %4
store i32 1, i32* %9
br label %44
36: ; preds = %17
%37 = load float, float* %7
%38 = fpext float %37 to double
%39 = fsub double 1.000000e+00, %38
%40 = fptrunc double %39 to float
store float %40, float* %7
%41 = load float, float* %4
%42 = fneg float %41
store float %42, float* %4
br label %44
43: ; preds = %17
br label %44
44: ; preds = %17, %43, %36, %33, %28
%45 = load float, float* %7
%46 = load float, float* %7
%47 = fmul float %45, %46
store float %47, float* %8
%48 = load float, float* %8
%49 = fpext float %48 to double
%50 = call double @llvm.fmuladd.f64(double 0x3F01C1782D55FF44, double %49, double 0x3FA18602AF3D5848)
%51 = load float, float* %8
%52 = fpext float %51 to double
%53 = call double @llvm.fmuladd.f64(double %50, double %52, double 0xC02F0382B321BD9C)
%54 = load float, float* %8
%55 = fpext float %54 to double
%56 = call double @llvm.fmuladd.f64(double %53, double %55, double 0x40907FE2340F255D)
%57 = load float, float* %8
%58 = fpext float %57 to double
%59 = call double @llvm.fmuladd.f64(double %56, double %58, double 0xC0C98619F05AD848)
%60 = load float, float* %7
%61 = fpext float %60 to double
%62 = fmul double %59, %61
%63 = fptrunc double %62 to float
store float %63, float* %5
%64 = load float, float* %5
%65 = fpext float %64 to double
%66 = load float, float* %8
%67 = fpext float %66 to double
%68 = call double @llvm.fmuladd.f64(double 1.000000e+00, double %67, double 0xC063701B2B00651D)
%69 = load float, float* %8
%70 = fpext float %69 to double
%71 = call double @llvm.fmuladd.f64(double %68, double %70, double 0x40B29DC05951F1B5)
%72 = load float, float* %8
%73 = fpext float %72 to double
%74 = call double @llvm.fmuladd.f64(double %71, double %73, double 0xC0D03FBCF3F2F7F7)
%75 = fdiv double %65, %74
%76 = fptrunc double %75 to float
store float %76, float* %5
%77 = load i32, i32* %9
%78 = icmp eq i32 %77, 1
br i1 %78, label %79, label %97
79: ; preds = %44
%80 = load float, float* %5
%81 = fpext float %80 to double
%82 = fcmp oeq double %81, 0.000000e+00
br i1 %82, label %83, label %92
83: ; preds = %79
%84 = load i32, i32* @ERANGE
store i32 %84, i32* @errno
%85 = load float, float* %4
%86 = fcmp ogt float %85, 0.000000e+00
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = load float, float* @HUGE_VALF
store float %88, float* %2
br label %101
89: ; preds = %83
%90 = load float, float* @HUGE_VALF
%91 = fneg float %90
store float %91, float* %2
br label %101
92: ; preds = %79
%93 = load float, float* %5
%94 = fpext float %93 to double
%95 = fdiv double 1.000000e+00, %94
%96 = fptrunc double %95 to float
store float %96, float* %5
br label %97
97: ; preds = %92, %44
%98 = load float, float* %4
%99 = load float, float* %5
%100 = fmul float %98, %99
store float %100, float* %2
br label %101
101: ; preds = %97, %89, %87
%102 = load float, float* %2
ret float %102
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VALF = global float 0.000000e+00
define float @tanf(float %0) {
%2 = alloca float
%3 = bitcast float* %2 to i8*
%4 = fcmp olt float %0, 0.000000e+00
%5 = fneg float %0
%6 = select i1 %4, float -1.000000e+00, float 1.000000e+00
%7 = select i1 %4, float %5, float %0
%8 = fpext float %7 to double
%9 = fmul double %8, 0x3FF45F306DC9C877
%10 = fptrunc double %9 to float
%11 = call float @modff(float %10, float* %2)
%12 = load float, float* %2
%13 = fptosi float %12 to i32
%14 = srem i32 %13, 4
switch i32 %14, label %22 [
i32 1, label %15
i32 2, label %17
i32 3, label %19
]
15: ; preds = %1
%16 = fsub float 1.000000e+00, %11
br label %22
17: ; preds = %1
%18 = fneg float %6
br label %22
19: ; preds = %1
%20 = fsub float 1.000000e+00, %11
%21 = fneg float %6
br label %22
22: ; preds = %1, %19, %17, %15
%23 = phi float [ %6, %1 ], [ %21, %19 ], [ %18, %17 ], [ %6, %15 ]
%24 = phi float [ %11, %1 ], [ %20, %19 ], [ %11, %17 ], [ %16, %15 ]
%25 = phi i1 [ false, %1 ], [ false, %19 ], [ true, %17 ], [ true, %15 ]
%26 = fmul float %24, %24
%27 = fpext float %26 to double
%28 = tail call double @llvm.fmuladd.f64(double %27, double 0x3F01C1782D55FF44, double 0x3FA18602AF3D5848)
%29 = tail call double @llvm.fmuladd.f64(double %28, double %27, double 0xC02F0382B321BD9C)
%30 = tail call double @llvm.fmuladd.f64(double %29, double %27, double 0x40907FE2340F255D)
%31 = tail call double @llvm.fmuladd.f64(double %30, double %27, double 0xC0C98619F05AD848)
%32 = fpext float %24 to double
%33 = fmul double %31, %32
%34 = fptrunc double %33 to float
%35 = fpext float %34 to double
%36 = fadd double %27, 0xC063701B2B00651D
%37 = tail call double @llvm.fmuladd.f64(double %36, double %27, double 0x40B29DC05951F1B5)
%38 = tail call double @llvm.fmuladd.f64(double %37, double %27, double 0xC0D03FBCF3F2F7F7)
%39 = fdiv double %35, %38
%40 = fptrunc double %39 to float
br i1 %25, label %41, label %51
41: ; preds = %22
%42 = fcmp oeq float %40, 0.000000e+00
br i1 %42, label %43, label %49
43: ; preds = %41
%44 = load i32, i32* @ERANGE
store i32 %44, i32* @errno
%45 = fcmp ogt float %23, 0.000000e+00
%46 = load float, float* @HUGE_VALF
br i1 %45, label %54, label %47
47: ; preds = %43
%48 = fneg float %46
br label %54
49: ; preds = %41
%50 = fdiv float 1.000000e+00, %40
br label %51
51: ; preds = %49, %22
%52 = phi float [ %50, %49 ], [ %40, %22 ]
%53 = fmul float %23, %52
br label %54
54: ; preds = %43, %51, %47
%55 = phi float [ %48, %47 ], [ %53, %51 ], [ %46, %43 ]
ret float %55
}