#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 *);
int xml_write_tree_file(struct xml_node *, int /*<<< orphan*/ *);
int xml_write_tree(struct xml_node *x, const char *fname) {
  FILE *fp;
  int res;
  if (!(fp = fopen(fname, "wb"))) {
    return -1;
  }
  res = xml_write_tree_file(x, fp);
  fclose(fp);
  return res;
}


x86 assembly (clang, -O0):
<xml_write_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116a <xml_write_tree+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <xml_write_tree+0x59>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <xml_write_tree_file@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xml_write_tree>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xebf(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     116a <xml_write_tree+0x3a>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <xml_write_tree_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    116f <xml_write_tree+0x3f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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