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

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int main() {
  FILE *fp;
  while (1) {
    char buf[1024];
    fp = fopen("/proc/ctx_proc", "r");
    if (fp == NULL) {
      perror("fopen");
      return -1;
    }
    while (!feof(fp)) {
      if (fgets(buf, sizeof(buf), fp) != NULL) {
        printf("%s", buf);
        fflush(stdout);
      }
    }
    fflush(stdout);
    sleep(2);
    printf("\033c");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <main+0x4e>
lea    0xe66(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
add    $0x410,%rsp
pop    %rbp
ret
jmp    11c3 <main+0x53>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e1 <main+0x71>
jmp    1228 <main+0xb8>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1223 <main+0xb3>
lea    -0x410(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    11c3 <main+0x53>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1182 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe78(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11bc <main+0x4c>
lea    0xe71(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%rbp
mov    %rsp,%rbx
lea    0xe4e(%rip),%r14
mov    0x2e10(%rip),%r15
lea    0xe29(%rip),%r12
lea    0xe31(%rip),%r13
jmp    1220 <main+0xb0>
mov    (%r15),%edi
call   1060 <fflush@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1199 <main+0x29>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11e0 <main+0x70>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1220 <main+0xb0>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
jmp    1220 <main+0xb0>

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/ctx_proc\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [3 x i8] c"%s\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"\1Bc\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
store i32 0, i32* %1
br label %4
4: ; preds = %0, %27
%5 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 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** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 -1
10: ; preds = %4
br label %11
11: ; preds = %26, %10
%12 = load i32*, i32** %2
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %27
16: ; preds = %11
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i32*, i32** %2
%19 = call i32* @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
br label %26
26: ; preds = %21, %16
br label %11
27: ; preds = %11
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
%30 = call i32 @sleep(i32 2)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %4
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/ctx_proc\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [3 x i8] c"%s\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"\1Bc\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %26, label %5
5: ; preds = %0, %19
%6 = phi i32* [ %24, %19 ], [ %3, %0 ]
%7 = call i32 @feof(i32* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %5, %16
%10 = call i32* @fgets(i8* %2, i32 1024, i32* %6)
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%14 = load i32, i32* @stdout
%15 = call i32 @fflush(i32 %14)
br label %16
16: ; preds = %12, %9
%17 = call i32 @feof(i32* %6)
%18 = icmp eq i32 %17, 0
br i1 %18, label %9, label %19
19: ; preds = %16, %5
%20 = load i32, i32* @stdout
%21 = call i32 @fflush(i32 %20)
%22 = call i32 @sleep(i32 2)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %5
26: ; preds = %19, %0
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 -1
}