#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 round_down(double, double);
double round_up(double, double);
void rs_rainflow_round_range_mean(double *cycle, double scale) {
  double a, b;
  a = cycle[1] - cycle[0] / 2.0;
  b = cycle[1] + cycle[0] / 2.0;
  if (a < b) {
    a = round_down(a, scale);
    b = round_up(b, scale);
  } else {
    a = round_up(a, scale);
    b = round_down(b, scale);
  }
  cycle[0] = (b - a);
  cycle[1] = (b + a) / 2.0;
}


x86 assembly (clang, -O0):
<rs_rainflow_round_range_mean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
movsd  0xeb6(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
movsd  0xe90(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11be <rs_rainflow_round_range_mean+0x9e>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <round_down@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <round_up@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    11e6 <rs_rainflow_round_range_mean+0xc6>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <round_up@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <round_down@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xdf6(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rs_rainflow_round_range_mean>:
push   %rbx
sub    $0x20,%rsp
movaps %xmm0,%xmm2
mov    %rdi,%rbx
movsd  (%rdi),%xmm3
movsd  0x8(%rdi),%xmm1
mulsd  0xec4(%rip),%xmm3
movapd %xmm1,%xmm0
subsd  %xmm3,%xmm0
addsd  %xmm1,%xmm3
movsd  %xmm3,0x10(%rsp)
ucomisd %xmm0,%xmm3
movsd  %xmm2,0x8(%rsp)
movaps %xmm2,%xmm1
jbe    117b <rs_rainflow_round_range_mean+0x5b>
call   1040 <round_down@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <round_up@plt>
jmp    1197 <rs_rainflow_round_range_mean+0x77>
call   1030 <round_up@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <round_down@plt>
movapd %xmm0,%xmm1
movsd  0x18(%rsp),%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,(%rbx)
addsd  %xmm0,%xmm2
mulsd  0xe4b(%rip),%xmm2
movsd  %xmm2,0x8(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @rs_rainflow_round_range_mean(double* %0, double %1) {
%3 = alloca double*
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double* %0, double** %3
store double %1, double* %4
%7 = load double*, double** %3
%8 = getelementptr inbounds double, double* %7, i64 1
%9 = load double, double* %8
%10 = load double*, double** %3
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = fdiv double %12, 2.000000e+00
%14 = fsub double %9, %13
store double %14, double* %5
%15 = load double*, double** %3
%16 = getelementptr inbounds double, double* %15, i64 1
%17 = load double, double* %16
%18 = load double*, double** %3
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = load double, double* %19
%21 = fdiv double %20, 2.000000e+00
%22 = fadd double %17, %21
store double %22, double* %6
%23 = load double, double* %5
%24 = load double, double* %6
%25 = fcmp olt double %23, %24
br i1 %25, label %26, label %33
26: ; preds = %2
%27 = load double, double* %5
%28 = load double, double* %4
%29 = call double @round_down(double %27, double %28)
store double %29, double* %5
%30 = load double, double* %6
%31 = load double, double* %4
%32 = call double @round_up(double %30, double %31)
store double %32, double* %6
br label %40
33: ; preds = %2
%34 = load double, double* %5
%35 = load double, double* %4
%36 = call double @round_up(double %34, double %35)
store double %36, double* %5
%37 = load double, double* %6
%38 = load double, double* %4
%39 = call double @round_down(double %37, double %38)
store double %39, double* %6
br label %40
40: ; preds = %33, %26
%41 = load double, double* %6
%42 = load double, double* %5
%43 = fsub double %41, %42
%44 = load double*, double** %3
%45 = getelementptr inbounds double, double* %44, i64 0
store double %43, double* %45
%46 = load double, double* %6
%47 = load double, double* %5
%48 = fadd double %46, %47
%49 = fdiv double %48, 2.000000e+00
%50 = load double*, double** %3
%51 = getelementptr inbounds double, double* %50, i64 1
store double %49, double* %51
ret void
}

LLVM IR (-O2):
define void @rs_rainflow_round_range_mean(double* nocapture %0, double %1) {
%3 = getelementptr inbounds double, double* %0, i64 1
%4 = load double, double* %3
%5 = load double, double* %0
%6 = fmul double %5, 5.000000e-01
%7 = fsub double %4, %6
%8 = fadd double %4, %6
%9 = fcmp olt double %7, %8
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call double @round_down(double %7, double %1)
%12 = tail call double @round_up(double %8, double %1)
br label %16
13: ; preds = %2
%14 = tail call double @round_up(double %7, double %1)
%15 = tail call double @round_down(double %8, double %1)
br label %16
16: ; preds = %13, %10
%17 = phi double [ %11, %10 ], [ %14, %13 ]
%18 = phi double [ %12, %10 ], [ %15, %13 ]
%19 = fsub double %18, %17
store double %19, double* %0
%20 = fadd double %17, %18
%21 = fmul double %20, 5.000000e-01
store double %21, double* %3
ret void
}