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


x86 assembly (clang, -O0):
<yaffs_fsetxattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <yaffsfs_CheckMemRegion@plt>
cmp    $0x0,%rax
jl     11b0 <yaffs_fsetxattr+0x50>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
xor    %edx,%edx
call   1040 <yaffsfs_CheckMemRegion@plt>
cmp    $0x0,%rax
jge    11c6 <yaffs_fsetxattr+0x66>
mov    $0xfffffff2,%edi
call   1050 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <yaffs_fsetxattr+0xd9>
mov    $0x0,%al
call   1070 <yaffsfs_Lock@plt>
mov    -0x8(%rbp),%edi
call   1060 <yaffsfs_HandleToObject@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f3 <yaffs_fsetxattr+0x93>
mov    $0xfffffff7,%edi
call   1050 <yaffsfs_SetError@plt>
jmp    122c <yaffs_fsetxattr+0xcc>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1080 <yaffs_set_xattrib@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1227 <yaffs_fsetxattr+0xc7>
mov    -0x2c(%rbp),%edi
call   1050 <yaffsfs_SetError@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    122c <yaffs_fsetxattr+0xcc>
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_fsetxattr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r12d
mov    %rsi,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <yaffsfs_CheckMemRegion@plt>
test   %rax,%rax
js     11ca <yaffs_fsetxattr+0x6a>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %edx,%edx
call   1040 <yaffsfs_CheckMemRegion@plt>
test   %rax,%rax
js     11ca <yaffs_fsetxattr+0x6a>
xor    %eax,%eax
call   1070 <yaffsfs_Lock@plt>
mov    %r12d,%edi
call   1060 <yaffsfs_HandleToObject@plt>
test   %rax,%rax
je     11db <yaffs_fsetxattr+0x7b>
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1080 <yaffs_set_xattrib@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11ec <yaffs_fsetxattr+0x8c>
jmp    11e0 <yaffs_fsetxattr+0x80>
mov    $0xfffffff2,%edi
call   1050 <yaffsfs_SetError@plt>
mov    $0xffffffff,%ebx
jmp    11f3 <yaffs_fsetxattr+0x93>
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    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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