#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 fmod(double, double);
double fmodulo(double v1, double v2) {
  if (v1 >= 0)
    return (v1 < v2) ? v1 : fmod(v1, v2);
  double tmp = fmod(v1, v2) + v2;
  return (tmp == v2) ? 0. : tmp;
}


x86 assembly (clang, -O0):
<fmodulo>:
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     117a <fmodulo+0x6a>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1157 <fmodulo+0x47>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    116b <fmodulo+0x5b>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <fmod@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ca <fmodulo+0xba>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <fmod@plt>
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    11b6 <fmodulo+0xa6>
jp     11b6 <fmodulo+0xa6>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11c0 <fmodulo+0xb0>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmodulo>:
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jae    1143 <fmodulo+0x33>
sub    $0x18,%rsp
movaps %xmm1,(%rsp)
call   1030 <fmod@plt>
movapd (%rsp),%xmm1
addsd  %xmm1,%xmm0
cmpeqsd %xmm0,%xmm1
andnpd %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
jmp    1149 <fmodulo+0x39>
ucomisd %xmm0,%xmm1
jbe    114a <fmodulo+0x3a>
ret
jmp    1030 <fmod@plt>

LLVM IR (-O0):
define double @fmodulo(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 %21
9: ; preds = %2
%10 = load double, double* %4
%11 = load double, double* %5
%12 = fcmp olt double %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load double, double* %4
br label %19
15: ; preds = %9
%16 = load double, double* %4
%17 = load double, double* %5
%18 = call double @fmod(double %16, double %17)
br label %19
19: ; preds = %15, %13
%20 = phi double [ %14, %13 ], [ %18, %15 ]
store double %20, double* %3
br label %35
21: ; preds = %2
%22 = load double, double* %4
%23 = load double, double* %5
%24 = call double @fmod(double %22, double %23)
%25 = load double, double* %5
%26 = fadd double %24, %25
store double %26, double* %6
%27 = load double, double* %6
%28 = load double, double* %5
%29 = fcmp oeq double %27, %28
br i1 %29, label %30, label %31
30: ; preds = %21
br label %33
31: ; preds = %21
%32 = load double, double* %6
br label %33
33: ; preds = %31, %30
%34 = phi double [ 0.000000e+00, %30 ], [ %32, %31 ]
store double %34, double* %3
br label %35
35: ; preds = %33, %19
%36 = load double, double* %3
ret double %36
}

LLVM IR (-O2):
define double @fmodulo(double %0, double %1) {
%3 = fcmp ult double %0, 0.000000e+00
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = fcmp olt double %0, %1
br i1 %5, label %13, label %6
6: ; preds = %4
%7 = tail call double @fmod(double %0, double %1)
br label %13
8: ; preds = %2
%9 = tail call double @fmod(double %0, double %1)
%10 = fadd double %9, %1
%11 = fcmp oeq double %10, %1
%12 = select i1 %11, double 0.000000e+00, double %10
br label %13
13: ; preds = %6, %4, %8
%14 = phi double [ %12, %8 ], [ %7, %6 ], [ %0, %4 ]
ret double %14
}