#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_pio2l(long double, long double *);
long double kernel_cosl(long double, long double);
long double kernel_sinl(long double, long double, int);
long double cosl(long double x) {
  long double y[2], z = 0.0L;
  int n;
  if (x >= -0.7853981633974483096156608458198757210492 &&
      x <= 0.7853981633974483096156608458198757210492)
    return kernel_cosl(x, z);
  else if ((x + x == x && x != 0.0) || x != x)
    return x - x;
  else {
    n = ieee754_rem_pio2l(x, y);
    switch (n & 3) {
    case 0:
      return kernel_cosl(y[0], y[1]);
    case 1:
      return -kernel_sinl(y[0], y[1], 1);
    case 2:
      return -kernel_cosl(y[0], y[1]);
    default:
      return kernel_sinl(y[0], y[1], 1);
    }
  }
}


x86 assembly (clang, -O0):
<cosl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fldz
fstpt  -0x50(%rbp)
fldt   -0x20(%rbp)
fldl   0xeb1(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     1193 <cosl+0x63>
jmp    1160 <cosl+0x30>
fldt   -0x20(%rbp)
fldl   0xe9f(%rip)
fucomip %st(1),%st
fstp   %st(0)
jb     1193 <cosl+0x63>
jmp    1178 <cosl+0x48>
fldt   -0x20(%rbp)
fldt   -0x50(%rbp)
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
call   1030 <kernel_cosl@plt>
fstpt  -0x10(%rbp)
jmp    12a7 <cosl+0x177>
fldt   -0x20(%rbp)
fld    %st(0)
fadd   %st(1),%st
fucomip %st(1),%st
fstp   %st(0)
jne    11cb <cosl+0x9b>
jp     11cb <cosl+0x9b>
jmp    11af <cosl+0x7f>
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11db <cosl+0xab>
jp     11db <cosl+0xab>
jmp    11cb <cosl+0x9b>
fldt   -0x20(%rbp)
fucomip %st(0),%st
jnp    11e8 <cosl+0xb8>
jmp    11db <cosl+0xab>
fldt   -0x20(%rbp)
fsub   %st,%st(0)
fstpt  -0x10(%rbp)
jmp    12a7 <cosl+0x177>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    -0x40(%rbp),%rdi
call   1040 <ieee754_rem_pio2l@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x58(%rbp)
je     1232 <cosl+0x102>
jmp    1210 <cosl+0xe0>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
je     124d <cosl+0x11d>
jmp    1221 <cosl+0xf1>
mov    -0x58(%rbp),%eax
sub    $0x2,%eax
je     126f <cosl+0x13f>
jmp    128c <cosl+0x15c>
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
call   1030 <kernel_cosl@plt>
fstpt  -0x10(%rbp)
jmp    12a7 <cosl+0x177>
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
mov    $0x1,%edi
call   1050 <kernel_sinl@plt>
fchs
fstpt  -0x10(%rbp)
jmp    12a7 <cosl+0x177>
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
call   1030 <kernel_cosl@plt>
fchs
fstpt  -0x10(%rbp)
jmp    12a7 <cosl+0x177>
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
mov    $0x1,%edi
call   1050 <kernel_sinl@plt>
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosl>:
sub    $0x48,%rsp
fldt   0x50(%rsp)
fldl   0xec2(%rip)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jb     1163 <cosl+0x33>
fldl   0xebc(%rip)
fucomip %st(1),%st
jb     1163 <cosl+0x33>
fldz
fstpt  0x10(%rsp)
fstpt  (%rsp)
call   1030 <kernel_cosl@plt>
add    $0x48,%rsp
ret
fld    %st(0)
fadd   %st(1),%st
fucomip %st(1),%st
setnp  %sil
sete   %al
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
setp   %cl
setne  %dl
fucomi %st(0),%st
jp     11b3 <cosl+0x83>
and    %sil,%al
or     %cl,%dl
and    %al,%dl
jne    11b3 <cosl+0x83>
fstpt  (%rsp)
lea    0x20(%rsp),%rdi
call   1040 <ieee754_rem_pio2l@plt>
and    $0x3,%eax
cmp    $0x2,%eax
je     11ba <cosl+0x8a>
cmp    $0x1,%eax
je     11d0 <cosl+0xa0>
test   %eax,%eax
jne    11f0 <cosl+0xc0>
fldt   0x20(%rsp)
fldt   0x30(%rsp)
jmp    1152 <cosl+0x22>
fsub   %st,%st(0)
add    $0x48,%rsp
ret
fldt   0x20(%rsp)
fldt   0x30(%rsp)
fstpt  0x10(%rsp)
fstpt  (%rsp)
call   1030 <kernel_cosl@plt>
jmp    11e9 <cosl+0xb9>
fldt   0x20(%rsp)
fldt   0x30(%rsp)
fstpt  0x10(%rsp)
fstpt  (%rsp)
mov    $0x1,%edi
call   1050 <kernel_sinl@plt>
fchs
add    $0x48,%rsp
ret
fldt   0x20(%rsp)
fldt   0x30(%rsp)
fstpt  0x10(%rsp)
fstpt  (%rsp)
mov    $0x1,%edi
call   1050 <kernel_sinl@plt>
add    $0x48,%rsp
ret

LLVM IR (-O0):
define x86_fp80 @cosl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca x86_fp80
%4 = alloca [2 x x86_fp80]
%5 = alloca x86_fp80
%6 = alloca i32
store x86_fp80 %0, x86_fp80* %3
store x86_fp80 0xK00000000000000000000, x86_fp80* %5
%7 = load x86_fp80, x86_fp80* %3
%8 = fcmp oge x86_fp80 %7, 0xKBFFEC90FDAA22168C000
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load x86_fp80, x86_fp80* %3
%11 = fcmp ole x86_fp80 %10, 0xK3FFEC90FDAA22168C000
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load x86_fp80, x86_fp80* %3
%14 = load x86_fp80, x86_fp80* %5
%15 = call x86_fp80 @kernel_cosl(x86_fp80 %13, x86_fp80 %14)
store x86_fp80 %15, x86_fp80* %2
br label %65
16: ; preds = %9, %1
%17 = load x86_fp80, x86_fp80* %3
%18 = load x86_fp80, x86_fp80* %3
%19 = fadd x86_fp80 %17, %18
%20 = load x86_fp80, x86_fp80* %3
%21 = fcmp oeq x86_fp80 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load x86_fp80, x86_fp80* %3
%24 = fcmp une x86_fp80 %23, 0xK00000000000000000000
br i1 %24, label %29, label %25
25: ; preds = %22, %16
%26 = load x86_fp80, x86_fp80* %3
%27 = load x86_fp80, x86_fp80* %3
%28 = fcmp une x86_fp80 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25, %22
%30 = load x86_fp80, x86_fp80* %3
%31 = load x86_fp80, x86_fp80* %3
%32 = fsub x86_fp80 %30, %31
store x86_fp80 %32, x86_fp80* %2
br label %65
33: ; preds = %25
%34 = load x86_fp80, x86_fp80* %3
%35 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 0
%36 = call i32 @ieee754_rem_pio2l(x86_fp80 %34, x86_fp80* %35)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = and i32 %37, 3
switch i32 %38, label %59 [
i32 0, label %39
i32 1, label %45
i32 2, label %52
]
39: ; preds = %33
%40 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 0
%41 = load x86_fp80, x86_fp80* %40
%42 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 1
%43 = load x86_fp80, x86_fp80* %42
%44 = call x86_fp80 @kernel_cosl(x86_fp80 %41, x86_fp80 %43)
store x86_fp80 %44, x86_fp80* %2
br label %65
45: ; preds = %33
%46 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 0
%47 = load x86_fp80, x86_fp80* %46
%48 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 1
%49 = load x86_fp80, x86_fp80* %48
%50 = call x86_fp80 @kernel_sinl(x86_fp80 %47, x86_fp80 %49, i32 1)
%51 = fneg x86_fp80 %50
store x86_fp80 %51, x86_fp80* %2
br label %65
52: ; preds = %33
%53 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 0
%54 = load x86_fp80, x86_fp80* %53
%55 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 1
%56 = load x86_fp80, x86_fp80* %55
%57 = call x86_fp80 @kernel_cosl(x86_fp80 %54, x86_fp80 %56)
%58 = fneg x86_fp80 %57
store x86_fp80 %58, x86_fp80* %2
br label %65
59: ; preds = %33
%60 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 0
%61 = load x86_fp80, x86_fp80* %60
%62 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %4, i64 0, i64 1
%63 = load x86_fp80, x86_fp80* %62
%64 = call x86_fp80 @kernel_sinl(x86_fp80 %61, x86_fp80 %63, i32 1)
store x86_fp80 %64, x86_fp80* %2
br label %65
65: ; preds = %59, %52, %45, %39, %29, %12
%66 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %66
}

