#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  FILE *fd;
  char buffer[256];
  char y_offset[] = "\n\n\n";
  char x_offset[] = "   ";
  int fp = 0, pos = 0;
  if ((fd = popen("gunzip -c sw1.txt.gz", "r")) == NULL) {
    fprintf(stderr, "pipe-error executing gunzip -c sw1.txt.gz\n");
    return 1;
  }
  while (fgets(buffer, 255, fd) != NULL) {
    if (pos == 0) {
      usleep((1000000 / 15) * fp);
      sscanf(buffer, "%d", &fp);
      printf("\033[;H\033[2J");
      printf("%s", y_offset);
    } else {
      printf("%s", x_offset);
      printf("%s", buffer);
    }
    pos++;
    if (pos > 13)
      pos = 0;
  }
  pclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe71(%rip),%eax
mov    %eax,-0x124(%rbp)
mov    0xe69(%rip),%eax
mov    %eax,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
movl   $0x0,-0x130(%rbp)
lea    0xe4c(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f7 <main+0x87>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12de <main+0x16e>
jmp    11fc <main+0x8c>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12ce <main+0x15e>
cmpl   $0x0,-0x130(%rbp)
jne    1279 <main+0x109>
imul   $0x1046a,-0x12c(%rbp),%edi
call   1090 <usleep@plt>
lea    -0x120(%rbp),%rdi
lea    0xe05(%rip),%rsi
lea    -0x12c(%rbp),%rdx
call   1070 <sscanf@plt>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x124(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a3 <main+0x133>
lea    -0x128(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
cmpl   $0xd,-0x130(%rbp)
jle    12c9 <main+0x159>
movl   $0x0,-0x130(%rbp)
jmp    11fc <main+0x8c>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movl   $0xa0a0a,0xc(%rsp)
movl   $0x202020,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xe60(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <popen@plt>
test   %rax,%rax
je     127a <main+0x10a>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     126e <main+0xfe>
xor    %r13d,%r13d
lea    0x10(%rsp),%rbx
lea    0xe6c(%rip),%rbp
xor    %r14d,%r14d
jmp    1230 <main+0xc0>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1(%r14),%r12d
cmp    $0xd,%r14d
cmovge %r13d,%r12d
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
mov    %r12d,%r14d
test   %rax,%rax
je     126e <main+0xfe>
test   %r14d,%r14d
jne    11f0 <main+0x80>
imul   $0x1046a,0x4(%rsp),%edi
call   1090 <usleep@plt>
mov    %rbx,%rdi
lea    0xdf6(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
lea    0xde8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbp,%rdi
lea    0xc(%rsp),%rsi
jmp    1205 <main+0x95>
mov    %r15,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
jmp    1294 <main+0x124>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.y_offset = [4 x i8] c"\0A\0A\0A\00"
@__const.main.x_offset = [4 x i8] c" \00"
@.str = [21 x i8] c"gunzip -c sw1.txt.gz\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"pipe-error executing gunzip -c sw1.txt.gz\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [9 x i8] c"\1B[;H\1B[2J\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca [4 x i8]
%9 = alloca [4 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [4 x i8]* %8 to i8*
%13 = bitcast [4 x i8]* %9 to i8*
store i32 0, i32* %10
store i32 0, i32* %11
%14 = call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %52
19: ; preds = %2
br label %20
20: ; preds = %48, %19
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32* @fgets(i8* %21, i32 255, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %49
25: ; preds = %20
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %10
%30 = mul nsw i32 66666, %29
%31 = call i32 @usleep(i32 %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %10)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %35)
br label %42
37: ; preds = %25
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %37, %28
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
%45 = load i32, i32* %11
%46 = icmp sgt i32 %45, 13
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 0, i32* %11
br label %48
48: ; preds = %47, %42
br label %20
49: ; preds = %20
%50 = load i32*, i32** %6
%51 = call i32 @pclose(i32* %50)
store i32 0, i32* %3
br label %52
52: ; preds = %49, %16
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [21 x i8] c"gunzip -c sw1.txt.gz\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"pipe-error executing gunzip -c sw1.txt.gz\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [9 x i8] c"\1B[;H\1B[2J\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
store i32 657930, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 2105376, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = tail call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = call i32* @fgets(i8* %7, i32 255, i32* %11)
%15 = icmp eq i32* %14, null
br i1 %15, label %38, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %40
19: ; preds = %13, %32
%20 = phi i32 [ %35, %32 ], [ 0, %13 ]
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %6
%24 = mul nsw i32 %23, 66666
%25 = call i32 @usleep(i32 %24)
%26 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %4)
br label %32
29: ; preds = %19
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %7)
br label %32
32: ; preds = %29, %22
%33 = add nsw i32 %20, 1
%34 = icmp sgt i32 %20, 12
%35 = select i1 %34, i32 0, i32 %33
%36 = call i32* @fgets(i8* %7, i32 255, i32* %11)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %19
38: ; preds = %32, %13
%39 = call i32 @pclose(i32* %11)
br label %40
40: ; preds = %38, %16
%41 = phi i32 [ 1, %16 ], [ 0, %38 ]
ret i32 %41
}