#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 */
typedef int /*<<< orphan*/ output_buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ mkfifo(char const *, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, float *, int);
int /*<<< orphan*/ unlink(char const *);
int /*<<< orphan*/ write(int, float *, int);
int main() {
  int fd_i;
  int fd_o;
  const char *input_fifo = "/tmp/input_fifo";
  const char *output_fifo = "/tmp/output_fifo";
  float input_buffer[3];
  float output_buffer[2];
  mkfifo(input_fifo, 0666);
  mkfifo(output_fifo, 0666);
  fd_i = open(input_fifo, O_RDONLY);
  fd_o = open(output_fifo, O_WRONLY);
  while (1) {
    float input[3];
    read(fd_i, input_buffer, (3) * sizeof(float));
    float v_ = input_buffer[0];
    float x_ = input_buffer[1];
    float a = input_buffer[2];
    float v = v_ + 0.15 * a;
    v = (v > 0.5) ? 0.5 : (v < -0.5) ? -0.5 : v;
    float x = x_ + 0.15 * v;
    output_buffer[0] = v;
    output_buffer[1] = x;
    write(fd_o, output_buffer, sizeof(output_buffer));
  }
  close(fd_i);
  close(fd_o);
  unlink(input_fifo);
  unlink(output_fifo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec2(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xec7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0xc,%edx
call   1040 <read@plt>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x44(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x4c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe14(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdea(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1232 <main+0xf2>
movsd  0xdd8(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1277 <main+0x137>
movss  -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdcd(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    125f <main+0x11f>
movsd  0xdbb(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    126d <main+0x12d>
movss  -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x48(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd69(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x50(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x54(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
jmp    11ab <main+0x6b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xebf(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
lea    0xebb(%rip),%rbp
mov    %rbp,%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%r14
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1040 <read@plt>
movss  0xc(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movss  0x14(%rsp),%xmm2
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm2,%xmm2
movsd  0xe1f(%rip),%xmm4
mulsd  %xmm4,%xmm2
addsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
movss  0xe10(%rip),%xmm2
maxss  %xmm0,%xmm2
movss  0xe08(%rip),%xmm5
movaps %xmm5,%xmm3
cmpltss %xmm0,%xmm3
movaps %xmm3,%xmm0
andnps %xmm2,%xmm0
andps  %xmm5,%xmm3
orps   %xmm0,%xmm3
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm3,0x4(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [16 x i8] c"/tmp/input_fifo\00"
@.str.1 = [17 x i8] c"/tmp/output_fifo\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [3 x float]
%7 = alloca [2 x float]
%8 = alloca [3 x float]
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
store i32 0, i32* %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %5
%14 = load i8*, i8** %4
%15 = call i32 @mkfifo(i8* %14, i32 438)
%16 = load i8*, i8** %5
%17 = call i32 @mkfifo(i8* %16, i32 438)
%18 = load i8*, i8** %4
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %2
%21 = load i8*, i8** %5
%22 = load i32, i32* @O_WRONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %3
br label %24
24: ; preds = %0, %54
%25 = load i32, i32* %2
%26 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%27 = call i32 @read(i32 %25, float* %26, i32 12)
%28 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%29 = load float, float* %28
store float %29, float* %9
%30 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 1
%31 = load float, float* %30
store float %31, float* %10
%32 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 2
%33 = load float, float* %32
store float %33, float* %11
%34 = load float, float* %9
%35 = fpext float %34 to double
%36 = load float, float* %11
%37 = fpext float %36 to double
%38 = call double @llvm.fmuladd.f64(double 1.500000e-01, double %37, double %35)
%39 = fptrunc double %38 to float
store float %39, float* %12
%40 = load float, float* %12
%41 = fpext float %40 to double
%42 = fcmp ogt double %41, 5.000000e-01
br i1 %42, label %43, label %44
43: ; preds = %24
br label %54
44: ; preds = %24
%45 = load float, float* %12
%46 = fpext float %45 to double
%47 = fcmp olt double %46, -5.000000e-01
br i1 %47, label %48, label %49
48: ; preds = %44
br label %52
49: ; preds = %44
%50 = load float, float* %12
%51 = fpext float %50 to double
br label %52
52: ; preds = %49, %48
%53 = phi double [ -5.000000e-01, %48 ], [ %51, %49 ]
br label %54
54: ; preds = %52, %43
%55 = phi double [ 5.000000e-01, %43 ], [ %53, %52 ]
%56 = fptrunc double %55 to float
store float %56, float* %12
%57 = load float, float* %10
%58 = fpext float %57 to double
%59 = load float, float* %12
%60 = fpext float %59 to double
%61 = call double @llvm.fmuladd.f64(double 1.500000e-01, double %60, double %58)
%62 = fptrunc double %61 to float
store float %62, float* %13
%63 = load float, float* %12
%64 = getelementptr inbounds [2 x float], [2 x float]* %7, i64 0, i64 0
store float %63, float* %64
%65 = load float, float* %13
%66 = getelementptr inbounds [2 x float], [2 x float]* %7, i64 0, i64 1
store float %65, float* %66
%67 = load i32, i32* %3
%68 = getelementptr inbounds [2 x float], [2 x float]* %7, i64 0, i64 0
%69 = call i32 @write(i32 %67, float* %68, i32 8)
br label %24
}

LLVM IR (-O2):
@.str = [16 x i8] c"/tmp/input_fifo\00"
@.str.1 = [17 x i8] c"/tmp/output_fifo\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca [3 x float]
%2 = alloca [2 x float]
%3 = bitcast [3 x float]* %1 to i8*
%4 = bitcast [2 x float]* %2 to i8*
%5 = tail call i32 @mkfifo(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 438)
%6 = tail call i32 @mkfifo(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 438)
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 0
%12 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 1
%13 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 2
%14 = getelementptr inbounds [2 x float], [2 x float]* %2, i64 0, i64 0
%15 = getelementptr inbounds [2 x float], [2 x float]* %2, i64 0, i64 1
br label %16
16: ; preds = %16, %0
%17 = call i32 @read(i32 %8, float* %11, i32 12)
%18 = load float, float* %11
%19 = load float, float* %12
%20 = load float, float* %13
%21 = fpext float %18 to double
%22 = fpext float %20 to double
%23 = tail call double @llvm.fmuladd.f64(double %22, double 1.500000e-01, double %21)
%24 = fptrunc double %23 to float
%25 = fcmp ogt float %24, 5.000000e-01
%26 = fcmp olt float %24, -5.000000e-01
%27 = select i1 %26, float -5.000000e-01, float %24
%28 = select i1 %25, float 5.000000e-01, float %27
%29 = fpext float %19 to double
%30 = fpext float %28 to double
%31 = tail call double @llvm.fmuladd.f64(double %30, double 1.500000e-01, double %29)
%32 = fptrunc double %31 to float
store float %28, float* %14
store float %32, float* %15
%33 = call i32 @write(i32 %10, float* %14, i32 8)
br label %16
}