#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 fabs(double);
void validate_x(double x[1], double x0[1]) {
  double small = 1.e-10;
  x[0] = (x[0] >= 1.0) ? (0.5 * (x0[0] + 1.)) : x[0];
  x[0] = (x[0] < -small) ? (0.5 * x0[0]) : x[0];
  x[0] = fabs(x[0]);
  return;
}


x86 assembly (clang, -O0):
<validate_x>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xef4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xed7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1159 <validate_x+0x59>
mov    -0x10(%rbp),%rax
movsd  0xec1(%rip),%xmm1
addsd  (%rax),%xmm1
movsd  0xec5(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1166 <validate_x+0x66>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    11bb <validate_x+0xbb>
mov    -0x10(%rbp),%rax
movsd  0xe63(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11c8 <validate_x+0xc8>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xe3c(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_x>:
movsd  (%rdi),%xmm0
ucomisd 0xef4(%rip),%xmm0
jb     1122 <validate_x+0x22>
movsd  (%rsi),%xmm0
addsd  0xee6(%rip),%xmm0
mulsd  0xee6(%rip),%xmm0
movsd  %xmm0,(%rdi)
movsd  0xee2(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1140 <validate_x+0x40>
movsd  (%rsi),%xmm0
mulsd  0xec8(%rip),%xmm0
andpd  0xed8(%rip),%xmm0
movlpd %xmm0,(%rdi)
ret

LLVM IR (-O0):
define void @validate_x(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
store double* %0, double** %3
store double* %1, double** %4
store double 1.000000e-10, double* %5
%6 = load double*, double** %3
%7 = getelementptr inbounds double, double* %6, i64 0
%8 = load double, double* %7
%9 = fcmp oge double %8, 1.000000e+00
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load double*, double** %4
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = fadd double %13, 1.000000e+00
%15 = fmul double 5.000000e-01, %14
br label %20
16: ; preds = %2
%17 = load double*, double** %3
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load double, double* %18
br label %20
20: ; preds = %16, %10
%21 = phi double [ %15, %10 ], [ %19, %16 ]
%22 = load double*, double** %3
%23 = getelementptr inbounds double, double* %22, i64 0
store double %21, double* %23
%24 = load double*, double** %3
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double, double* %25
%27 = load double, double* %5
%28 = fneg double %27
%29 = fcmp olt double %26, %28
br i1 %29, label %30, label %35
30: ; preds = %20
%31 = load double*, double** %4
%32 = getelementptr inbounds double, double* %31, i64 0
%33 = load double, double* %32
%34 = fmul double 5.000000e-01, %33
br label %39
35: ; preds = %20
%36 = load double*, double** %3
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
br label %39
39: ; preds = %35, %30
%40 = phi double [ %34, %30 ], [ %38, %35 ]
%41 = load double*, double** %3
%42 = getelementptr inbounds double, double* %41, i64 0
store double %40, double* %42
%43 = load double*, double** %3
%44 = getelementptr inbounds double, double* %43, i64 0
%45 = load double, double* %44
%46 = call double @llvm.fabs.f64(double %45)
%47 = load double*, double** %3
%48 = getelementptr inbounds double, double* %47, i64 0
store double %46, double* %48
ret void
}

LLVM IR (-O2):
define void @validate_x(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = fcmp ult double %3, 1.000000e+00
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load double, double* %1
%7 = fadd double %6, 1.000000e+00
%8 = fmul double %7, 5.000000e-01
br label %9
9: ; preds = %2, %5
%10 = phi double [ %8, %5 ], [ %3, %2 ]
store double %10, double* %0
%11 = fcmp olt double %10, -1.000000e-10
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load double, double* %1
%14 = fmul double %13, 5.000000e-01
br label %15
15: ; preds = %9, %12
%16 = phi double [ %14, %12 ], [ %10, %9 ]
%17 = tail call double @llvm.fabs.f64(double %16)
store double %17, double* %0
ret void
}