#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 fabs(scalar_t__);
double floor(double);
scalar_t__ fmod(double, int);
double calc_flattop_slope(double n) {
  double knee, midpoint, trough, top, slope;
  knee = 0.5 - fabs(fmod(n, 1.) - 0.5);
  midpoint = floor(n + 0.5);
  trough = 2. * midpoint - midpoint * midpoint / n;
  top = (1. - knee / n) / trough;
  slope = -top / (n - knee);
  return slope;
}


x86 assembly (clang, -O0):
<calc_flattop_slope>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    $0x1,%edi
call   1030 <fmod@plt>
cvtsi2sd %rax,%xmm0
movsd  0xeaf(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xe96(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe85(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
divsd  -0x8(%rbp),%xmm1
movsd  0xe24(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_flattop_slope>:
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%edi
call   1030 <fmod@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0xeac(%rip),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <fabs@plt>
movsd  0xea2(%rip),%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm1,%xmm0
call   1050 <floor@plt>
movsd  0x10(%rsp),%xmm4
movapd %xmm4,%xmm2
movsd  0x8(%rsp),%xmm3
divsd  %xmm3,%xmm2
movsd  0xe71(%rip),%xmm1
subsd  %xmm2,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
divsd  %xmm3,%xmm2
addsd  %xmm0,%xmm0
xorpd  0xe65(%rip),%xmm1
subsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
subsd  %xmm4,%xmm3
divsd  %xmm3,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @calc_flattop_slope(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %2
%8 = load double, double* %2
%9 = call i64 @fmod(double %8, i32 1)
%10 = sitofp i64 %9 to double
%11 = fsub double %10, 5.000000e-01
%12 = fptosi double %11 to i64
%13 = call double @fabs(i64 %12)
%14 = fsub double 5.000000e-01, %13
store double %14, double* %3
%15 = load double, double* %2
%16 = fadd double %15, 5.000000e-01
%17 = call double @llvm.floor.f64(double %16)
store double %17, double* %4
%18 = load double, double* %4
%19 = load double, double* %4
%20 = load double, double* %4
%21 = fmul double %19, %20
%22 = load double, double* %2
%23 = fdiv double %21, %22
%24 = fneg double %23
%25 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %18, double %24)
store double %25, double* %5
%26 = load double, double* %3
%27 = load double, double* %2
%28 = fdiv double %26, %27
%29 = fsub double 1.000000e+00, %28
%30 = load double, double* %5
%31 = fdiv double %29, %30
store double %31, double* %6
%32 = load double, double* %6
%33 = fneg double %32
%34 = load double, double* %2
%35 = load double, double* %3
%36 = fsub double %34, %35
%37 = fdiv double %33, %36
store double %37, double* %7
%38 = load double, double* %7
ret double %38
}

LLVM IR (-O2):
define double @calc_flattop_slope(double %0) {
%2 = tail call i64 @fmod(double %0, i32 1)
%3 = sitofp i64 %2 to double
%4 = fadd double %3, -5.000000e-01
%5 = fptosi double %4 to i64
%6 = tail call double @fabs(i64 %5)
%7 = fsub double 5.000000e-01, %6
%8 = fadd double %0, 5.000000e-01
%9 = tail call double @llvm.floor.f64(double %8)
%10 = fneg double %9
%11 = fmul double %9, %10
%12 = fdiv double %11, %0
%13 = tail call double @llvm.fmuladd.f64(double %9, double 2.000000e+00, double %12)
%14 = fdiv double %7, %0
%15 = fsub double 1.000000e+00, %14
%16 = fneg double %15
%17 = fdiv double %16, %13
%18 = fsub double %0, %7
%19 = fdiv double %17, %18
ret double %19
}