#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 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(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;
  }
  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    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11d4 <read_xmlfile+0x54>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1330 <read_xmlfile+0x1b0>
mov    -0x20(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1220 <read_xmlfile+0xa0>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe14(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1330 <read_xmlfile+0x1b0>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0xffffffffffffffff,%rax
jne    1269 <read_xmlfile+0xe9>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdcb(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1330 <read_xmlfile+0x1b0>
mov    -0x20(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0xffffffff,%eax
jne    12b5 <read_xmlfile+0x135>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd7f(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1330 <read_xmlfile+0x1b0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1080 <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     131f <read_xmlfile+0x19f>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd3f(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1330 <read_xmlfile+0x1b0>
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    0xe6b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1236 <read_xmlfile+0xb6>
mov    %rax,%r12
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0xffffffff,%eax
je     1214 <read_xmlfile+0x94>
mov    %r12,%rdi
call   1070 <ftell@plt>
mov    %rax,(%r15)
cmp    $0xffffffffffffffff,%rax
je     1214 <read_xmlfile+0x94>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0xffffffff,%eax
je     1214 <read_xmlfile+0x94>
mov    (%r15),%rdi
call   1080 <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    125f <read_xmlfile+0xdf>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    1250 <read_xmlfile+0xd0>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    124e <read_xmlfile+0xce>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    122c <read_xmlfile+0xac>

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 %71
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 %71
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 %71
37: ; preds = %26
%38 = load i32*, i32** %6
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %4
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
store i8* null, i8** %3
br label %71
48: ; preds = %37
%49 = load i64*, i64** %5
%50 = load i64, i64* %49
%51 = call i64 @malloc(i64 %50)
%52 = inttoptr i64 %51 to i8*
store i8* %52, i8** %7
%53 = load i8*, i8** %7
%54 = load i64*, i64** %5
%55 = load i64, i64* %54
%56 = load i32*, i32** %6
%57 = call i32 @fread(i8* %53, i64 %55, i32 1, i32* %56)
%58 = icmp ne i32 %57, 1
br i1 %58, label %59, label %67
59: ; preds = %48
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %4
%62 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %61)
%63 = load i8*, i8** %7
%64 = call i32 @free(i8* %63)
%65 = load i32*, i32** %6
%66 = call i32 @fclose(i32* %65)
store i8* null, i8** %3
br label %71
67: ; preds = %48
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = load i8*, i8** %7
store i8* %70, i8** %3
br label %71
71: ; preds = %67, %59, %42, %31, %20, %11
%72 = load i8*, i8** %3
ret i8* %72
}

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 %45
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 %45
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 %45
23: ; preds = %16
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %3, i32 0, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%30 = tail call i32 @fclose(i32* %3)
br label %45
31: ; preds = %23
%32 = load i64, i64* %1
%33 = tail call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i8*
%35 = load i64, i64* %1
%36 = tail call i32 @fread(i8* %34, i64 %35, i32 1, i32* %3)
%37 = icmp eq i32 %36, 1
br i1 %37, label %43, label %38
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%41 = tail call i32 @free(i8* %34)
%42 = tail call i32 @fclose(i32* %3)
br label %45
43: ; preds = %31
%44 = tail call i32 @fclose(i32* %3)
br label %45
45: ; preds = %43, %38, %27, %19, %12, %5
%46 = phi i8* [ null, %12 ], [ null, %19 ], [ null, %27 ], [ null, %38 ], [ %34, %43 ], [ null, %5 ]
ret i8* %46
}