#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 stat {
  int dummy;
};
struct stack {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ dtree_error_from_errno();
char *file_path_from_stack(struct stack **, char const *);
int /*<<< orphan*/ free(void *);
scalar_t__ stat(char const *, struct stat *);
int path_stat(struct stack **path, const char *fname, struct stat *st) {
  const char *fpath = file_path_from_stack(path, fname);
  if (fpath == NULL)
    goto clean_and_exit;
  if (stat(fpath, st))
    goto clean_and_exit;
  free((void *)fpath);
  return 0;
clean_and_exit:
  dtree_error_from_errno();
  if (fpath != NULL)
    free((void *)fpath);
  return 1;
}


x86 assembly (clang, -O0):
<path_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <file_path_from_stack@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1175 <path_stat+0x35>
jmp    11a6 <path_stat+0x66>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1191 <path_stat+0x51>
jmp    11a6 <path_stat+0x66>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <path_stat+0x88>
mov    $0x0,%al
call   1060 <dtree_error_from_errno@plt>
cmpq   $0x0,-0x28(%rbp)
je     11c1 <path_stat+0x81>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_stat>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
call   1050 <file_path_from_stack@plt>
test   %rax,%rax
je     1175 <path_stat+0x35>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <stat@plt>
test   %rax,%rax
je     1183 <path_stat+0x43>
xor    %eax,%eax
call   1060 <dtree_error_from_errno@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    117c <path_stat+0x3c>
xor    %eax,%eax
call   1060 <dtree_error_from_errno@plt>
mov    $0x1,%eax
jmp    118d <path_stat+0x4d>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
%struct.stat = type { i32 }
define i32 @path_stat(%struct.stack** %0, i8* %1, %struct.stat* %2) {
%4 = alloca i32
%5 = alloca %struct.stack**
%6 = alloca i8*
%7 = alloca %struct.stat*
%8 = alloca i8*
store %struct.stack** %0, %struct.stack*** %5
store i8* %1, i8** %6
store %struct.stat* %2, %struct.stat** %7
%9 = load %struct.stack**, %struct.stack*** %5
%10 = load i8*, i8** %6
%11 = call i8* @file_path_from_stack(%struct.stack** %9, i8* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
br label %24
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = load %struct.stat*, %struct.stat** %7
%18 = call i64 @stat(i8* %16, %struct.stat* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %24
21: ; preds = %15
%22 = load i8*, i8** %8
%23 = call i32 @free(i8* %22)
store i32 0, i32* %4
br label %32
24: ; preds = %20, %14
%25 = call i32 (...) @dtree_error_from_errno()
%26 = load i8*, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
br label %31
31: ; preds = %28, %24
store i32 1, i32* %4
br label %32
32: ; preds = %31, %21
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
%struct.stack = type { i32 }
%struct.stat = type { i32 }
define i32 @path_stat(%struct.stack** %0, i8* %1, %struct.stat* %2) {
%4 = tail call i8* @file_path_from_stack(%struct.stack** %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (...) @dtree_error_from_errno()
br label %16
8: ; preds = %3
%9 = tail call i64 @stat(i8* %4, %struct.stat* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @free(i8* %4)
br label %16
13: ; preds = %8
%14 = tail call i32 (...) @dtree_error_from_errno()
%15 = tail call i32 @free(i8* %4)
br label %16
16: ; preds = %6, %13, %11
%17 = phi i32 [ 0, %11 ], [ 1, %13 ], [ 1, %6 ]
ret i32 %17
}