#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 */
struct xml_node {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
struct xml_node *xml_read_tree_file(int /*<<< orphan*/ *);
struct xml_node *xml_read_tree(const char *fname) {
  FILE *fp;
  struct xml_node *xml;
  if (!(fp = fopen(fname, "rb"))) {
    return 0;
  }
  xml = xml_read_tree_file(fp);
  fclose(fp);
  return xml;
}


x86 assembly (clang, -O0):
<xml_read_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1167 <xml_read_tree+0x37>
movq   $0x0,-0x8(%rbp)
jmp    1185 <xml_read_tree+0x55>
mov    -0x18(%rbp),%rdi
call   1050 <xml_read_tree_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xml_read_tree>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1160 <xml_read_tree+0x30>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <xml_read_tree_file@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
jmp    1162 <xml_read_tree+0x32>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.xml_node = type { i32 }
@.str = [3 x i8] c"rb\00"
define %struct.xml_node* @xml_read_tree(i8* %0) {
%2 = alloca %struct.xml_node*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.xml_node*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store %struct.xml_node* null, %struct.xml_node** %2
br label %16
10: ; preds = %1
%11 = load i32*, i32** %4
%12 = call %struct.xml_node* @xml_read_tree_file(i32* %11)
store %struct.xml_node* %12, %struct.xml_node** %5
%13 = load i32*, i32** %4
%14 = call i32 @fclose(i32* %13)
%15 = load %struct.xml_node*, %struct.xml_node** %5
store %struct.xml_node* %15, %struct.xml_node** %2
br label %16
16: ; preds = %10, %9
%17 = load %struct.xml_node*, %struct.xml_node** %2
ret %struct.xml_node* %17
}

LLVM IR (-O2):
%struct.xml_node = type { i32 }
@.str = [3 x i8] c"rb\00"
define %struct.xml_node* @xml_read_tree(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call %struct.xml_node* @xml_read_tree_file(i32* %2)
%6 = tail call i32 @fclose(i32* %2)
br label %7
7: ; preds = %1, %4
%8 = phi %struct.xml_node* [ %5, %4 ], [ null, %1 ]
ret %struct.xml_node* %8
}