LLVM IR (-O2):
define x86_fp80 @cosl(x86_fp80 %0) {
%2 = alloca [2 x x86_fp80]
%3 = bitcast [2 x x86_fp80]* %2 to i8*
%4 = fcmp oge x86_fp80 %0, 0xKBFFEC90FDAA22168C000
%5 = fcmp ole x86_fp80 %0, 0xK3FFEC90FDAA22168C000
%6 = and i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call x86_fp80 @kernel_cosl(x86_fp80 %0, x86_fp80 0xK00000000000000000000)
br label %44
9: ; preds = %1
%10 = fadd x86_fp80 %0, %0
%11 = fcmp oeq x86_fp80 %10, %0
%12 = fcmp une x86_fp80 %0, 0xK00000000000000000000
%13 = and i1 %12, %11
%14 = fcmp uno x86_fp80 %0, 0xK00000000000000000000
%15 = or i1 %14, %13
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = fsub x86_fp80 %0, %0
br label %44
18: ; preds = %9
%19 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %2, i64 0, i64 0
%20 = call i32 @ieee754_rem_pio2l(x86_fp80 %0, x86_fp80* %19)
%21 = and i32 %20, 3
switch i32 %21, label %39 [
i32 0, label %22
i32 1, label %27
i32 2, label %33
]
22: ; preds = %18
%23 = load x86_fp80, x86_fp80* %19
%24 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %2, i64 0, i64 1
%25 = load x86_fp80, x86_fp80* %24
%26 = call x86_fp80 @kernel_cosl(x86_fp80 %23, x86_fp80 %25)
br label %44
27: ; preds = %18
%28 = load x86_fp80, x86_fp80* %19
%29 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %2, i64 0, i64 1
%30 = load x86_fp80, x86_fp80* %29
%31 = call x86_fp80 @kernel_sinl(x86_fp80 %28, x86_fp80 %30, i32 1)
%32 = fneg x86_fp80 %31
br label %44
33: ; preds = %18
%34 = load x86_fp80, x86_fp80* %19
%35 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %2, i64 0, i64 1
%36 = load x86_fp80, x86_fp80* %35
%37 = call x86_fp80 @kernel_cosl(x86_fp80 %34, x86_fp80 %36)
%38 = fneg x86_fp80 %37
br label %44
39: ; preds = %18
%40 = load x86_fp80, x86_fp80* %19
%41 = getelementptr inbounds [2 x x86_fp80], [2 x x86_fp80]* %2, i64 0, i64 1
%42 = load x86_fp80, x86_fp80* %41
%43 = call x86_fp80 @kernel_sinl(x86_fp80 %40, x86_fp80 %42, i32 1)
br label %44
44: ; preds = %39, %33, %27, %22, %16, %7
%45 = phi x86_fp80 [ %8, %7 ], [ %17, %16 ], [ %43, %39 ], [ %38, %33 ], [ %32, %27 ], [ %26, %22 ]
ret x86_fp80 %45
}