#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 *, ...);
main(int argc, char *argv[]) {
  char line[80], *pattern;
  long lineno, pageno;
  FILE *fp;
  if (argc == 1) {
    printf("error: no files are named as arguments\n");
    return -1;
  } else {
    while (--argc > 0) {
      if ((fp = fopen(*++argv, "r")) == NULL) {
        printf("find: can't open %s\n", *argv);
        continue;
      }
      lineno = 0;
      pageno = 1;
      printf("%s:\nPage %ld:\n", *argv, pageno);
      while (fgets(line, 80, fp) != NULL) {
        lineno++;
        printf("%s", line);
        if (lineno == 20) {
          lineno = 0;
          pageno++;
          printf("\nPage %ld:\n", pageno);
        }
      }
      printf("\n");
      pageno++;
    }
    fclose(fp);
  }
  return pageno;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    117d <main+0x3d>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a3 <main+0x163>
jmp    1182 <main+0x42>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1293 <main+0x153>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
jne    11db <main+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1182 <main+0x42>
movq   $0x0,-0x70(%rbp)
movq   $0x1,-0x78(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x78(%rbp),%rdx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1274 <main+0x134>
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x14,-0x70(%rbp)
jne    126f <main+0x12f>
movq   $0x0,-0x70(%rbp)
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1204 <main+0xc4>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    1182 <main+0x42>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x78(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
cmp    $0x1,%edi
jne    118a <main+0x2a>
lea    0xeaf(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
jmp    12ab <main+0x14b>
mov    %rsi,%rbx
mov    %edi,%r12d
lea    0xe69(%rip),%rbp
add    $0x8,%rbx
mov    %r12d,%r15d
lea    0xe5d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%rdi
mov    %rbp,%rsi
call   1080 <fopen@plt>
mov    %rax,%r13
mov    (%rbx),%rsi
test   %rax,%rax
jne    11f0 <main+0x90>
add    $0xffffffff,%r15d
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x1(%r15),%eax
add    $0x8,%rbx
cmp    $0x2,%eax
ja     11b0 <main+0x50>
jmp    12a3 <main+0x143>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%r14d
mov    $0x1,%edx
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x50,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1280 <main+0x120>
mov    $0x1,%r14d
xor    %ebp,%ebp
jmp    1245 <main+0xe5>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x50,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1280 <main+0x120>
add    $0x1,%rbp
lea    0xdd6(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x14,%rbp
jne    1230 <main+0xd0>
add    $0x1,%r14
lea    0xdaf(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %ebp,%ebp
jmp    1230 <main+0xd0>
nopl   0x0(%rax)
lea    -0x1(%r15),%r12d
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
cmp    $0x3,%r15d
lea    0xd63(%rip),%rbp
jge    1197 <main+0x37>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"find: can't open %s\0A\00"
@.str.3 = [15 x i8] c"%s:\0APage %ld:\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [12 x i8] c"\0APage %ld:\0A\00"
@str = [39 x i8] c"error: no files are named as arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br label %45
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %53
10: ; preds = %45, %19
%11 = phi i32 [ %46, %45 ], [ %13, %19 ]
%12 = phi i8** [ %48, %45 ], [ %14, %19 ]
%13 = add nsw i32 %11, -1
%14 = getelementptr inbounds i8*, i8** %12, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
%18 = load i8*, i8** %14
br i1 %17, label %19, label %22
19: ; preds = %10
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%21 = icmp ugt i32 %11, 2
br i1 %21, label %10, label %49
22: ; preds = %10
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %18, i64 1)
%24 = call i32* @fgets(i8* %4, i32 80, i32* %16)
%25 = icmp eq i32* %24, null
br i1 %25, label %40, label %26
26: ; preds = %22, %35
%27 = phi i64 [ %37, %35 ], [ 1, %22 ]
%28 = phi i64 [ %36, %35 ], [ 0, %22 ]
%29 = add nsw i64 %28, 1
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%31 = icmp eq i64 %29, 20
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = add nsw i64 %27, 1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i64 %33)
br label %35
35: ; preds = %32, %26
%36 = phi i64 [ 0, %32 ], [ %29, %26 ]
%37 = phi i64 [ %33, %32 ], [ %27, %26 ]
%38 = call i32* @fgets(i8* %4, i32 80, i32* %16)
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %26
40: ; preds = %35, %22
%41 = phi i64 [ 1, %22 ], [ %37, %35 ]
%42 = call i32 @putchar(i32 10)
%43 = add nsw i64 %41, 1
%44 = icmp sgt i32 %11, 2
br i1 %44, label %45, label %49
45: ; preds = %6, %40
%46 = phi i32 [ %13, %40 ], [ %0, %6 ]
%47 = phi i64 [ %43, %40 ], [ undef, %6 ]
%48 = phi i8** [ %14, %40 ], [ %1, %6 ]
br label %10
49: ; preds = %40, %19
%50 = phi i64 [ %47, %19 ], [ %43, %40 ]
%51 = call i32 @fclose(i32* %16)
%52 = trunc i64 %50 to i32
br label %53
53: ; preds = %49, %8
%54 = phi i32 [ -1, %8 ], [ %52, %49 ]
ret i32 %54
}