#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 */
long double fabsl(long double);
long double truncl(long double);
long double remainderl(long double x, long double y) {
  long double q = x / y;
  long double n = truncl(q);
  if (fabsl(n - q) >= 0.5L)
    ++n;
  return x - n * y;
}


x86 assembly (clang, -O0):
<remainderl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x20(%rbp)
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x10(%rbp)
fldt   -0x20(%rbp)
fdivrp %st,%st(1)
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <truncl@plt>
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
fsubrp %st,%st(1)
fabs
flds   0xeb1(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     116a <remainderl+0x5a>
jmp    1160 <remainderl+0x50>
fldt   -0x40(%rbp)
fld1
faddp  %st,%st(1)
fstpt  -0x40(%rbp)
fldt   -0x10(%rbp)
fldt   -0x40(%rbp)
fldt   -0x20(%rbp)
fmulp  %st,%st(1)
fsubrp %st,%st(1)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remainderl>:
sub    $0x38,%rsp
fldt   0x50(%rsp)
fld    %st(0)
fstpt  0x20(%rsp)
fldt   0x40(%rsp)
fld    %st(0)
fstpt  0x2c(%rsp)
fdivp  %st,%st(1)
fld    %st(0)
fstpt  0x14(%rsp)
fstpt  (%rsp)
call   1030 <truncl@plt>
fldt   0x14(%rsp)
fsubr  %st(1),%st
fabs
flds   0xeba(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
fld1
fadd   %st(1),%st
fcmovb %st(1),%st
fstp   %st(1)
fldt   0x20(%rsp)
fmulp  %st,%st(1)
fldt   0x2c(%rsp)
fsubp  %st,%st(1)
add    $0x38,%rsp
ret

LLVM IR (-O0):
define x86_fp80 @remainderl(x86_fp80 %0, x86_fp80 %1) {
%3 = alloca x86_fp80
%4 = alloca x86_fp80
%5 = alloca x86_fp80
%6 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %3
store x86_fp80 %1, x86_fp80* %4
%7 = load x86_fp80, x86_fp80* %3
%8 = load x86_fp80, x86_fp80* %4
%9 = fdiv x86_fp80 %7, %8
store x86_fp80 %9, x86_fp80* %5
%10 = load x86_fp80, x86_fp80* %5
%11 = call x86_fp80 @llvm.trunc.f80(x86_fp80 %10)
store x86_fp80 %11, x86_fp80* %6
%12 = load x86_fp80, x86_fp80* %6
%13 = load x86_fp80, x86_fp80* %5
%14 = fsub x86_fp80 %12, %13
%15 = call x86_fp80 @llvm.fabs.f80(x86_fp80 %14)
%16 = fcmp oge x86_fp80 %15, 0xK3FFE8000000000000000
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load x86_fp80, x86_fp80* %6
%19 = fadd x86_fp80 %18, 0xK3FFF8000000000000000
store x86_fp80 %19, x86_fp80* %6
br label %20
20: ; preds = %17, %2
%21 = load x86_fp80, x86_fp80* %3
%22 = load x86_fp80, x86_fp80* %6
%23 = load x86_fp80, x86_fp80* %4
%24 = fneg x86_fp80 %22
%25 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %24, x86_fp80 %23, x86_fp80 %21)
ret x86_fp80 %25
}

LLVM IR (-O2):
define x86_fp80 @remainderl(x86_fp80 %0, x86_fp80 %1) {
%3 = fdiv x86_fp80 %0, %1
%4 = tail call x86_fp80 @llvm.trunc.f80(x86_fp80 %3)
%5 = fsub x86_fp80 %4, %3
%6 = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %5)
%7 = fcmp ult x86_fp80 %6, 0xK3FFE8000000000000000
%8 = fadd x86_fp80 %4, 0xK3FFF8000000000000000
%9 = select i1 %7, x86_fp80 %4, x86_fp80 %8
%10 = fneg x86_fp80 %9
%11 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %10, x86_fp80 %1, x86_fp80 %0)
ret x86_fp80 %11
}