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


x86 assembly (clang, -O0):
<rs_rainflow_round_amplitude_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
subsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    119e <rs_rainflow_round_amplitude_mean+0x7e>
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    11c6 <rs_rainflow_round_amplitude_mean+0xa6>
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
movsd  0xe28(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe0a(%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_amplitude_mean>:
push   %rbx
sub    $0x20,%rsp
movaps %xmm0,%xmm2
mov    %rdi,%rbx
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm3
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
addsd  %xmm1,%xmm3
movsd  %xmm3,0x10(%rsp)
ucomisd %xmm0,%xmm3
movsd  %xmm2,0x8(%rsp)
movaps %xmm2,%xmm1
jbe    1173 <rs_rainflow_round_amplitude_mean+0x53>
call   1040 <round_down@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <round_up@plt>
jmp    118f <rs_rainflow_round_amplitude_mean+0x6f>
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),%xmm3
subsd  %xmm3,%xmm1
movsd  0xe5b(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  %xmm1,(%rbx)
addsd  %xmm0,%xmm3
mulsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

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

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