#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printhdr(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc == 1) {
    printf("usage: %s file [file..]\n", argv[0]);
    return 1;
  }
  int lc = 0;
  int pgc = 0;
  char line[1000];
  FILE *fp;
  while (--argc > 0) {
    if ((fp = fopen(*++argv, "r")) == NULL) {
      fprintf(stderr, "fcat: can't open file %s\n.", *argv);
      return -1;
    }
    pgc = 1;
    printhdr(*argv, pgc);
    lc = 0;
    while (fgets(line, 1000, fp) != NULL) {
      if (lc == 5) {
        pgc++;
        printhdr(*argv, pgc);
        lc = 0;
      }
      lc++;
      printf("%s", line);
    }
    while (lc++ < 5)
      printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1194 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cf <main+0x17f>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    12c8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x408(%rbp)
cmp    $0x0,%rax
jne    120c <main+0xbc>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe20(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cf <main+0x17f>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%esi
call   1030 <printhdr@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1297 <main+0x147>
cmpl   $0x5,-0x14(%rbp)
jne    1274 <main+0x124>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%esi
call   1030 <printhdr@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0x400(%rbp),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1229 <main+0xd9>
jmp    129c <main+0x14c>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x5,%eax
jge    12c3 <main+0x173>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129c <main+0x14c>
jmp    11a2 <main+0x52>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rsi,%r12
cmp    $0x1,%edi
jne    1195 <main+0x35>
mov    (%r12),%rsi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    12d6 <main+0x176>
mov    %edi,%r15d
xor    %eax,%eax
cmp    $0x2,%edi
jl     12d6 <main+0x176>
lea    0x10(%rsp),%rbx
jmp    11c1 <main+0x61>
nopw   0x0(%rax,%rax,1)
lea    -0x1(%r15),%eax
cmp    $0x3,%r15d
mov    %eax,%r15d
jl     12b4 <main+0x154>
mov    0x8(%r12),%rdi
add    $0x8,%r12
lea    0xe48(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12b8 <main+0x158>
mov    %rax,%rbp
mov    (%r12),%rdi
mov    $0x1,%esi
call   1040 <printhdr@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1290 <main+0x130>
mov    %r15,0x8(%rsp)
xor    %r14d,%r14d
mov    $0x1,%r15d
jmp    125d <main+0xfd>
nopl   0x0(%rax)
add    $0x1,%r15d
mov    (%r12),%rdi
mov    %r15d,%esi
call   1040 <printhdr@plt>
xor    %r13d,%r13d
lea    0x1(%r13),%r14d
lea    0xdf8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1270 <main+0x110>
cmp    $0x5,%r14d
je     1220 <main+0xc0>
mov    %r14d,%r13d
jmp    1233 <main+0xd3>
nopl   0x0(%rax,%rax,1)
cmp    $0x3,%r13d
mov    0x8(%rsp),%r15
jg     11b0 <main+0x50>
jmp    1293 <main+0x133>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %r14d,%r14d
add    $0xfffffffb,%r14d
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
inc    %r14d
jne    12a0 <main+0x140>
jmp    11b0 <main+0x50>
xor    %eax,%eax
jmp    12d6 <main+0x176>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xd4f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"usage: %s file [file..]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"fcat: can't open file %s\0A.\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1000 x i8]
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %67
17: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %7
br label %18
18: ; preds = %65, %17
%19 = load i32, i32* %4
%20 = add nsw i32 %19, -1
store i32 %20, i32* %4
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %66
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %5
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %9
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %31)
store i32 -1, i32* %3
br label %67
33: ; preds = %22
store i32 1, i32* %7
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = load i32, i32* %7
%37 = call i32 @printhdr(i8* %35, i32 %36)
store i32 0, i32* %6
br label %38
38: ; preds = %53, %33
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%40 = load i32*, i32** %9
%41 = call i32* @fgets(i8* %39, i32 1000, i32* %40)
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %58
43: ; preds = %38
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 5
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
%49 = load i8**, i8*** %5
%50 = load i8*, i8** %49
%51 = load i32, i32* %7
%52 = call i32 @printhdr(i8* %50, i32 %51)
store i32 0, i32* %6
br label %53
53: ; preds = %46, %43
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %56)
br label %38
58: ; preds = %38
br label %59
59: ; preds = %63, %58
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
%62 = icmp slt i32 %60, 5
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %59
65: ; preds = %59
br label %18
66: ; preds = %18
store i32 0, i32* %3
br label %67
67: ; preds = %66, %28, %12
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [25 x i8] c"usage: %s file [file..]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"fcat: can't open file %s\0A.\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %56
8: ; preds = %2
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%10 = icmp sgt i32 %0, 1
br i1 %10, label %13, label %54
11: ; preds = %49, %30
%12 = icmp sgt i32 %14, 2
br i1 %12, label %13, label %54
13: ; preds = %8, %11
%14 = phi i32 [ %16, %11 ], [ %0, %8 ]
%15 = phi i8** [ %17, %11 ], [ %1, %8 ]
%16 = add nsw i32 %14, -1
%17 = getelementptr inbounds i8*, i8** %15, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %17
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %54
25: ; preds = %13
%26 = load i8*, i8** %17
%27 = call i32 @printhdr(i8* %26, i32 1)
%28 = call i32* @fgets(i8* %9, i32 1000, i32* %19)
%29 = icmp eq i32* %28, null
br i1 %29, label %32, label %34
30: ; preds = %42
%31 = icmp slt i32 %43, 4
br i1 %31, label %32, label %11
32: ; preds = %25, %30
%33 = phi i32 [ 0, %25 ], [ %45, %30 ]
br label %49
34: ; preds = %25, %42
%35 = phi i32 [ %44, %42 ], [ 1, %25 ]
%36 = phi i32 [ %45, %42 ], [ 0, %25 ]
%37 = icmp eq i32 %36, 5
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = add nsw i32 %35, 1
%40 = load i8*, i8** %17
%41 = call i32 @printhdr(i8* %40, i32 %39)
br label %42
42: ; preds = %38, %34
%43 = phi i32 [ 0, %38 ], [ %36, %34 ]
%44 = phi i32 [ %39, %38 ], [ %35, %34 ]
%45 = add nsw i32 %43, 1
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%47 = call i32* @fgets(i8* %9, i32 1000, i32* %19)
%48 = icmp eq i32* %47, null
br i1 %48, label %30, label %34
49: ; preds = %32, %49
%50 = phi i32 [ %51, %49 ], [ %33, %32 ]
%51 = add i32 %50, 1
%52 = call i32 @putchar(i32 10)
%53 = icmp eq i32 %51, 5
br i1 %53, label %11, label %49
54: ; preds = %11, %8, %21
%55 = phi i32 [ -1, %21 ], [ 0, %8 ], [ 0, %11 ]
br label %56
56: ; preds = %54, %5
%57 = phi i32 [ 1, %5 ], [ %55, %54 ]
ret i32 %57
}