#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 /*<<< orphan*/ modf(double, double *);
double fmod(double x, double y) {
  double z;
  double result;
  if (y == 0.0) {
    return 0;
  }
  modf(x / y, &z);
  result = x - z * y;
  if ((x < 0) && (result > 0)) {
    result = -result;
  }
  return (result);
}


x86 assembly (clang, -O0):
<fmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1147 <fmod+0x37>
jp     1147 <fmod+0x37>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d8 <fmod+0xc8>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1030 <modf@plt>
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11ce <fmod+0xbe>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ce <fmod+0xbe>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmod>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1121 <fmod+0x11>
jp     1121 <fmod+0x11>
ret
sub    $0x28,%rsp
movapd %xmm2,%xmm0
divsd  %xmm1,%xmm0
lea    0x8(%rsp),%rdi
movapd %xmm2,0x10(%rsp)
movsd  %xmm1,(%rsp)
call   1030 <modf@plt>
movsd  (%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm3
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
movapd 0xe9d(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
cmpltsd %xmm2,%xmm3
cmpltsd %xmm0,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm3,%xmm1
andpd  %xmm3,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

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

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