#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 */

/* Variables and functions */
int ENODATA;
int _fgetxattr(int, char const *, void *, size_t);
int errno;
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int xattr_get(int fd, const char *name, void *value, size_t size) {
  if (_fgetxattr(fd, name, value, size) == -1) {
    if (errno == ENODATA) {
      memset(value, 0, size);
      return 0;
    }
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<xattr_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <_fgetxattr@plt>
cmp    $0xffffffff,%eax
jne    119a <xattr_get+0x7a>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%eax
jne    1187 <xattr_get+0x67>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <xattr_get+0x81>
xor    %eax,%eax
mov    0x2e48(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <xattr_get+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xattr_get>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
call   1040 <_fgetxattr@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    115d <xattr_get+0x3d>
mov    0x2e9b(%rip),%rax
mov    (%rax),%ebp
mov    0x2ea2(%rip),%rax
cmp    (%rax),%ebp
jne    115b <xattr_get+0x3b>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
jmp    115d <xattr_get+0x3d>
neg    %ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@ENODATA = global i32 0
define i32 @xattr_get(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load i32, i32* %6
%11 = load i8*, i8** %7
%12 = load i8*, i8** %8
%13 = load i64, i64* %9
%14 = call i32 @_fgetxattr(i32 %10, i8* %11, i8* %12, i64 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %27
16: ; preds = %4
%17 = load i32, i32* @errno
%18 = load i32, i32* @ENODATA
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i64, i64* %9
%23 = call i32 @memset(i8* %21, i32 0, i64 %22)
store i32 0, i32* %5
br label %28
24: ; preds = %16
%25 = load i32, i32* @errno
%26 = sub nsw i32 0, %25
store i32 %26, i32* %5
br label %28
27: ; preds = %4
store i32 0, i32* %5
br label %28
28: ; preds = %27, %24, %20
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
@errno = global i32 0
@ENODATA = global i32 0
define i32 @xattr_get(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i32 @_fgetxattr(i32 %0, i8* %1, i8* %2, i64 %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = load i32, i32* @ENODATA
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @memset(i8* %2, i32 0, i64 %3)
br label %15
13: ; preds = %7
%14 = sub nsw i32 0, %8
br label %15
15: ; preds = %4, %13, %11
%16 = phi i32 [ 0, %11 ], [ %14, %13 ], [ 0, %4 ]
ret i32 %16
}