#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 __irmod(int /*<<< orphan*/);
double fabs(double);
int /*<<< orphan*/ round(double);
double trunc(double);
double remquo(double x, double y, int *quo) {
  double q = x / y;
  double n = trunc(q);
  if (fabs(n - q) >= 0.5)
    ++n;
  *quo = __irmod(round(q));
  return x - n * y;
}


x86 assembly (clang, -O0):
<remquo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <trunc@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xe9b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe7f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     119d <remquo+0x6d>
movsd  0xe75(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <round@plt>
mov    %eax,%edi
call   1030 <__irmod@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movsd  -0x8(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remquo>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x18(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <trunc@plt>
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm4
subsd  %xmm4,%xmm1
andpd  0xe97(%rip),%xmm1
movsd  0xe9f(%rip),%xmm2
addsd  %xmm0,%xmm2
movsd  0xe9b(%rip),%xmm3
cmpnlesd %xmm1,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm2,%xmm3
orpd   %xmm0,%xmm3
movapd %xmm3,0x20(%rsp)
movapd %xmm4,%xmm0
call   1050 <round@plt>
mov    %eax,%edi
call   1030 <__irmod@plt>
mov    %eax,(%rbx)
movapd 0x20(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @remquo(double %0, double %1, i32* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32*
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store i32* %2, i32** %6
%9 = load double, double* %4
%10 = load double, double* %5
%11 = fdiv double %9, %10
store double %11, double* %7
%12 = load double, double* %7
%13 = call double @llvm.trunc.f64(double %12)
store double %13, double* %8
%14 = load double, double* %8
%15 = load double, double* %7
%16 = fsub double %14, %15
%17 = call double @llvm.fabs.f64(double %16)
%18 = fcmp oge double %17, 5.000000e-01
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load double, double* %8
%21 = fadd double %20, 1.000000e+00
store double %21, double* %8
br label %22
22: ; preds = %19, %3
%23 = load double, double* %7
%24 = call i32 @round(double %23)
%25 = call i32 @__irmod(i32 %24)
%26 = load i32*, i32** %6
store i32 %25, i32* %26
%27 = load double, double* %4
%28 = load double, double* %8
%29 = load double, double* %5
%30 = fneg double %28
%31 = call double @llvm.fmuladd.f64(double %30, double %29, double %27)
ret double %31
}

LLVM IR (-O2):
define double @remquo(double %0, double %1, i32* nocapture writeonly %2) {
%4 = fdiv double %0, %1
%5 = tail call double @llvm.trunc.f64(double %4)
%6 = fsub double %5, %4
%7 = tail call double @llvm.fabs.f64(double %6)
%8 = fcmp ult double %7, 5.000000e-01
%9 = fadd double %5, 1.000000e+00
%10 = select i1 %8, double %5, double %9
%11 = tail call i32 @round(double %4)
%12 = tail call i32 @__irmod(i32 %11)
store i32 %12, i32* %2
%13 = fneg double %10
%14 = tail call double @llvm.fmuladd.f64(double %13, double %1, double %0)
ret double %14
}