#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int process_document(int /*<<< orphan*/ *, char *, char *, int /*<<< orphan*/,
                     int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *outfp;
  int ret = 0;
  if (argc != 3) {
    fprintf(stderr, "usage: %s <infilename> <outfilename>\n", argv[0]);
    return (2);
  }
  if ((outfp = fopen(argv[2], "w")) == NULL) {
    fprintf(stderr, "Error: couldn't open output file '%s'\n", argv[2]);
    return (3);
  }
  ret = process_document(outfp, argv[1], argv[1], 0, 0);
  fclose(outfp);
  return ret;
}


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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118f <main+0x4f>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    120b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11da <main+0x9a>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    120b <main+0xcb>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1050 <process_document@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1186 <main+0x46>
mov    0x10(%rbx),%rdi
lea    0xecf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a5 <main+0x65>
mov    %rax,%r14
mov    0x8(%rbx),%rdx
mov    %rax,%rdi
mov    %rdx,%rsi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <process_document@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
jmp    11c3 <main+0x83>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%eax
jmp    11c3 <main+0x83>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"usage: %s <infilename> <outfilename>\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [39 x i8] c"Error: couldn't open output file '%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 2, i32* %3
br label %40
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i32 3, i32* %3
br label %40
28: ; preds = %16
%29 = load i32*, i32** %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @process_document(i32* %29, i8* %32, i8* %35, i32 0, i32 0)
store i32 %36, i32* %7
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
%39 = load i32, i32* %7
store i32 %39, i32* %3
br label %40
40: ; preds = %28, %22, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"usage: %s <infilename> <outfilename>\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [39 x i8] c"Error: couldn't open output file '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %22
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %22
17: ; preds = %8
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @process_document(i32* %11, i8* %19, i8* %19, i32 0, i32 0)
%21 = tail call i32 @fclose(i32* %11)
br label %22
22: ; preds = %17, %13, %4
%23 = phi i32 [ 2, %4 ], [ 3, %13 ], [ %20, %17 ]
ret i32 %23
}