#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 a, double b) {
  double out;
  if (a >= 0) {
    out = (a - (floor(a / b) * b));
  } else {
    out = (a - (-floor(a / -b) * b));
  }
  if (out < 0) {
    return out + b;
  }
  return out;
}


x86 assembly (clang, -O0):
<mod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1180 <mod+0x70>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <floor@plt>
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11f9 <mod+0xe9>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
divsd  %xmm1,%xmm0
call   1030 <floor@plt>
movsd  -0x30(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%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,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    121b <mod+0x10b>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <mod+0x115>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod>:
sub    $0x28,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
movapd %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
jae    1141 <mod+0x31>
movapd 0xece(%rip),%xmm2
xorpd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
call   1030 <floor@plt>
jmp    1152 <mod+0x42>
divsd  %xmm1,%xmm0
call   1030 <floor@plt>
xorpd  0xeae(%rip),%xmm0
movapd 0x10(%rsp),%xmm3
mulsd  %xmm3,%xmm0
addsd  0x8(%rsp),%xmm0
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm1
cmpltsd %xmm2,%xmm1
andpd  %xmm1,%xmm3
movsd  0xe95(%rip),%xmm2
andnpd %xmm2,%xmm1
orpd   %xmm3,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

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

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