#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 trunc(double);
double f_mod(double f, double m) {
  double x;
  x = f / m;
  x = (x - trunc(x)) * m;
  while (x < 0)
    x += m;
  while (x > m)
    x -= m;
  return x;
}


x86 assembly (clang, -O0):
<f_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
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <trunc@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    117d <f_mod+0x6d>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    115b <f_mod+0x4b>
jmp    1182 <f_mod+0x72>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11aa <f_mod+0x9a>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1182 <f_mod+0x72>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_mod>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <trunc@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1164 <f_mod+0x54>
nopw   0x0(%rax,%rax,1)
addsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
ja     1150 <f_mod+0x40>
jmp    1164 <f_mod+0x54>
nopl   0x0(%rax)
subsd  %xmm2,%xmm1
ucomisd %xmm2,%xmm1
ja     1160 <f_mod+0x50>
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @f_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 = load double, double* %5
%11 = call double @llvm.trunc.f64(double %10)
%12 = fsub double %9, %11
%13 = load double, double* %4
%14 = fmul double %12, %13
store double %14, double* %5
br label %15
15: ; preds = %18, %2
%16 = load double, double* %5
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load double, double* %4
%20 = load double, double* %5
%21 = fadd double %20, %19
store double %21, double* %5
br label %15
22: ; preds = %15
br label %23
23: ; preds = %27, %22
%24 = load double, double* %5
%25 = load double, double* %4
%26 = fcmp ogt double %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load double, double* %4
%29 = load double, double* %5
%30 = fsub double %29, %28
store double %30, double* %5
br label %23
31: ; preds = %23
%32 = load double, double* %5
ret double %32
}

LLVM IR (-O2):
define double @f_mod(double %0, double %1) {
%3 = fdiv double %0, %1
%4 = tail call double @llvm.trunc.f64(double %3)
%5 = fsub double %3, %4
%6 = fmul double %5, %1
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %11, label %8
8: ; preds = %11, %2
%9 = phi double [ %6, %2 ], [ %13, %11 ]
%10 = fcmp ogt double %9, %1
br i1 %10, label %15, label %19
11: ; preds = %2, %11
%12 = phi double [ %13, %11 ], [ %6, %2 ]
%13 = fadd double %12, %1
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %11, label %8
15: ; preds = %8, %15
%16 = phi double [ %17, %15 ], [ %9, %8 ]
%17 = fsub double %16, %1
%18 = fcmp ogt double %17, %1
br i1 %18, label %15, label %19
19: ; preds = %15, %8
%20 = phi double [ %9, %8 ], [ %17, %15 ]
ret double %20
}