#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 M_PI;
int fabs(double);
scalar_t__ floor(double);
int /*<<< orphan*/ tan(int);
double tanh(int /*<<< orphan*/);
double tri(double phase) {
  phase -= floor(phase + 0.5);
  return tanh(tan(2 * M_PI * fabs(phase) - 0.5 * M_PI));
}


x86 assembly (clang, -O0):
<tri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xeb3(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1060 <floor@plt>
cvtsi2sd %rax,%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
mov    0x2e4a(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  0xe56(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <tan@plt>
mov    %eax,%edi
call   1030 <tanh@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tri>:
push   %rbp
push   %rbx
push   %rax
movapd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movsd  0xeac(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
mov    0x2e73(%rip),%rbx
mov    (%rbx),%ebp
call   1040 <fabs@plt>
imul   %ebp,%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl (%rbx),%xmm1
mulsd  0xe71(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1050 <tan@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <tanh@plt>

LLVM IR (-O0):
@M_PI = global i32 0
define double @tri(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fadd double %3, 5.000000e-01
%5 = call i64 @floor(double %4)
%6 = sitofp i64 %5 to double
%7 = load double, double* %2
%8 = fsub double %7, %6
store double %8, double* %2
%9 = load i32, i32* @M_PI
%10 = mul nsw i32 2, %9
%11 = load double, double* %2
%12 = call i32 @fabs(double %11)
%13 = mul nsw i32 %10, %12
%14 = sitofp i32 %13 to double
%15 = load i32, i32* @M_PI
%16 = sitofp i32 %15 to double
%17 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %16, double %14)
%18 = fptosi double %17 to i32
%19 = call i32 @tan(i32 %18)
%20 = call double @tanh(i32 %19)
ret double %20
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @tri(double %0) {
%2 = fadd double %0, 5.000000e-01
%3 = tail call i64 @floor(double %2)
%4 = sitofp i64 %3 to double
%5 = fsub double %0, %4
%6 = load i32, i32* @M_PI
%7 = shl nsw i32 %6, 1
%8 = tail call i32 @fabs(double %5)
%9 = mul nsw i32 %7, %8
%10 = sitofp i32 %9 to double
%11 = load i32, i32* @M_PI
%12 = sitofp i32 %11 to double
%13 = tail call double @llvm.fmuladd.f64(double %12, double -5.000000e-01, double %10)
%14 = fptosi double %13 to i32
%15 = tail call i32 @tan(i32 %14)
%16 = tail call double @tanh(i32 %15)
ret double %16
}