#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 */
int yaffs_list_xattrib(struct yaffs_obj *, char *, int);
scalar_t__ yaffsfs_CheckMemRegion(char *, int, int);
struct yaffs_obj *yaffsfs_HandleToObject(int);
int /*<<< orphan*/ yaffsfs_Lock();
int /*<<< orphan*/ yaffsfs_SetError(int);
int /*<<< orphan*/ yaffsfs_Unlock();
int yaffs_flistxattr(int fd, char *data, int size) {
  struct yaffs_obj *obj;
  int retVal = -1;
  if (yaffsfs_CheckMemRegion(data, size, 1) < 0) {
    yaffsfs_SetError(-14);
    return -1;
  }
  yaffsfs_Lock();
  obj = yaffsfs_HandleToObject(fd);
  if (obj) {
    retVal = yaffs_list_xattrib(obj, data, size);
    if (retVal < 0) {
      yaffsfs_SetError(retVal);
      retVal = -1;
    }
  } else
    yaffsfs_SetError(-9);
  yaffsfs_Unlock();
  return retVal;
}


x86 assembly (clang, -O0):
<yaffs_flistxattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <yaffsfs_CheckMemRegion@plt>
cmp    $0x0,%rax
jge    11aa <yaffs_flistxattr+0x4a>
mov    $0xfffffff2,%edi
call   1050 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <yaffs_flistxattr+0xb0>
mov    $0x0,%al
call   1070 <yaffsfs_Lock@plt>
mov    -0x8(%rbp),%edi
call   1060 <yaffsfs_HandleToObject@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f9 <yaffs_flistxattr+0x99>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1080 <yaffs_list_xattrib@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11f4 <yaffs_flistxattr+0x94>
mov    -0x24(%rbp),%edi
call   1050 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1203 <yaffs_flistxattr+0xa3>
mov    $0xfffffff7,%edi
call   1050 <yaffsfs_SetError@plt>
mov    $0x0,%al
call   1030 <yaffsfs_Unlock@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yaffs_flistxattr>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
mov    %edx,%esi
mov    $0x1,%edx
call   1040 <yaffsfs_CheckMemRegion@plt>
test   %rax,%rax
js     11a9 <yaffs_flistxattr+0x49>
xor    %eax,%eax
call   1070 <yaffsfs_Lock@plt>
mov    %r14d,%edi
call   1060 <yaffsfs_HandleToObject@plt>
test   %rax,%rax
je     11ba <yaffs_flistxattr+0x5a>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <yaffs_list_xattrib@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11cb <yaffs_flistxattr+0x6b>
jmp    11bf <yaffs_flistxattr+0x5f>
mov    $0xfffffff2,%edi
call   1050 <yaffsfs_SetError@plt>
mov    $0xffffffff,%ebx
jmp    11d2 <yaffs_flistxattr+0x72>
mov    $0xfffffff7,%ebx
mov    %ebx,%edi
call   1050 <yaffsfs_SetError@plt>
mov    $0xffffffff,%ebx
xor    %eax,%eax
call   1030 <yaffsfs_Unlock@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.yaffs_obj = type { i32 }
define i32 @yaffs_flistxattr(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.yaffs_obj*
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 -1, i32* %9
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i64 @yaffsfs_CheckMemRegion(i8* %10, i32 %11, i32 1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @yaffsfs_SetError(i32 -14)
store i32 -1, i32* %4
br label %38
16: ; preds = %3
%17 = call i32 (...) @yaffsfs_Lock()
%18 = load i32, i32* %5
%19 = call %struct.yaffs_obj* @yaffsfs_HandleToObject(i32 %18)
store %struct.yaffs_obj* %19, %struct.yaffs_obj** %8
%20 = load %struct.yaffs_obj*, %struct.yaffs_obj** %8
%21 = icmp ne %struct.yaffs_obj* %20, null
br i1 %21, label %22, label %33
22: ; preds = %16
%23 = load %struct.yaffs_obj*, %struct.yaffs_obj** %8
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32 @yaffs_list_xattrib(%struct.yaffs_obj* %23, i8* %24, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %9
%31 = call i32 @yaffsfs_SetError(i32 %30)
store i32 -1, i32* %9
br label %32
32: ; preds = %29, %22
br label %35
33: ; preds = %16
%34 = call i32 @yaffsfs_SetError(i32 -9)
br label %35
35: ; preds = %33, %32
%36 = call i32 (...) @yaffsfs_Unlock()
%37 = load i32, i32* %9
store i32 %37, i32* %4
br label %38
38: ; preds = %35, %14
%39 = load i32, i32* %4
ret i32 %39
}

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