#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 */
char *FileReadStr(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int i;
  FILE *f = NULL;
  int minusn = 0;
  int num = 0;
  char *s;
  if (argc == 1) {
    fprintf(stderr, "USAGE: cat sourcefile1 sourcefile2 ...\n");
    return 1;
  }
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-n")) {
      minusn = 1;
    }
  }
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-n"))
      continue;
    f = fopen(argv[i], "r");
    if (f == NULL) {
      perror(argv[1]);
      continue;
    }
    while ((s = FileReadStr(f)) != NULL) {
      if (minusn)
        printf("%d   ", ++num);
      printf("%s\n", s);
      free(s);
    }
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11d7 <main+0x57>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1312 <main+0x192>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1225 <main+0xa5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1212 <main+0x92>
movl   $0x1,-0x24(%rbp)
jmp    1217 <main+0x97>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11de <main+0x5e>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    130b <main+0x18b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xddd(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    125e <main+0xde>
jmp    12fd <main+0x17d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdba(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1297 <main+0x117>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
jmp    12fd <main+0x17d>
jmp    129c <main+0x11c>
mov    -0x20(%rbp),%rdi
call   10a0 <FileReadStr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12f4 <main+0x174>
cmpl   $0x0,-0x24(%rbp)
je     12d4 <main+0x154>
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    129c <main+0x11c>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122c <main+0xac>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jne    11c2 <main+0x32>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    12db <main+0x14b>
xor    %eax,%eax
cmp    $0x2,%edi
jl     12db <main+0x14b>
mov    %rsi,%rbp
mov    %edi,0x8(%rsp)
mov    %edi,%r15d
xor    %r14d,%r14d
mov    $0x1,%ebx
lea    0xe42(%rip),%r12
mov    $0x1,%r13d
nopl   0x0(%rax)
mov    0x0(%rbp,%rbx,8),%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
cmove  %r13d,%r14d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11f0 <main+0x60>
mov    %r15,0x10(%rsp)
xor    %eax,%eax
cmpl   $0x2,0x8(%rsp)
jl     12db <main+0x14b>
mov    %rbp,0x8(%rsp)
mov    $0x1,%r12d
lea    0xdfd(%rip),%r13
xor    %ebp,%ebp
mov    0x10(%rsp),%r15
jmp    125a <main+0xca>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x10(%rsp),%r15
add    $0x1,%r12
cmp    %r15,%r12
je     12d9 <main+0x149>
mov    0x8(%rsp),%rax
mov    (%rax,%r12,8),%rbx
mov    %rbx,%rdi
lea    0xdbb(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     124d <main+0xbd>
mov    %rbx,%rdi
lea    0xdab(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c6 <main+0x136>
mov    %rax,%rbx
jmp    12a0 <main+0x110>
nop
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   10b0 <FileReadStr@plt>
mov    %rax,%r15
test   %rax,%rax
je     1240 <main+0xb0>
test   %r14d,%r14d
je     1290 <main+0x100>
add    $0x1,%ebp
mov    %r13,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1290 <main+0x100>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
jmp    124d <main+0xbd>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"USAGE: cat sourcefile1 sourcefile2 ...\0A\00"
@.str.1 = [3 x i8] c"-n\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%d \00"
@.str.4 = [4 x i8] c"%s\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 i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %86
16: ; preds = %2
store i32 1, i32* %6
br label %17
17: ; preds = %31, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %21
store i32 1, i32* %8
br label %30
30: ; preds = %29, %21
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %17
34: ; preds = %17
store i32 1, i32* %6
br label %35
35: ; preds = %82, %34
%36 = load i32, i32* %6
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %85
39: ; preds = %35
%40 = load i8**, i8*** %5
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %39
br label %82
48: ; preds = %39
%49 = load i8**, i8*** %5
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %54, i32** %7
%55 = load i32*, i32** %7
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %62
57: ; preds = %48
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i32 @perror(i8* %60)
br label %82
62: ; preds = %48
br label %63
63: ; preds = %74, %62
%64 = load i32*, i32** %7
%65 = call i8* @FileReadStr(i32* %64)
store i8* %65, i8** %10
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %79
67: ; preds = %63
%68 = load i32, i32* %8
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* %9
%72 = add nsw i32 %71, 1
store i32 %72, i32* %9
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %70, %67
%75 = load i8*, i8** %10
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %75)
%77 = load i8*, i8** %10
%78 = call i32 @free(i8* %77)
br label %63
79: ; preds = %63
%80 = load i32*, i32** %7
%81 = call i32 @fclose(i32* %80)
br label %82
82: ; preds = %79, %57, %47
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %35
85: ; preds = %35
store i32 0, i32* %3
br label %86
86: ; preds = %85, %13
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"USAGE: cat sourcefile1 sourcefile2 ...\0A\00"
@.str.1 = [3 x i8] c"-n\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %61
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %16
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %61
11: ; preds = %16
br i1 %5, label %12, label %61
12: ; preds = %11
%13 = icmp eq i32 %23, 0
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = zext i32 %0 to i64
br label %26
16: ; preds = %6, %16
%17 = phi i64 [ 1, %6 ], [ %24, %16 ]
%18 = phi i32 [ 0, %6 ], [ %23, %16 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %17
%20 = load i8*, i8** %19
%21 = tail call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i32 1, i32 %18
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %11, label %16
26: ; preds = %12, %57
%27 = phi i64 [ 1, %12 ], [ %59, %57 ]
%28 = phi i32 [ 0, %12 ], [ %58, %57 ]
%29 = getelementptr inbounds i8*, i8** %1, i64 %27
%30 = load i8*, i8** %29
%31 = tail call i32 @strcmp(i8* dereferenceable(1) %30, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %57, label %33
33: ; preds = %26
%34 = tail call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = tail call i8* @FileReadStr(i32* %34)
%38 = icmp eq i8* %37, null
br i1 %38, label %54, label %42
39: ; preds = %33
%40 = load i8*, i8** %14
%41 = tail call i32 @perror(i8* %40)
br label %57
42: ; preds = %36, %48
%43 = phi i8* [ %52, %48 ], [ %37, %36 ]
%44 = phi i32 [ %49, %48 ], [ %28, %36 ]
br i1 %13, label %48, label %45
45: ; preds = %42
%46 = add nsw i32 %44, 1
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45, %42
%49 = phi i32 [ %46, %45 ], [ %44, %42 ]
%50 = tail call i32 @puts(i8* %43)
%51 = tail call i32 @free(i8* %43)
%52 = tail call i8* @FileReadStr(i32* %34)
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %42
54: ; preds = %48, %36
%55 = phi i32 [ %28, %36 ], [ %49, %48 ]
%56 = tail call i32 @fclose(i32* %34)
br label %57
57: ; preds = %26, %54, %39
%58 = phi i32 [ %28, %39 ], [ %55, %54 ], [ %28, %26 ]
%59 = add nuw nsw i64 %27, 1
%60 = icmp eq i64 %59, %15
br i1 %60, label %61, label %26
61: ; preds = %57, %4, %11, %8
%62 = phi i32 [ 1, %8 ], [ 0, %11 ], [ 0, %4 ], [ 0, %57 ]
ret i32 %62
}