double dmod(dnum, dm)
double dnum, dm;
{
  double dnumx, dnumi, dnumf;
  if (dnum < 0.0)
    dnumx = -dnum;
  else
    dnumx = dnum;
  dnumi = dint(dnumx / dm);
  if (dnum < 0.0)
    dnumf = dnum + (dnumi * dm);
  else if (dnum > 0.0)
    dnumf = dnum - (dnumi * dm);
  else
    dnumf = 0.0;
  return (dnumf);
}


x86 assembly (clang, -O0):
<dmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1156 <dmod+0x46>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1160 <dmod+0x50>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
mov    $0x1,%al
call   1030 <dint@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11a9 <dmod+0x99>
movsd  -0x8(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1200 <dmod+0xf0>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11f3 <dmod+0xe3>
movsd  -0x8(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11fb <dmod+0xeb>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1200 <dmod+0xf0>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmod>:
sub    $0x28,%rsp
movapd %xmm0,%xmm4
movapd %xmm0,0x10(%rsp)
movapd 0xeda(%rip),%xmm2
xorpd  %xmm0,%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm4,%xmm0
orpd   %xmm2,%xmm0
movsd  %xmm1,0x8(%rsp)
divsd  %xmm1,%xmm0
mov    $0x1,%al
call   1030 <dint@plt>
xorpd  %xmm3,%xmm3
movapd 0x10(%rsp),%xmm1
ucomisd %xmm1,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
jbe    1176 <dmod+0x66>
mulsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x28,%rsp
ret
movsd  0x8(%rsp),%xmm2
ucomisd %xmm3,%xmm1
jbe    1193 <dmod+0x83>
mulsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret
xorpd  %xmm0,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @dmod(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
store double %1, double* %4
%8 = load double, double* %3
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load double, double* %3
%12 = fneg double %11
store double %12, double* %5
br label %15
13: ; preds = %2
%14 = load double, double* %3
store double %14, double* %5
br label %15
15: ; preds = %13, %10
%16 = load double, double* %5
%17 = load double, double* %4
%18 = fdiv double %16, %17
%19 = call i32 (double, ...) bitcast (i32 (...)* @dint to i32 (double, ...)*)(double %18)
%20 = sitofp i32 %19 to double
store double %20, double* %6
%21 = load double, double* %3
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load double, double* %3
%25 = load double, double* %6
%26 = load double, double* %4
%27 = call double @llvm.fmuladd.f64(double %25, double %26, double %24)
store double %27, double* %7
br label %39
28: ; preds = %15
%29 = load double, double* %3
%30 = fcmp ogt double %29, 0.000000e+00
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load double, double* %3
%33 = load double, double* %6
%34 = load double, double* %4
%35 = fneg double %33
%36 = call double @llvm.fmuladd.f64(double %35, double %34, double %32)
store double %36, double* %7
br label %38
37: ; preds = %28
store double 0.000000e+00, double* %7
br label %38
38: ; preds = %37, %31
br label %39
39: ; preds = %38, %23
%40 = load double, double* %7
ret double %40
}

LLVM IR (-O2):
define double @dmod(double %0, double %1) {
%3 = fcmp olt double %0, 0.000000e+00
%4 = fneg double %0
%5 = select i1 %3, double %4, double %0
%6 = fdiv double %5, %1
%7 = tail call i32 (double, ...) bitcast (i32 (...)* @dint to i32 (double, ...)*)(double %6)
%8 = sitofp i32 %7 to double
br i1 %3, label %9, label %11
9: ; preds = %2
%10 = tail call double @llvm.fmuladd.f64(double %8, double %1, double %0)
br label %16
11: ; preds = %2
%12 = fcmp ogt double %0, 0.000000e+00
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = fneg double %8
%15 = tail call double @llvm.fmuladd.f64(double %14, double %1, double %0)
br label %16
16: ; preds = %11, %13, %9
%17 = phi double [ %10, %9 ], [ %15, %13 ], [ 0.000000e+00, %11 ]
ret double %17
}