#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*/ XML_StartElementHandler;
typedef int /*<<< orphan*/ XML_Parser;
typedef int /*<<< orphan*/ XML_EndElementHandler;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ XML_ErrorString(int /*<<< orphan*/);
char *XML_GetBuffer(int /*<<< orphan*/, int);
int /*<<< orphan*/ XML_GetCurrentLineNumber(int /*<<< orphan*/);
int /*<<< orphan*/ XML_GetErrorCode(int /*<<< orphan*/);
int XML_ParseBuffer(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ XML_ParserCreate(int /*<<< orphan*/ *);
int XML_STATUS_ERROR;
int /*<<< orphan*/ XML_SetElementHandler(int /*<<< orphan*/, int /*<<< orphan*/,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ XML_SetUserData(int /*<<< orphan*/, void *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
void parse_xml_file(const char *filename, XML_StartElementHandler start,
                    XML_EndElementHandler end, void *data) {
  XML_Parser parser;
  char *buffer;
  int fd, len, err;
  parser = XML_ParserCreate(NULL);
  XML_SetElementHandler(parser, start, end);
  XML_SetUserData(parser, data);
  fd = open(filename, O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "failed to open %s: %m\n", filename);
    exit(-1);
  }
  while (1) {
    buffer = XML_GetBuffer(parser, 4096);
    len = read(fd, buffer, 4096);
    if (len == 0)
      break;
    err = XML_ParseBuffer(parser, len, len == 0);
    if (err == XML_STATUS_ERROR) {
      fprintf(stderr, "parse error at line %lu:\n%s\n",
              XML_GetCurrentLineNumber(parser),
              XML_ErrorString(XML_GetErrorCode(parser)));
      exit(-1);
    }
  }
  if (fd < 0) {
    fprintf(stderr, "read: %m\n");
    exit(-1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<parse_xml_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <XML_ParserCreate@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10e0 <XML_SetElementHandler@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <XML_SetUserData@plt>
mov    -0x8(%rbp),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1250 <parse_xml_file+0x80>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    1255 <parse_xml_file+0x85>
mov    -0x1c(%rbp),%edi
mov    $0x1000,%esi
call   1030 <XML_GetBuffer@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    1289 <parse_xml_file+0xb9>
jmp    1300 <parse_xml_file+0x130>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%esi
cmpl   $0x0,-0x30(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edx
call   10b0 <XML_ParseBuffer@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%eax
jne    12fb <parse_xml_file+0x12b>
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <XML_GetCurrentLineNumber@plt>
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <XML_GetErrorCode@plt>
mov    %eax,%edi
call   10c0 <XML_ErrorString@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    %eax,%ecx
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    1255 <parse_xml_file+0x85>
cmpl   $0x0,-0x2c(%rbp)
jge    132b <parse_xml_file+0x15b>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_xml_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r14
xor    %edi,%edi
call   1050 <XML_ParserCreate@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %ebp,%esi
mov    %r12d,%edx
call   10e0 <XML_SetElementHandler@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <XML_SetUserData@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     12ae <parse_xml_file+0xde>
mov    %eax,%ebp
mov    0x2dbc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    $0x1000,%esi
call   1030 <XML_GetBuffer@plt>
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
test   %eax,%eax
je     129f <parse_xml_file+0xcf>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <XML_ParseBuffer@plt>
cmp    (%r14),%eax
jne    1230 <parse_xml_file+0x60>
mov    0x2d6a(%rip),%rax
mov    (%rax),%r14d
mov    %ebx,%edi
call   1060 <XML_GetCurrentLineNumber@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <XML_GetErrorCode@plt>
mov    %eax,%edi
call   10c0 <XML_ErrorString@plt>
lea    0xd90(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    %ebp,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <close@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"failed to open %s: %m\0A\00"
@XML_STATUS_ERROR = global i32 0
@.str.1 = [29 x i8] c"parse error at line %lu:\0A%s\0A\00"
@.str.2 = [10 x i8] c"read: %m\0A\00"
define void @parse_xml_file(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%14 = call i32 @XML_ParserCreate(i32* null)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = call i32 @XML_SetElementHandler(i32 %15, i32 %16, i32 %17)
%19 = load i32, i32* %9
%20 = load i8*, i8** %8
%21 = call i32 @XML_SetUserData(i32 %19, i8* %20)
%22 = load i8*, i8** %5
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %4
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %5
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %4
br label %33
33: ; preds = %32, %61
%34 = load i32, i32* %9
%35 = call i8* @XML_GetBuffer(i32 %34, i32 4096)
store i8* %35, i8** %10
%36 = load i32, i32* %11
%37 = load i8*, i8** %10
%38 = call i32 @read(i32 %36, i8* %37, i32 4096)
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
br label %62
42: ; preds = %33
%43 = load i32, i32* %9
%44 = load i32, i32* %12
%45 = load i32, i32* %12
%46 = icmp eq i32 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @XML_ParseBuffer(i32 %43, i32 %44, i32 %47)
store i32 %48, i32* %13
%49 = load i32, i32* %13
%50 = load i32, i32* @XML_STATUS_ERROR
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %61
52: ; preds = %42
%53 = load i32, i32* @stderr
%54 = load i32, i32* %9
%55 = call i32 @XML_GetCurrentLineNumber(i32 %54)
%56 = load i32, i32* %9
%57 = call i32 @XML_GetErrorCode(i32 %56)
%58 = call i32 @XML_ErrorString(i32 %57)
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %55, i32 %58)
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %42
br label %33
62: ; preds = %41
%63 = load i32, i32* %11
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%68 = call i32 @exit(i32 -1)
unreachable
69: ; preds = %62
%70 = load i32, i32* %11
%71 = call i32 @close(i32 %70)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"failed to open %s: %m\0A\00"
@XML_STATUS_ERROR = global i32 0
@.str.1 = [29 x i8] c"parse error at line %lu:\0A%s\0A\00"
define void @parse_xml_file(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32 @XML_ParserCreate(i32* null)
%6 = tail call i32 @XML_SetElementHandler(i32 %5, i32 %1, i32 %2)
%7 = tail call i32 @XML_SetUserData(i32 %5, i8* %3)
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* %0, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %4, %19
%16 = tail call i8* @XML_GetBuffer(i32 %5, i32 4096)
%17 = tail call i32 @read(i32 %9, i8* %16, i32 4096)
%18 = icmp eq i32 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %15
%20 = tail call i32 @XML_ParseBuffer(i32 %5, i32 %17, i32 0)
%21 = load i32, i32* @XML_STATUS_ERROR
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %15
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = tail call i32 @XML_GetCurrentLineNumber(i32 %5)
%26 = tail call i32 @XML_GetErrorCode(i32 %5)
%27 = tail call i32 @XML_ErrorString(i32 %26)
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %27)
%29 = tail call i32 @exit(i32 -1)
unreachable
30: ; preds = %15
%31 = tail call i32 @close(i32 %9)
ret void
}