#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ init_testing();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ process_file(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int exit_status = 0;
  init_testing();
  if (argc == 1) {
    process_file(stdin, stdout);
  } else {
    FILE *ifp;
    int i;
    for (i = 1; i < argc; ++i) {
      if (strcmp(argv[i], "-") == 0) {
        ifp = stdin;
        printf("# [stdin]\n");
      } else if ((ifp = fopen(argv[i], "r")) == NULL) {
        fprintf(stderr, "Cannot open '%s': %s\n", argv[i], strerror(errno));
        return 1;
      } else {
        printf("# %s\n", argv[i]);
      }
      if (process_file(ifp, stdout) != 0)
        exit_status = 1;
      fclose(ifp);
    }
  }
  return exit_status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1060 <init_testing@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11cb <main+0x4b>
mov    0x2e33(%rip),%rax
mov    (%rax),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1040 <process_file@plt>
jmp    12f1 <main+0x171>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ec <main+0x16c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe0f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1221 <main+0xa1>
mov    0x2de1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b2 <main+0x132>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd9(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1293 <main+0x113>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xd8d(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f7 <main+0x177>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b2 <main+0x132>
mov    -0x20(%rbp),%rdi
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
call   1040 <process_file@plt>
cmp    $0x0,%rax
je     12d5 <main+0x155>
movl   $0x1,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d2 <main+0x52>
jmp    12f1 <main+0x171>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <init_testing@plt>
cmp    $0x1,%r14d
jne    11cd <main+0x3d>
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
call   1050 <process_file@plt>
jmp    12a4 <main+0x114>
jle    12a4 <main+0x114>
mov    %r14d,%r12d
mov    $0x1,%r13d
mov    $0x1,%r14d
xor    %ebp,%ebp
jmp    122f <main+0x9f>
cs nopw 0x0(%rax,%rax,1)
mov    0x2df1(%rip),%rax
mov    (%rax),%r15
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1050 <process_file@plt>
test   %rax,%rax
cmovne %r14d,%ebp
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x1,%r13
cmp    %r13,%r12
je     12a4 <main+0x114>
mov    (%rbx,%r13,8),%rdi
lea    0xdc6(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11f0 <main+0x60>
mov    (%rbx,%r13,8),%rdi
lea    0xdb3(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1270 <main+0xe0>
mov    %rax,%r15
mov    (%rbx,%r13,8),%rsi
lea    0xdb3(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1206 <main+0x76>
mov    0x2d61(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx,%r13,8),%rbx
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd72(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1090 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32 0
@.str = [2 x i8] c"-\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"Cannot open '%s': %s\0A\00"
@errno = global i32 0
@.str.4 = [6 x i8] c"# %s\0A\00"
@str = [10 x i8] c"# [stdin]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @init_testing()
%4 = icmp eq i32 %0, 1
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %45
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %13
9: ; preds = %2
%10 = load i32*, i32** @stdin
%11 = load i32, i32* @stdout
%12 = tail call i64 @process_file(i32* %10, i32 %11)
br label %45
13: ; preds = %7, %36
%14 = phi i64 [ 1, %7 ], [ %43, %36 ]
%15 = phi i32 [ 0, %7 ], [ %41, %36 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %14
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32*, i32** @stdin
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %36
23: ; preds = %13
%24 = load i8*, i8** %16
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %16
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %31)
br label %45
33: ; preds = %23
%34 = load i8*, i8** %16
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %33, %20
%37 = phi i32* [ %21, %20 ], [ %25, %33 ]
%38 = load i32, i32* @stdout
%39 = tail call i64 @process_file(i32* %37, i32 %38)
%40 = icmp eq i64 %39, 0
%41 = select i1 %40, i32 %15, i32 1
%42 = tail call i32 @fclose(i32* %37)
%43 = add nuw nsw i64 %14, 1
%44 = icmp eq i64 %43, %8
br i1 %44, label %45, label %13
45: ; preds = %36, %5, %9, %27
%46 = phi i32 [ 1, %27 ], [ 0, %9 ], [ 0, %5 ], [ %41, %36 ]
ret i32 %46
}