#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 EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ indexfile(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  if (argc == 1) {
    indexfile(stdin, stdout);
  } else
    while (*++argv) {
      if (strcmp(*argv, "-") == 0) {
        indexfile(stdin, stdout);
        continue;
      }
      in = fopen(*argv, "r");
      if (in == NULL) {
        perror(*argv++);
        continue;
      }
      out = fopen(*++argv, "w");
      if (out == NULL) {
        perror(*argv);
        fclose(in);
        continue;
      }
      indexfile(in, out);
      fclose(in);
      fclose(out);
    }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    118e <main+0x3e>
mov    0x2e71(%rip),%rax
mov    (%rax),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%rsi
call   1070 <indexfile@plt>
jmp    1297 <main+0x147>
jmp    1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
cmpq   $0x0,0x8(%rax)
je     1292 <main+0x142>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe45(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11e8 <main+0x98>
mov    0x2e17(%rip),%rax
mov    (%rax),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%rsi
call   1070 <indexfile@plt>
jmp    1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe0c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1226 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rdi
call   1060 <perror@plt>
jmp    1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xdc4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126e <main+0x11e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1193 <main+0x43>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <indexfile@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1193 <main+0x43>
jmp    1297 <main+0x147>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    117e <main+0x2e>
mov    0x2e81(%rip),%rax
mov    (%rax),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%rsi
call   1070 <indexfile@plt>
jmp    124c <main+0xfc>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     124c <main+0xfc>
lea    0x8(%rbx),%rbp
lea    0xe67(%rip),%r12
lea    0xe62(%rip),%r14
lea    0xe5d(%rip),%r15
jmp    11d9 <main+0x89>
nopl   0x0(%rax)
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%rsi
call   1070 <indexfile@plt>
mov    %rbp,%rbx
add    $0x8,%rbp
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     124c <main+0xfc>
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b0 <main+0x60>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
add    $0x10,%rbx
test   %rax,%rax
je     1231 <main+0xe1>
mov    %rax,%r13
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     123f <main+0xef>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %rax,%rsi
call   1070 <indexfile@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rbp
jmp    11c9 <main+0x79>
mov    0x0(%rbp),%rdi
call   1060 <perror@plt>
mov    %rbx,%rbp
jmp    11c9 <main+0x79>
mov    (%rbx),%rdi
call   1060 <perror@plt>
mov    %r13,%rdi
jmp    1227 <main+0xd7>
mov    0x2d7d(%rip),%rax
mov    (%rax),%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* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32*, i32** @stdin
%12 = load i32*, i32** @stdout
%13 = call i32 @indexfile(i32* %11, i32* %12)
br label %62
14: ; preds = %2
br label %15
15: ; preds = %53, %47, %35, %25, %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %61
20: ; preds = %15
%21 = load i8**, i8*** %5
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32*, i32** @stdin
%27 = load i32*, i32** @stdout
%28 = call i32 @indexfile(i32* %26, i32* %27)
br label %15
29: ; preds = %20
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i32 1
store i8** %37, i8*** %5
%38 = load i8*, i8** %36
%39 = call i32 @perror(i8* %38)
br label %15
40: ; preds = %29
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i32 1
store i8** %42, i8*** %5
%43 = load i8*, i8** %42
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %44, i32** %7
%45 = load i32*, i32** %7
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %53
47: ; preds = %40
%48 = load i8**, i8*** %5
%49 = load i8*, i8** %48
%50 = call i32 @perror(i8* %49)
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
br label %15
53: ; preds = %40
%54 = load i32*, i32** %6
%55 = load i32*, i32** %7
%56 = call i32 @indexfile(i32* %54, i32* %55)
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
br label %15
61: ; preds = %15
br label %62
62: ; preds = %61, %10
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EXIT_SUCCESS = global i32 0
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 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %47, label %12
8: ; preds = %2
%9 = load i32*, i32** @stdin
%10 = load i32*, i32** @stdout
%11 = tail call i32 @indexfile(i32* %9, i32* %10)
br label %47
12: ; preds = %4, %22
%13 = phi i8* [ %25, %22 ], [ %6, %4 ]
%14 = phi i8** [ %24, %22 ], [ %5, %4 ]
%15 = phi i8** [ %23, %22 ], [ %1, %4 ]
%16 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %12
%19 = load i32*, i32** @stdin
%20 = load i32*, i32** @stdout
%21 = tail call i32 @indexfile(i32* %19, i32* %20)
br label %22
22: ; preds = %18, %32, %39, %43
%23 = phi i8** [ %14, %18 ], [ %31, %32 ], [ %31, %39 ], [ %31, %43 ]
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %47, label %12
27: ; preds = %12
%28 = load i8*, i8** %14
%29 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
%31 = getelementptr inbounds i8*, i8** %15, i64 2
br i1 %30, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %14
%34 = tail call i32 @perror(i8* %33)
br label %22
35: ; preds = %27
%36 = load i8*, i8** %31
%37 = tail call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i8*, i8** %31
%41 = tail call i32 @perror(i8* %40)
%42 = tail call i32 @fclose(i32* %29)
br label %22
43: ; preds = %35
%44 = tail call i32 @indexfile(i32* %29, i32* %37)
%45 = tail call i32 @fclose(i32* %29)
%46 = tail call i32 @fclose(i32* %37)
br label %22
47: ; preds = %22, %4, %8
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}