#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 */
double modf(double, double *);
double sinus(double arg, int quad) {
  double e, f, ysq, x, y, temp1, temp2;
  int k;
  x = arg;
  if (x < 0) {
    x = -x;
    quad += 2;
  }
  x *= 1 / 1.570796326794896619231e0;
  if (x > 32764) {
    y = modf(x, &e);
    e += quad;
    modf(0.25 * e, &f);
    quad = e - 4 * f;
  } else {
    k = x;
    y = x - k;
    quad += k;
    quad &= 3;
  }
  if (quad & 1)
    y = 1 - y;
  if (quad > 1)
    y = -y;
  ysq = y * y;
  temp1 =
      ((((.1459688406665768722226959e3 * ysq + -.1384727249982452873054457e5) *
             ysq +
         .4401030535375266501944918e6) *
            ysq +
        -.4942908100902844161158627e7) *
           ysq +
       .1357884097877375669092680e8) *
      y;
  temp2 = ((((ysq + .1326534908786136358911494e3) * ysq +
             .9463096101538208180571257e4) *
                ysq +
            .4081792252343299749395779e6) *
               ysq +
           .8644558652922534429915149e7);
  return temp1 / temp2;
}


x86 assembly (clang, -O0):
<sinus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1162 <sinus+0x52>
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
movsd  0xe9e(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe7f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e9 <sinus+0xd9>
movsd  -0x30(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe63(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1030 <modf@plt>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
jmp    1216 <sinus+0x106>
cvttsd2si -0x30(%rbp),%eax
mov    %eax,-0x4c(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x4c(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4c(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1237 <sinus+0x127>
movsd  0xdf3(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    1262 <sinus+0x152>
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xde2(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdde(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb9(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd7f(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd61(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd43(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd26(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd09(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sinus>:
push   %rbx
sub    $0x30,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
lea    0x2(%rdi),%ebx
movapd 0xed8(%rip),%xmm2
xorpd  %xmm0,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm2
cmovbe %edi,%ebx
andnpd %xmm0,%xmm3
orpd   %xmm2,%xmm3
mulsd  0xec4(%rip),%xmm3
ucomisd 0xec4(%rip),%xmm3
jbe    11b8 <sinus+0xa8>
lea    0x18(%rsp),%rdi
movapd %xmm3,%xmm0
call   1030 <modf@plt>
movapd %xmm0,0x20(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
addsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xe9b(%rip),%xmm0
mulsd  %xmm1,%xmm0
lea    0x10(%rsp),%rdi
call   1030 <modf@plt>
movapd 0x20(%rsp),%xmm3
movsd  0x10(%rsp),%xmm0
mulsd  0xe81(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%ebx
test   $0x1,%bl
jne    11d2 <sinus+0xc2>
jmp    11e2 <sinus+0xd2>
cvttsd2si %xmm3,%eax
cvttpd2dq %xmm3,%xmm0
cvtdq2pd %xmm0,%xmm0
subsd  %xmm0,%xmm3
add    %eax,%ebx
and    $0x3,%ebx
test   $0x1,%bl
je     11e2 <sinus+0xd2>
movsd  0xe56(%rip),%xmm0
subsd  %xmm3,%xmm0
movapd %xmm0,%xmm3
cmp    $0x2,%ebx
jl     11ef <sinus+0xdf>
xorpd  0xe11(%rip),%xmm3
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
movsd  0xe39(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe35(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe31(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe2d(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe29(%rip),%xmm0
movsd  0xe29(%rip),%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe21(%rip),%xmm2
mulsd  %xmm3,%xmm0
mulsd  %xmm1,%xmm2
addsd  0xe19(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe15(%rip),%xmm2
divsd  %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @sinus(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%13 = load double, double* %3
store double %13, double* %8
%14 = load double, double* %8
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load double, double* %8
%18 = fneg double %17
store double %18, double* %8
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 2
store i32 %20, i32* %4
br label %21
21: ; preds = %16, %2
%22 = load double, double* %8
%23 = fmul double %22, 0x3FE45F306DC9C883
store double %23, double* %8
%24 = load double, double* %8
%25 = fcmp ogt double %24, 3.276400e+04
br i1 %25, label %26, label %40
26: ; preds = %21
%27 = load double, double* %8
%28 = call double @modf(double %27, double* %5)
store double %28, double* %9
%29 = load i32, i32* %4
%30 = sitofp i32 %29 to double
%31 = load double, double* %5
%32 = fadd double %31, %30
store double %32, double* %5
%33 = load double, double* %5
%34 = fmul double 2.500000e-01, %33
%35 = call double @modf(double %34, double* %6)
%36 = load double, double* %5
%37 = load double, double* %6
%38 = call double @llvm.fmuladd.f64(double -4.000000e+00, double %37, double %36)
%39 = fptosi double %38 to i32
store i32 %39, i32* %4
br label %52
40: ; preds = %21
%41 = load double, double* %8
%42 = fptosi double %41 to i32
store i32 %42, i32* %12
%43 = load double, double* %8
%44 = load i32, i32* %12
%45 = sitofp i32 %44 to double
%46 = fsub double %43, %45
store double %46, double* %9
%47 = load i32, i32* %12
%48 = load i32, i32* %4
%49 = add nsw i32 %48, %47
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = and i32 %50, 3
store i32 %51, i32* %4
br label %52
52: ; preds = %40, %26
%53 = load i32, i32* %4
%54 = and i32 %53, 1
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load double, double* %9
%58 = fsub double 1.000000e+00, %57
store double %58, double* %9
br label %59
59: ; preds = %56, %52
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 1
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load double, double* %9
%64 = fneg double %63
store double %64, double* %9
br label %65
65: ; preds = %62, %59
%66 = load double, double* %9
%67 = load double, double* %9
%68 = fmul double %66, %67
store double %68, double* %7
%69 = load double, double* %7
%70 = call double @llvm.fmuladd.f64(double 0x40623F00BE243F71, double %69, double 0xC0CB0BA2E1463542)
%71 = load double, double* %7
%72 = call double @llvm.fmuladd.f64(double %70, double %71, double 0x411ADC9C36D28A98)
%73 = load double, double* %7
%74 = call double @llvm.fmuladd.f64(double %72, double %73, double 0xC152DB0F06753134)
%75 = load double, double* %7
%76 = call double @llvm.fmuladd.f64(double %74, double %75, double 0x4169E64B1F521D57)
%77 = load double, double* %9
%78 = fmul double %76, %77
store double %78, double* %10
%79 = load double, double* %7
%80 = fadd double %79, 0x406094E965B3FC28
%81 = load double, double* %7
%82 = call double @llvm.fmuladd.f64(double %80, double %81, double 0x40C27B8C4D0E21DA)
%83 = load double, double* %7
%84 = call double @llvm.fmuladd.f64(double %82, double %83, double 0x4118E9CCE6A3D405)
%85 = load double, double* %7
%86 = call double @llvm.fmuladd.f64(double %84, double %85, double 0x41607CF9D4E4BDCD)
store double %86, double* %11
%87 = load double, double* %10
%88 = load double, double* %11
%89 = fdiv double %87, %88
ret double %89
}

LLVM IR (-O2):
define double @sinus(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %3 to i8*
%6 = bitcast double* %4 to i8*
%7 = fcmp olt double %0, 0.000000e+00
%8 = fneg double %0
%9 = add nsw i32 %1, 2
%10 = select i1 %7, double %8, double %0
%11 = select i1 %7, i32 %9, i32 %1
%12 = fmul double %10, 0x3FE45F306DC9C883
%13 = fcmp ogt double %12, 3.276400e+04
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = call double @modf(double %12, double* %3)
%16 = sitofp i32 %11 to double
%17 = load double, double* %3
%18 = fadd double %17, %16
%19 = fmul double %18, 2.500000e-01
%20 = call double @modf(double %19, double* %4)
%21 = load double, double* %4
%22 = tail call double @llvm.fmuladd.f64(double %21, double -4.000000e+00, double %18)
%23 = fptosi double %22 to i32
br label %30
24: ; preds = %2
%25 = fptosi double %12 to i32
%26 = sitofp i32 %25 to double
%27 = fsub double %12, %26
%28 = add nsw i32 %11, %25
%29 = and i32 %28, 3
br label %30
30: ; preds = %24, %14
%31 = phi double [ %15, %14 ], [ %27, %24 ]
%32 = phi i32 [ %23, %14 ], [ %29, %24 ]
%33 = and i32 %32, 1
%34 = icmp eq i32 %33, 0
%35 = fsub double 1.000000e+00, %31
%36 = select i1 %34, double %31, double %35
%37 = icmp sgt i32 %32, 1
%38 = fneg double %36
%39 = select i1 %37, double %38, double %36
%40 = fmul double %39, %39
%41 = tail call double @llvm.fmuladd.f64(double %40, double 0x40623F00BE243F71, double 0xC0CB0BA2E1463542)
%42 = tail call double @llvm.fmuladd.f64(double %41, double %40, double 0x411ADC9C36D28A98)
%43 = tail call double @llvm.fmuladd.f64(double %42, double %40, double 0xC152DB0F06753134)
%44 = tail call double @llvm.fmuladd.f64(double %43, double %40, double 0x4169E64B1F521D57)
%45 = fmul double %39, %44
%46 = fadd double %40, 0x406094E965B3FC28
%47 = tail call double @llvm.fmuladd.f64(double %46, double %40, double 0x40C27B8C4D0E21DA)
%48 = tail call double @llvm.fmuladd.f64(double %47, double %40, double 0x4118E9CCE6A3D405)
%49 = tail call double @llvm.fmuladd.f64(double %48, double %40, double 0x41607CF9D4E4BDCD)
%50 = fdiv double %45, %49
ret double %50
}