#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*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ stderr;
char *read_xmlfile(const char filename[], long *fsize) {
  FILE *fp;
  char *data;
  if (!(fp = fopen(filename, "r"))) {
    fprintf(stderr, "XML file %s not found\n", filename);
    return NULL;
  }
  if (fseek(fp, 0, SEEK_END) == -1) {
    fprintf(stderr, "XML file %s broken (seek error)\n", filename);
    fclose(fp);
    return NULL;
  }
  if ((*fsize = ftell(fp)) == -1) {
    fprintf(stderr, "XML file %s broken (seek error)\n", filename);
    fclose(fp);
    return NULL;
  }
  assert(*fsize >= 0);
  if (fseek(fp, 0, SEEK_SET) == -1) {
    fprintf(stderr, "XML file %s broken (seek error)\n", filename);
    fclose(fp);
    return NULL;
  }
  data = (char *)malloc((size_t)*fsize);
  if (fread(data, (size_t)*fsize, 1, fp) != 1) {
    fprintf(stderr, "XML file %s broken (read error)\n", filename);
    free(data);
    fclose(fp);
    return NULL;
  }
  fclose(fp);
  return data;
}


x86 assembly (clang, -O0):
<read_xmlfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e4 <read_xmlfile+0x54>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe30(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1355 <read_xmlfile+0x1c5>
mov    -0x20(%rbp),%rdi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1230 <read_xmlfile+0xa0>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe04(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1355 <read_xmlfile+0x1c5>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0xffffffffffffffff,%rax
jne    1279 <read_xmlfile+0xe9>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdbb(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1355 <read_xmlfile+0x1c5>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d37(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0xffffffff,%eax
jne    12da <read_xmlfile+0x14a>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd5a(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1355 <read_xmlfile+0x1c5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1344 <read_xmlfile+0x1b4>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd1a(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1355 <read_xmlfile+0x1c5>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_xmlfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe5b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1254 <read_xmlfile+0xc4>
mov    %rax,%r12
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0xffffffff,%eax
je     1232 <read_xmlfile+0xa2>
mov    %r12,%rdi
call   1080 <ftell@plt>
mov    %rax,(%r15)
cmp    $0xffffffffffffffff,%rax
je     1232 <read_xmlfile+0xa2>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0xffffffff,%eax
je     1232 <read_xmlfile+0xa2>
mov    (%r15),%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    127d <read_xmlfile+0xed>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    126e <read_xmlfile+0xde>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    126c <read_xmlfile+0xdc>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    124a <read_xmlfile+0xba>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"XML file %s not found\0A\00"
@SEEK_END = global i32 0
@.str.2 = [33 x i8] c"XML file %s broken (seek error)\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [33 x i8] c"XML file %s broken (read error)\0A\00"
define i8* @read_xmlfile(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i8* null, i8** %3
br label %76
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %6
%25 = call i32 @fclose(i32* %24)
store i8* null, i8** %3
br label %76
26: ; preds = %15
%27 = load i32*, i32** %6
%28 = call i64 @ftell(i32* %27)
%29 = load i64*, i64** %5
store i64 %28, i64* %29
%30 = icmp eq i64 %28, -1
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %4
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
store i8* null, i8** %3
br label %76
37: ; preds = %26
%38 = load i64*, i64** %5
%39 = load i64, i64* %38
%40 = icmp sge i64 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i32*, i32** %6
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @fseek(i32* %43, i32 0, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %53
47: ; preds = %37
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %4
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
store i8* null, i8** %3
br label %76
53: ; preds = %37
%54 = load i64*, i64** %5
%55 = load i64, i64* %54
%56 = call i64 @malloc(i64 %55)
%57 = inttoptr i64 %56 to i8*
store i8* %57, i8** %7
%58 = load i8*, i8** %7
%59 = load i64*, i64** %5
%60 = load i64, i64* %59
%61 = load i32*, i32** %6
%62 = call i32 @fread(i8* %58, i64 %60, i32 1, i32* %61)
%63 = icmp ne i32 %62, 1
br i1 %63, label %64, label %72
64: ; preds = %53
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %4
%67 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %66)
%68 = load i8*, i8** %7
%69 = call i32 @free(i8* %68)
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
store i8* null, i8** %3
br label %76
72: ; preds = %53
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i8*, i8** %7
store i8* %75, i8** %3
br label %76
76: ; preds = %72, %64, %47, %31, %20, %11
%77 = load i8*, i8** %3
ret i8* %77
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"XML file %s not found\0A\00"
@SEEK_END = global i32 0
@.str.2 = [33 x i8] c"XML file %s broken (seek error)\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [33 x i8] c"XML file %s broken (read error)\0A\00"
define i8* @read_xmlfile(i8* %0, i64* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %49
8: ; preds = %2
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %3, i32 0, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = tail call i32 @fclose(i32* %3)
br label %49
16: ; preds = %8
%17 = tail call i64 @ftell(i32* %3)
store i64 %17, i64* %1
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%22 = tail call i32 @fclose(i32* %3)
br label %49
23: ; preds = %16
%24 = lshr i64 %17, 63
%25 = trunc i64 %24 to i32
%26 = xor i32 %25, 1
%27 = tail call i32 @assert(i32 %26)
%28 = load i32, i32* @SEEK_SET
%29 = tail call i32 @fseek(i32* %3, i32 0, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%34 = tail call i32 @fclose(i32* %3)
br label %49
35: ; preds = %23
%36 = load i64, i64* %1
%37 = tail call i64 @malloc(i64 %36)
%38 = inttoptr i64 %37 to i8*
%39 = load i64, i64* %1
%40 = tail call i32 @fread(i8* %38, i64 %39, i32 1, i32* %3)
%41 = icmp eq i32 %40, 1
br i1 %41, label %47, label %42
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%45 = tail call i32 @free(i8* %38)
%46 = tail call i32 @fclose(i32* %3)
br label %49
47: ; preds = %35
%48 = tail call i32 @fclose(i32* %3)
br label %49
49: ; preds = %47, %42, %31, %19, %12, %5
%50 = phi i8* [ null, %12 ], [ null, %19 ], [ null, %31 ], [ null, %42 ], [ %38, %47 ], [ null, %5 ]
ret i8* %50
}