#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 */
float fmodf(float, float);
float CC3CyclicDifference(float minuend, float subtrahend, float period) {
  float semiPeriod = period * 0.5f;
  float diff = (fmodf((minuend - subtrahend), (period)));
  if (diff > semiPeriod) {
    diff -= period;
  } else if (diff < -semiPeriod) {
    diff += period;
  }
  return diff;
}


x86 assembly (clang, -O0):
<CC3CyclicDifference>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  0xed1(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
call   1030 <fmodf@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
ucomiss -0x10(%rbp),%xmm0
jbe    1179 <CC3CyclicDifference+0x69>
movss  -0xc(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11ad <CC3CyclicDifference+0x9d>
movss  -0x14(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
ucomiss %xmm1,%xmm0
jbe    11a8 <CC3CyclicDifference+0x98>
movss  -0xc(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11ad <CC3CyclicDifference+0x9d>
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CC3CyclicDifference>:
sub    $0x28,%rsp
movss  0xee4(%rip),%xmm3
mulss  %xmm2,%xmm3
movaps %xmm3,0x10(%rsp)
subss  %xmm1,%xmm0
movss  %xmm2,0xc(%rsp)
movaps %xmm2,%xmm1
call   1030 <fmodf@plt>
movaps 0x10(%rsp),%xmm2
ucomiss %xmm2,%xmm0
jbe    114c <CC3CyclicDifference+0x3c>
subss  0xc(%rsp),%xmm0
add    $0x28,%rsp
ret
movss  0xc(%rsp),%xmm1
xorps  0xeb7(%rip),%xmm2
ucomiss %xmm0,%xmm2
jbe    1162 <CC3CyclicDifference+0x52>
addss  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define float @CC3CyclicDifference(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%9 = load float, float* %6
%10 = fmul float %9, 5.000000e-01
store float %10, float* %7
%11 = load float, float* %4
%12 = load float, float* %5
%13 = fsub float %11, %12
%14 = load float, float* %6
%15 = call float @fmodf(float %13, float %14)
store float %15, float* %8
%16 = load float, float* %8
%17 = load float, float* %7
%18 = fcmp ogt float %16, %17
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load float, float* %6
%21 = load float, float* %8
%22 = fsub float %21, %20
store float %22, float* %8
br label %33
23: ; preds = %3
%24 = load float, float* %8
%25 = load float, float* %7
%26 = fneg float %25
%27 = fcmp olt float %24, %26
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load float, float* %6
%30 = load float, float* %8
%31 = fadd float %30, %29
store float %31, float* %8
br label %32
32: ; preds = %28, %23
br label %33
33: ; preds = %32, %19
%34 = load float, float* %8
ret float %34
}

LLVM IR (-O2):
define float @CC3CyclicDifference(float %0, float %1, float %2) {
%4 = fmul float %2, 5.000000e-01
%5 = fsub float %0, %1
%6 = tail call float @fmodf(float %5, float %2)
%7 = fcmp ogt float %6, %4
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = fsub float %6, %2
br label %15
10: ; preds = %3
%11 = fneg float %4
%12 = fcmp olt float %6, %11
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = fadd float %6, %2
br label %15
15: ; preds = %10, %13, %8
%16 = phi float [ %9, %8 ], [ %14, %13 ], [ %6, %10 ]
ret float %16
}