#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int test_igd_desc_parse(char *, int);
int main(int argc, char **argv) {
  FILE *f;
  char *buffer;
  int len;
  int r = 0;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
    return 1;
  }
  f = fopen(argv[1], "r");
  if (!f) {
    fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
    return 1;
  }
  fseek(f, 0, SEEK_END);
  len = ftell(f);
  fseek(f, 0, SEEK_SET);
  buffer = malloc(len);
  fread(buffer, 1, len, f);
  fclose(f);
  r = test_igd_desc_parse(buffer, len);
  free(buffer);
  return r;
}


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)
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11df <main+0x4f>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe32(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a7 <main+0x117>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe26(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122b <main+0x9b>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdfc(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a7 <main+0x117>
mov    -0x18(%rbp),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10b0 <test_igd_desc_parse@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11b4 <main+0x24>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe51(%rip),%rsi
jmp    124c <main+0xbc>
mov    0x8(%rbx),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xa8>
mov    %rax,%r14
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   10b0 <test_igd_desc_parse@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    1256 <main+0xc6>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdca(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s file.xml\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Cannot open %s for reading.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%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 ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %54
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 ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %54
31: ; preds = %18
%32 = load i32*, i32** %6
%33 = load i32, i32* @SEEK_END
%34 = call i32 @fseek(i32* %32, i32 0, i32 %33)
%35 = load i32*, i32** %6
%36 = call i32 @ftell(i32* %35)
store i32 %36, i32* %8
%37 = load i32*, i32** %6
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %37, i32 0, i32 %38)
%40 = load i32, i32* %8
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = load i32, i32* %8
%44 = load i32*, i32** %6
%45 = call i32 @fread(i8* %42, i32 1, i32 %43, i32* %44)
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i8*, i8** %7
%49 = load i32, i32* %8
%50 = call i32 @test_igd_desc_parse(i8* %48, i32 %49)
store i32 %50, i32* %9
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
%53 = load i32, i32* %9
store i32 %53, i32* %3
br label %54
54: ; preds = %31, %25, %12
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s file.xml\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Cannot open %s for reading.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %28
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%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 ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %28
17: ; preds = %8
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %11, i32 0, i32 %18)
%20 = tail call i32 @ftell(i32* %11)
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %11, i32 0, i32 %21)
%23 = tail call i8* @malloc(i32 %20)
%24 = tail call i32 @fread(i8* %23, i32 1, i32 %20, i32* %11)
%25 = tail call i32 @fclose(i32* %11)
%26 = tail call i32 @test_igd_desc_parse(i8* %23, i32 %20)
%27 = tail call i32 @free(i8* %23)
br label %28
28: ; preds = %17, %13, %4
%29 = phi i32 [ 1, %4 ], [ %26, %17 ], [ 1, %13 ]
ret i32 %29
}