#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 stack {
  int dummy;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ dtree_error_from_errno();
int /*<<< orphan*/ *opendir_on_stack(struct stack **);
scalar_t__ stack_push_fname(struct stack **, int /*<<< orphan*/);
DIR *open_dir_from_dirent(struct dirent *d, struct stack **path) {
  if (d == NULL)
    return NULL;
  if (stack_push_fname(path, d->d_name)) {
    dtree_error_from_errno();
    return NULL;
  }
  return opendir_on_stack(path);
}


x86 assembly (clang, -O0):
<open_dir_from_dirent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <open_dir_from_dirent+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1192 <open_dir_from_dirent+0x62>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1030 <stack_push_fname@plt>
cmp    $0x0,%rax
je     1185 <open_dir_from_dirent+0x55>
mov    $0x0,%al
call   1050 <dtree_error_from_errno@plt>
movq   $0x0,-0x8(%rbp)
jmp    1192 <open_dir_from_dirent+0x62>
mov    -0x18(%rbp),%rdi
call   1040 <opendir_on_stack@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_dir_from_dirent>:
push   %rbx
test   %rdi,%rdi
je     114f <open_dir_from_dirent+0x1f>
mov    %rsi,%rbx
mov    (%rdi),%esi
mov    %rbx,%rdi
call   1030 <stack_push_fname@plt>
test   %rax,%rax
je     1153 <open_dir_from_dirent+0x23>
xor    %eax,%eax
call   1050 <dtree_error_from_errno@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <opendir_on_stack@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.stack = type { i32 }
define i32* @open_dir_from_dirent(%struct.dirent* %0, %struct.stack** %1) {
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.stack**
store %struct.dirent* %0, %struct.dirent** %4
store %struct.stack** %1, %struct.stack*** %5
%6 = load %struct.dirent*, %struct.dirent** %4
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
store i32* null, i32** %3
br label %21
9: ; preds = %2
%10 = load %struct.stack**, %struct.stack*** %5
%11 = load %struct.dirent*, %struct.dirent** %4
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i64 @stack_push_fname(%struct.stack** %10, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 (...) @dtree_error_from_errno()
store i32* null, i32** %3
br label %21
18: ; preds = %9
%19 = load %struct.stack**, %struct.stack*** %5
%20 = call i32* @opendir_on_stack(%struct.stack** %19)
store i32* %20, i32** %3
br label %21
21: ; preds = %18, %16, %8
%22 = load i32*, i32** %3
ret i32* %22
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
%struct.stack = type { i32 }
define i32* @open_dir_from_dirent(%struct.dirent* %0, %struct.stack** %1) {
%3 = icmp eq %struct.dirent* %0, null
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i64 @stack_push_fname(%struct.stack** %1, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 (...) @dtree_error_from_errno()
br label %13
11: ; preds = %4
%12 = tail call i32* @opendir_on_stack(%struct.stack** %1)
br label %13
13: ; preds = %2, %11, %9
%14 = phi i32* [ null, %9 ], [ %12, %11 ], [ null, %2 ]
ret i32* %14
}