#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*/ buffer;
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 fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int test_parsing(char *, int, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *f;
  char buffer[4096];
  int l;
  int ok;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s file.xml [file.namevalues]\n", argv[0]);
    return 1;
  }
  f = fopen(argv[1], "r");
  if (!f) {
    fprintf(stderr, "Error : can not open file %s\n", argv[1]);
    return 2;
  }
  l = fread(buffer, 1, sizeof(buffer) - 1, f);
  fclose(f);
  f = NULL;
  buffer[l] = '\0';
  if (argc > 2) {
    f = fopen(argv[2], "r");
    if (!f) {
      fprintf(stderr, "Error : can not open file %s\n", argv[2]);
      return 2;
    }
  }
  ok = test_parsing(buffer, l, f);
  if (f) {
    fclose(f);
  }
  return ok ? 0 : 3;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119b <main+0x4b>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <main+0x97>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe52(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12c8 <main+0x178>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xfff,%edx
call   1030 <fread@plt>
mov    %eax,-0x1024(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x18(%rbp)
movslq -0x1024(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
cmpl   $0x2,-0x8(%rbp)
jle    1282 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    127d <main+0x12d>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdbc(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12c8 <main+0x178>
jmp    1282 <main+0x132>
lea    -0x1020(%rbp),%rdi
mov    -0x1024(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1070 <test_parsing@plt>
mov    %eax,-0x1028(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b2 <main+0x162>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1028(%rbp),%edx
mov    $0x3,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
jg     1187 <main+0x37>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe88(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    1247 <main+0xf7>
mov    %edi,%ebp
mov    0x8(%r15),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ff <main+0xaf>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xfff,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
movslq %r14d,%rax
movb   $0x0,(%rsp,%rax,1)
cmp    $0x2,%ebp
jbe    120e <main+0xbe>
mov    0x10(%r15),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1229 <main+0xd9>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1070 <test_parsing@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    121d <main+0xcd>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
jmp    1236 <main+0xe6>
mov    %rsp,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1070 <test_parsing@plt>
mov    %eax,%ebp
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
lea    (%rax,%rax,2),%eax
jmp    1247 <main+0xf7>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rdx
lea    0xdeb(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Usage: %s file.xml [file.namevalues]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Error : can not open file %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %43
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %43
19: ; preds = %10
%20 = call i32 @fread(i8* %4, i32 1, i32 4095, i32* %13)
%21 = tail call i32 @fclose(i32* %13)
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
%24 = icmp ugt i32 %0, 2
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = call i32 @test_parsing(i8* %4, i32 %20, i32* null)
br label %39
27: ; preds = %19
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %28
%35 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %43
36: ; preds = %27
%37 = call i32 @test_parsing(i8* %4, i32 %20, i32* %30)
%38 = call i32 @fclose(i32* %30)
br label %39
39: ; preds = %25, %36
%40 = phi i32 [ %26, %25 ], [ %37, %36 ]
%41 = icmp eq i32 %40, 0
%42 = select i1 %41, i32 3, i32 0
br label %43
43: ; preds = %39, %32, %15, %6
%44 = phi i32 [ 1, %6 ], [ %42, %39 ], [ 2, %32 ], [ 2, %15 ]
ret i32 %44
}