#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 yaffs_obj {
  int dummy;
};

/* Variables and functions */
scalar_t__ yaffsfs_CheckMemRegion(char const *, int /*<<< orphan*/,
                                  int /*<<< orphan*/);
scalar_t__ yaffsfs_CheckPath(char const *);
int yaffsfs_CountHandles(struct yaffs_obj *);
struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *, char const *,
                                     int /*<<< orphan*/, int,
                                     int /*<<< orphan*/, int /*<<< orphan*/,
                                     int /*<<< orphan*/);
int /*<<< orphan*/ yaffsfs_SetError(int);
int yaffs_n_handles_reldir(struct yaffs_obj *reldir, const char *path) {
  struct yaffs_obj *obj;
  if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
    yaffsfs_SetError(-14);
    return -1;
  }
  if (yaffsfs_CheckPath(path) < 0) {
    yaffsfs_SetError(-36);
    return -1;
  }
  obj = yaffsfs_FindObject(reldir, path, 0, 1, (0), (0), (0));
  if (obj)
    return yaffsfs_CountHandles(obj);
  else
    return -1;
}


x86 assembly (clang, -O0):
<yaffs_n_handles_reldir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <yaffsfs_CheckMemRegion@plt>
cmp    $0x0,%rax
jge    118d <yaffs_n_handles_reldir+0x3d>
mov    $0xfffffff2,%edi
call   1060 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <yaffs_n_handles_reldir+0xaf>
mov    -0x18(%rbp),%rdi
call   1070 <yaffsfs_CheckPath@plt>
cmp    $0x0,%rax
jge    11b6 <yaffs_n_handles_reldir+0x66>
mov    $0xffffffdc,%edi
call   1060 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <yaffs_n_handles_reldir+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %r9d,%r9d
mov    $0x1,%ecx
mov    %r9d,%edx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   1030 <yaffsfs_FindObject@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f8 <yaffs_n_handles_reldir+0xa8>
mov    -0x20(%rbp),%rdi
call   1050 <yaffsfs_CountHandles@plt>
mov    %eax,-0x4(%rbp)
jmp    11ff <yaffs_n_handles_reldir+0xaf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yaffs_n_handles_reldir>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <yaffsfs_CheckMemRegion@plt>
test   %rax,%rax
js     11ab <yaffs_n_handles_reldir+0x5b>
mov    %rbx,%rdi
call   1070 <yaffsfs_CheckPath@plt>
test   %rax,%rax
js     11b2 <yaffs_n_handles_reldir+0x62>
movl   $0x0,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <yaffsfs_FindObject@plt>
test   %rax,%rax
je     11bc <yaffs_n_handles_reldir+0x6c>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <yaffsfs_CountHandles@plt>
mov    $0xfffffff2,%edi
jmp    11b7 <yaffs_n_handles_reldir+0x67>
mov    $0xffffffdc,%edi
call   1060 <yaffsfs_SetError@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.yaffs_obj = type { i32 }
define i32 @yaffs_n_handles_reldir(%struct.yaffs_obj* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.yaffs_obj*
%5 = alloca i8*
%6 = alloca %struct.yaffs_obj*
store %struct.yaffs_obj* %0, %struct.yaffs_obj** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @yaffsfs_CheckMemRegion(i8* %7, i32 0, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @yaffsfs_SetError(i32 -14)
store i32 -1, i32* %3
br label %28
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i64 @yaffsfs_CheckPath(i8* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @yaffsfs_SetError(i32 -36)
store i32 -1, i32* %3
br label %28
18: ; preds = %12
%19 = load %struct.yaffs_obj*, %struct.yaffs_obj** %4
%20 = load i8*, i8** %5
%21 = call %struct.yaffs_obj* @yaffsfs_FindObject(%struct.yaffs_obj* %19, i8* %20, i32 0, i32 1, i32 0, i32 0, i32 0)
store %struct.yaffs_obj* %21, %struct.yaffs_obj** %6
%22 = load %struct.yaffs_obj*, %struct.yaffs_obj** %6
%23 = icmp ne %struct.yaffs_obj* %22, null
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load %struct.yaffs_obj*, %struct.yaffs_obj** %6
%26 = call i32 @yaffsfs_CountHandles(%struct.yaffs_obj* %25)
store i32 %26, i32* %3
br label %28
27: ; preds = %18
store i32 -1, i32* %3
br label %28
28: ; preds = %27, %24, %16, %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.yaffs_obj = type { i32 }
define i32 @yaffs_n_handles_reldir(%struct.yaffs_obj* %0, i8* %1) {
%3 = tail call i64 @yaffsfs_CheckMemRegion(i8* %1, i32 0, i32 0)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @yaffsfs_SetError(i32 -14)
br label %17
7: ; preds = %2
%8 = tail call i64 @yaffsfs_CheckPath(i8* %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @yaffsfs_SetError(i32 -36)
br label %17
12: ; preds = %7
%13 = tail call %struct.yaffs_obj* @yaffsfs_FindObject(%struct.yaffs_obj* %0, i8* %1, i32 0, i32 1, i32 0, i32 0, i32 0)
%14 = icmp eq %struct.yaffs_obj* %13, null
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @yaffsfs_CountHandles(%struct.yaffs_obj* %13)
br label %17
17: ; preds = %12, %15, %10, %5
%18 = phi i32 [ -1, %5 ], [ -1, %10 ], [ %16, %15 ], [ -1, %12 ]
ret i32 %18
}