#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int move(int, char);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char c;
  int pos = 5;
  FILE *fp = fopen("input", "r");
  if (fp == NULL) {
    printf("could not open input file\n");
    return -1;
  }
  while ((c = fgetc(fp)) != EOF) {
    pos = move(pos, c);
    if (c == 10) {
      printf("%i", pos);
    }
  }
  printf("\n");
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0xc(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <main+0x52>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <main+0xc8>
jmp    11a7 <main+0x57>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2e2b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11fa <main+0xaa>
mov    -0xc(%rbp),%edi
movsbl -0x5(%rbp),%esi
call   1070 <move@plt>
mov    %eax,-0xc(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    11f5 <main+0xa5>
mov    -0xc(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a7 <main+0x57>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe81(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11be <main+0x4e>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2e46(%rip),%r12
cmp    (%r12),%al
jne    11d8 <main+0x68>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    11cf <main+0x5f>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x5,%ebp
lea    0xe24(%rip),%r14
jmp    11fe <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <fgetc@plt>
cmp    (%r12),%al
je     11a8 <main+0x38>
movsbl %al,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   1090 <move@plt>
mov    %eax,%ebp
cmp    $0xa,%bl
jne    11f0 <main+0x80>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f0 <main+0x80>

LLVM IR (-O0):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"could not open input file\0A\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%i\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i32 5, i32* %3
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %33
10: ; preds = %0
br label %11
11: ; preds = %28, %10
%12 = load i32*, i32** %4
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %2
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i32, i32* %3
%20 = load i8, i8* %2
%21 = call i32 @move(i32 %19, i8 signext %20)
store i32 %21, i32* %3
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %18
br label %11
29: ; preds = %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %1
br label %33
33: ; preds = %29, %8
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%i\00"
@str = [26 x i8] c"could not open input file\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %20, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %23
9: ; preds = %3, %16
%10 = phi i8 [ %17, %16 ], [ %4, %3 ]
%11 = phi i32 [ %12, %16 ], [ 5, %3 ]
%12 = tail call i32 @move(i32 %11, i8 signext %10)
%13 = icmp eq i8 %10, 10
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %16
16: ; preds = %14, %9
%17 = tail call signext i8 @fgetc(i32* %1)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %20, label %9
20: ; preds = %16, %3
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 @fclose(i32* %1)
br label %23
23: ; preds = %20, %7
%24 = phi i32 [ -1, %7 ], [ 0, %20 ]
ret i32 %24
}