#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*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  assert(argc == 2);
  FILE *f = fopen(argv[1], "r");
  while (!feof(f)) {
    char c = fgetc(f);
    if (c == '\a') {
      getchar();
      printf("\033[A");
      fflush(stdout);
    } else
      putchar(c);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ed <main+0x5d>
jmp    123a <main+0xaa>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x7,%eax
jne    122c <main+0x9c>
mov    $0x0,%al
call   1070 <getchar@plt>
lea    0xdee(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    1235 <main+0xa5>
movsbl -0x19(%rbp),%edi
call   1030 <putchar@plt>
jmp    11cf <main+0x3f>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1080 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe4e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11d6 <main+0x46>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe25(%rip),%r14
mov    0x2dfc(%rip),%r15
jmp    1204 <main+0x74>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    11c6 <main+0x36>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0x7,%al
jne    11f0 <main+0x60>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    (%r15),%edi
call   10a0 <fflush@plt>
jmp    11f8 <main+0x68>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"\1B[A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
br label %16
16: ; preds = %35, %2
%17 = load i32*, i32** %6
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = load i32*, i32** %6
%23 = call signext i8 @fgetc(i32* %22)
store i8 %23, i8* %7
%24 = load i8, i8* %7
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 7
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = call i32 (...) @getchar()
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @stdout
%31 = call i32 @fflush(i32 %30)
br label %35
32: ; preds = %21
%33 = load i8, i8* %7
%34 = call i32 @putchar(i8 signext %33)
br label %35
35: ; preds = %32, %27
br label %16
36: ; preds = %16
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"\1B[A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @feof(i32* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %2, %21
%12 = tail call signext i8 @fgetc(i32* %8)
%13 = icmp eq i8 %12, 7
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = tail call i32 (...) @getchar()
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = tail call i32 @fflush(i32 %17)
br label %21
19: ; preds = %11
%20 = tail call i32 @putchar(i8 signext %12)
br label %21
21: ; preds = %19, %14
%22 = tail call i32 @feof(i32* %8)
%23 = icmp eq i32 %22, 0
br i1 %23, label %11, label %24
24: ; preds = %21, %2
%25 = tail call i32 @fclose(i32* %8)
ret i32 0
}