#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 cos(double);
int remainder(double, int);
double sqrt(double);
void cmco_sine(double *x, double *sx, double *cx) {
  *x = (*x > 0) ? remainder(*x, 2 * 3.141592653589793)
                : remainder(*x, 2 * 3.141592653589793) + 2 * 3.141592653589793;
  *cx = cos(*x);
  *sx = (*x > 3.141592653589793) ? -sqrt(1.0 - (*cx * *cx))
                                 : sqrt(1.0 - (*cx * *cx));
}


x86 assembly (clang, -O0):
<cmco_sine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1179 <cmco_sine+0x49>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    $0x6,%edi
call   1030 <remainder@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11a0 <cmco_sine+0x70>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    $0x6,%edi
call   1030 <remainder@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe69(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
call   1040 <cos@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe36(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1239 <cmco_sine+0x109>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe01(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    127a <cmco_sine+0x14a>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xda4(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmco_sine>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x6,%edi
call   1030 <remainder@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe9e(%rip),%xmm2
addsd  %xmm1,%xmm2
xorpd  %xmm0,%xmm0
cmpltsd 0x8(%rsp),%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movlpd %xmm0,(%rbx)
call   1040 <cos@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,(%r15)
movsd  (%rbx),%xmm3
mulsd  %xmm0,%xmm1
movsd  0xe69(%rip),%xmm0
subsd  %xmm1,%xmm0
ucomisd 0xe6d(%rip),%xmm0
jb     11b3 <cmco_sine+0x83>
sqrtsd %xmm0,%xmm0
jmp    11c4 <cmco_sine+0x94>
movsd  %xmm3,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movapd 0xe54(%rip),%xmm1
xorpd  %xmm0,%xmm1
movsd  0xe38(%rip),%xmm2
cmpltsd %xmm3,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movlpd %xmm2,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @cmco_sine(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%7 = load double*, double** %4
%8 = load double, double* %7
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load double*, double** %4
%12 = load double, double* %11
%13 = call i32 @remainder(double %12, i32 6)
%14 = sitofp i32 %13 to double
br label %21
15: ; preds = %3
%16 = load double*, double** %4
%17 = load double, double* %16
%18 = call i32 @remainder(double %17, i32 6)
%19 = sitofp i32 %18 to double
%20 = fadd double %19, 0x401921FB54442D18
br label %21
21: ; preds = %15, %10
%22 = phi double [ %14, %10 ], [ %20, %15 ]
%23 = load double*, double** %4
store double %22, double* %23
%24 = load double*, double** %4
%25 = load double, double* %24
%26 = call double @cos(double %25)
%27 = load double*, double** %6
store double %26, double* %27
%28 = load double*, double** %4
%29 = load double, double* %28
%30 = fcmp ogt double %29, 0x400921FB54442D18
br i1 %30, label %31, label %40
31: ; preds = %21
%32 = load double*, double** %6
%33 = load double, double* %32
%34 = load double*, double** %6
%35 = load double, double* %34
%36 = fneg double %33
%37 = call double @llvm.fmuladd.f64(double %36, double %35, double 1.000000e+00)
%38 = call double @sqrt(double %37)
%39 = fneg double %38
br label %48
40: ; preds = %21
%41 = load double*, double** %6
%42 = load double, double* %41
%43 = load double*, double** %6
%44 = load double, double* %43
%45 = fneg double %42
%46 = call double @llvm.fmuladd.f64(double %45, double %44, double 1.000000e+00)
%47 = call double @sqrt(double %46)
br label %48
48: ; preds = %40, %31
%49 = phi double [ %39, %31 ], [ %47, %40 ]
%50 = load double*, double** %5
store double %49, double* %50
ret void
}

LLVM IR (-O2):
define void @cmco_sine(double* nocapture %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = load double, double* %0
%5 = fcmp ogt double %4, 0.000000e+00
%6 = tail call i32 @remainder(double %4, i32 6)
%7 = sitofp i32 %6 to double
%8 = fadd double %7, 0x401921FB54442D18
%9 = select i1 %5, double %7, double %8
store double %9, double* %0
%10 = tail call double @cos(double %9)
store double %10, double* %2
%11 = load double, double* %0
%12 = fcmp ogt double %11, 0x400921FB54442D18
%13 = fneg double %10
%14 = tail call double @llvm.fmuladd.f64(double %13, double %10, double 1.000000e+00)
%15 = tail call double @sqrt(double %14)
%16 = fneg double %15
%17 = select i1 %12, double %16, double %15
store double %17, double* %1
ret void
}