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


x86 assembly (clang, -O0):
<yaffs_fgetxattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <yaffsfs_CheckMemRegion@plt>
cmp    $0x0,%rax
jl     11af <yaffs_fgetxattr+0x4f>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1050 <yaffsfs_CheckMemRegion@plt>
cmp    $0x0,%rax
jge    11c5 <yaffs_fgetxattr+0x65>
mov    $0xfffffff2,%edi
call   1060 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <yaffs_fgetxattr+0xcf>
mov    $0x0,%al
call   1080 <yaffsfs_Lock@plt>
mov    -0x8(%rbp),%edi
call   1070 <yaffsfs_HandleToObject@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1218 <yaffs_fgetxattr+0xb8>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <yaffs_get_xattrib@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1213 <yaffs_fgetxattr+0xb3>
mov    -0x2c(%rbp),%edi
call   1060 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1222 <yaffs_fgetxattr+0xc2>
mov    $0xfffffff7,%edi
call   1060 <yaffsfs_SetError@plt>
mov    $0x0,%al
call   1030 <yaffsfs_Unlock@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yaffs_fgetxattr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r15d
mov    %rsi,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <yaffsfs_CheckMemRegion@plt>
test   %rax,%rax
js     11c6 <yaffs_fgetxattr+0x66>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
call   1050 <yaffsfs_CheckMemRegion@plt>
test   %rax,%rax
js     11c6 <yaffs_fgetxattr+0x66>
xor    %eax,%eax
call   1080 <yaffsfs_Lock@plt>
mov    %r15d,%edi
call   1070 <yaffsfs_HandleToObject@plt>
test   %rax,%rax
je     11d7 <yaffs_fgetxattr+0x77>
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1040 <yaffs_get_xattrib@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e8 <yaffs_fgetxattr+0x88>
jmp    11dc <yaffs_fgetxattr+0x7c>
mov    $0xfffffff2,%edi
call   1060 <yaffsfs_SetError@plt>
mov    $0xffffffff,%ebx
jmp    11ef <yaffs_fgetxattr+0x8f>
mov    $0xfffffff7,%ebx
mov    %ebx,%edi
call   1060 <yaffsfs_SetError@plt>
mov    $0xffffffff,%ebx
xor    %eax,%eax
call   1030 <yaffsfs_Unlock@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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