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

/* Variables and functions */
int /*<<< orphan*/ dat_free(struct dat *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
struct dat *xmlparser_parse(int /*<<< orphan*/ *);
struct dat *parse_dat(const char *path) {
  FILE *file;
  struct dat *d;
  if ((file = fopen(path, "r")) == NULL)
    return NULL;
  d = xmlparser_parse(file);
  if (fclose(file)) {
    if (d != NULL)
      dat_free(d);
    d = NULL;
  }
  return d;
}


x86 assembly (clang, -O0):
<parse_dat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1177 <parse_dat+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11bb <parse_dat+0x7b>
mov    -0x18(%rbp),%rdi
call   1050 <xmlparser_parse@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     11b3 <parse_dat+0x73>
cmpq   $0x0,-0x20(%rbp)
je     11ab <parse_dat+0x6b>
mov    -0x20(%rbp),%rdi
call   1030 <dat_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_dat>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117d <parse_dat+0x3d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <xmlparser_parse@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1180 <parse_dat+0x40>
test   %r14,%r14
je     117d <parse_dat+0x3d>
mov    %r14,%rdi
call   1030 <dat_free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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