#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*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void print_file(char *file) {
  FILE *fp;
  char line[1000];
  int lineno = 0;
  int page = 1;
  if ((fp = fopen(file, "r")) == NULL) {
    printf("%s: error opening file\n", file);
    return;
  }
  printf("----------New file----------\n");
  printf("Title: %s\n\n", file);
  while (fgets(line, 1000, fp) != NULL) {
    if (lineno % 30 == 0) {
      printf("Page %d\n", page);
      page++;
    }
    printf("%s", line);
    lineno++;
  }
  if (ferror(fp)) {
    fprintf(stderr, "%s: error in file\n", file);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x404(%rbp)
movl   $0x1,-0x408(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b8 <print_file+0x58>
mov    -0x8(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    128f <print_file+0x12f>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     125a <print_file+0xfa>
mov    -0x404(%rbp),%eax
mov    $0x1e,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1231 <print_file+0xd1>
mov    -0x408(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x408(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x408(%rbp)
lea    -0x400(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    11d8 <print_file+0x78>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1286 <print_file+0x126>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdcf(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rdi,%rbx
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     128e <print_file+0x11e>
mov    %rax,%r13
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124d <print_file+0xdd>
mov    $0x1,%ebp
lea    0xe4e(%rip),%r12
lea    0x10(%rsp),%rbx
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    121a <print_file+0xaa>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r14d
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
add    $0xffffffff,%r15d
test   %rax,%rax
je     124d <print_file+0xdd>
mov    %r14d,%eax
mov    $0x88888889,%ecx
imul   %rcx,%rax
shr    $0x24,%rax
mov    %eax,%ecx
shl    $0x5,%ecx
sub    %eax,%ecx
sub    %eax,%ecx
add    %r15d,%ecx
jne    11f0 <print_file+0x80>
lea    0xde7(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebp
jmp    11f0 <print_file+0x80>
mov    %r13,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1274 <print_file+0x104>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    0x8(%rsp),%rdx
call   1080 <fprintf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"%s: error opening file\0A\00"
@.str.2 = [30 x i8] c"----------New file----------\0A\00"
@.str.3 = [12 x i8] c"Title: %s\0A\0A\00"
@.str.4 = [9 x i8] c"Page %d\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.6 = [19 x i8] c"%s: error in file\0A\00"
define void @print_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1000 x i8]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
store i32 1, i32* %6
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %47
13: ; preds = %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %31, %13
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i32* @fgets(i8* %18, i32 1000, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = load i32, i32* %5
%24 = srem i32 %23, 30
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %31
31: ; preds = %26, %22
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %17
36: ; preds = %17
%37 = load i32*, i32** %3
%38 = call i64 @ferror(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %2
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %40, %36
%45 = load i32*, i32** %3
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"%s: error opening file\0A\00"
@.str.3 = [12 x i8] c"Title: %s\0A\0A\00"
@.str.4 = [9 x i8] c"Page %d\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.6 = [19 x i8] c"%s: error in file\0A\00"
@str = [29 x i8] c"----------New file----------\00"
define void @print_file(i8* %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %35
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%11 = call i32* @fgets(i8* %3, i32 1000, i32* %4)
%12 = icmp eq i32* %11, null
br i1 %12, label %27, label %13
13: ; preds = %8, %21
%14 = phi i32 [ %22, %21 ], [ 1, %8 ]
%15 = phi i32 [ %24, %21 ], [ 0, %8 ]
%16 = urem i32 %15, 30
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%20 = add nsw i32 %14, 1
br label %21
21: ; preds = %18, %13
%22 = phi i32 [ %20, %18 ], [ %14, %13 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%24 = add nuw nsw i32 %15, 1
%25 = call i32* @fgets(i8* %3, i32 1000, i32* %4)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %13
27: ; preds = %21, %8
%28 = call i64 @ferror(i32* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %33
33: ; preds = %30, %27
%34 = call i32 @fclose(i32* %4)
br label %35
35: ; preds = %33, %6
ret void
}