#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, float *, float *, float *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *fp = fopen("open-loop.dat", "r");
  if (fp == NULL) {
    printf("File error");
    exit(-1);
  }
  float prev = 0;
  float output = 0;
  float time = 0, left = 0, right = 0;
  while (!feof(fp)) {
    if (fscanf(fp, "%f %f %f", &time, &left, &right) != 3) {
      printf("fail\n");
      break;
    }
    output = (0.5f) * left + (1.0f - (0.5f)) * prev;
    prev = output;
    printf("%f %f\n", time, output);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <main+0x50>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f6 <main+0x96>
jmp    1284 <main+0x124>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
je     122e <main+0xce>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1284 <main+0x124>
movss  -0x28(%rbp),%xmm0
movss  0xdc5(%rip),%xmm1
mulss  -0x1c(%rbp),%xmm1
movss  0xdb8(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdb4(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
jmp    11d8 <main+0x78>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7f(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     127a <main+0x10a>
mov    %rax,%rbx
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1261 <main+0xf1>
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
lea    0xe48(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x14(%rsp),%r13
lea    0xe3b(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1060 <fscanf@plt>
cmp    $0x3,%eax
jne    1255 <main+0xe5>
movss  0x8(%rsp),%xmm1
movss  0xde9(%rip),%xmm2
mulss  %xmm2,%xmm1
movss  0xc(%rsp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm0,%xmm1
movss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  %xmm1,0x8(%rsp)
cvtss2sd %xmm1,%xmm1
mov    %rbp,%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11f0 <main+0x80>
jmp    1261 <main+0xf1>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd91(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"open-loop.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"File error\00"
@.str.3 = [9 x i8] c"%f %f %f\00"
@.str.4 = [6 x i8] c"fail\0A\00"
@.str.5 = [7 x i8] c"%f %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %8
store float 0.000000e+00, float* %9
store float 0.000000e+00, float* %10
store float 0.000000e+00, float* %11
br label %19
19: ; preds = %30, %18
%20 = load i32*, i32** %6
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %41
24: ; preds = %19
%25 = load i32*, i32** %6
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float* %9, float* %10, float* %11)
%27 = icmp ne i32 %26, 3
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %41
30: ; preds = %24
%31 = load float, float* %10
%32 = load float, float* %7
%33 = fmul float 5.000000e-01, %32
%34 = call float @llvm.fmuladd.f32(float 5.000000e-01, float %31, float %33)
store float %34, float* %8
%35 = load float, float* %8
store float %35, float* %7
%36 = load float, float* %9
%37 = fpext float %36 to double
%38 = load float, float* %8
%39 = fpext float %38 to double
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %37, double %39)
br label %19
41: ; preds = %28, %19
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"open-loop.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"File error\00"
@.str.3 = [9 x i8] c"%f %f %f\00"
@.str.5 = [7 x i8] c"%f %f\0A\00"
@str = [5 x i8] c"fail\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = bitcast float* %3 to i8*
store float 0.000000e+00, float* %3
%13 = bitcast float* %4 to i8*
store float 0.000000e+00, float* %4
%14 = bitcast float* %5 to i8*
store float 0.000000e+00, float* %5
%15 = call i32 @feof(i32* %6)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %11, %23
%18 = phi float [ %26, %23 ], [ 0.000000e+00, %11 ]
%19 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float* %3, float* %4, float* %5)
%20 = icmp eq i32 %19, 3
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %33
23: ; preds = %17
%24 = load float, float* %4
%25 = fmul float %18, 5.000000e-01
%26 = call float @llvm.fmuladd.f32(float %24, float 5.000000e-01, float %25)
%27 = load float, float* %3
%28 = fpext float %27 to double
%29 = fpext float %26 to double
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %28, double %29)
%31 = call i32 @feof(i32* %6)
%32 = icmp eq i32 %31, 0
br i1 %32, label %17, label %33
33: ; preds = %23, %11, %21
%34 = call i32 @fclose(i32* %6)
ret i32 0
}