#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 floor(double);
double mod(double x, double y) {
  double quotient;
  quotient = x / y;
  if (quotient >= 0)
    quotient = floor(quotient);
  else
    quotient = -floor(-quotient);
  return (x - y * quotient);
}


x86 assembly (clang, -O0):
<mod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1157 <mod+0x47>
movsd  -0x18(%rbp),%xmm0
call   1030 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    1194 <mod+0x84>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <floor@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod>:
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    1145 <mod+0x35>
xorpd  0xeca(%rip),%xmm0
call   1030 <floor@plt>
xorpd  0xebd(%rip),%xmm0
jmp    114a <mod+0x3a>
call   1030 <floor@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @mod(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %3
%7 = load double, double* %4
%8 = fdiv double %6, %7
store double %8, double* %5
%9 = load double, double* %5
%10 = fcmp oge double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load double, double* %5
%13 = call double @llvm.floor.f64(double %12)
store double %13, double* %5
br label %19
14: ; preds = %2
%15 = load double, double* %5
%16 = fneg double %15
%17 = call double @llvm.floor.f64(double %16)
%18 = fneg double %17
store double %18, double* %5
br label %19
19: ; preds = %14, %11
%20 = load double, double* %3
%21 = load double, double* %4
%22 = load double, double* %5
%23 = fneg double %21
%24 = call double @llvm.fmuladd.f64(double %23, double %22, double %20)
ret double %24
}

LLVM IR (-O2):
define double @mod(double %0, double %1) {
%3 = fdiv double %0, %1
%4 = fcmp ult double %3, 0.000000e+00
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call double @llvm.floor.f64(double %3)
br label %11
7: ; preds = %2
%8 = fneg double %3
%9 = tail call double @llvm.floor.f64(double %8)
%10 = fneg double %9
br label %11
11: ; preds = %7, %5
%12 = phi double [ %6, %5 ], [ %10, %7 ]
%13 = fneg double %1
%14 = tail call double @llvm.fmuladd.f64(double %13, double %12, double %0)
ret double %14
}