#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
void print_file_90(char *file) {
  FILE *f;
  f = fopen(file, "r");
  char buf[1024];
  int i;
  printf("\033[2J");
  printf("\033[;H");
  printf("\033[s");
  while (fgets(buf, 1024, f) != NULL) {
    printf("\033[u");
    printf("\033[1C");
    printf("\033[s");
    for (i = 0; buf[i] != '\0'; ++i) {
      printf("%c", buf[i]);
      printf("\033[1D\033[1B");
    }
  }
  printf("\n");
  fclose(f);
}


x86 assembly (clang, -O0):
<print_file_90>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123c <print_file_90+0xfc>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x414(%rbp)
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1237 <print_file_90+0xf7>
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%esi
ff
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11e0 <print_file_90+0xa0>
jmp    118d <print_file_90+0x4d>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file_90>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1240 <print_file_90+0xf0>
lea    0xe5a(%rip),%r15
lea    0xe4b(%rip),%r12
mov    %rsp,%r13
lea    0xe4e(%rip),%rbp
jmp    11e5 <print_file_90+0x95>
nopl   (%rax)
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1240 <print_file_90+0xf0>
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%al
test   %al,%al
je     11d0 <print_file_90+0x80>
lea    0x1(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r14),%eax
add    $0x1,%r14
test   %al,%al
jne    1220 <print_file_90+0xd0>
jmp    11d0 <print_file_90+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [5 x i8] c"\1B[;H\00"
@.str.3 = [4 x i8] c"\1B[s\00"
@.str.4 = [4 x i8] c"\1B[u\00"
@.str.5 = [5 x i8] c"\1B[1C\00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [9 x i8] c"\1B[1D\1B[1B\00"
@.str.8 = [2 x i8] c"\0A\00"
define void @print_file_90(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %11
11: ; preds = %38, %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = load i32*, i32** %3
%14 = call i32* @fgets(i8* %12, i32 1024, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %39
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %20
20: ; preds = %35, %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %20
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %35
35: ; preds = %27
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %20
38: ; preds = %20
br label %11
39: ; preds = %11
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%41 = load i32*, i32** %3
%42 = call i32 @fclose(i32* %41)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [5 x i8] c"\1B[;H\00"
@.str.3 = [4 x i8] c"\1B[s\00"
@.str.4 = [4 x i8] c"\1B[u\00"
@.str.5 = [5 x i8] c"\1B[1C\00"
@.str.7 = [9 x i8] c"\1B[1D\1B[1B\00"
define void @print_file_90(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32* @fgets(i8* %4, i32 1024, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %29, label %13
10: ; preds = %19, %13
%11 = call i32* @fgets(i8* %4, i32 1024, i32* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %29, label %13
13: ; preds = %1, %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%17 = load i8, i8* %4
%18 = icmp eq i8 %17, 0
br i1 %18, label %10, label %19
19: ; preds = %13, %19
%20 = phi i64 [ %25, %19 ], [ 0, %13 ]
%21 = phi i8 [ %27, %19 ], [ %17, %13 ]
%22 = sext i8 %21 to i32
%23 = call i32 @putchar(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%25 = add nuw i64 %20, 1
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %10, label %19
29: ; preds = %10, %1
%30 = call i32 @putchar(i32 10)
%31 = call i32 @fclose(i32* %3)
ret void
}