#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int errno;
scalar_t__ fsetxattr(int, char const *, char *, size_t, int /*<<< orphan*/);
size_t strlen(char *);
int xset_fill_buf(int, int, char *, int);
int fxseti(int fd, const char *xname, int base, int i) {
  int ret;
  size_t b_len;
  char buf[32];
  ret = xset_fill_buf(base, i, buf, sizeof(buf));
  if (ret)
    return ret;
  b_len = strlen(buf);
  if (fsetxattr(fd, xname, buf, b_len, 0) < 0)
    return -errno;
  return 0;
}


x86 assembly (clang, -O0):
<fxseti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x50(%rbp),%rdx
mov    $0x20,%ecx
call   1030 <xset_fill_buf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1171 <fxseti+0x41>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <fxseti+0x89>
lea    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    -0x28(%rbp),%rcx
xor    %r8d,%r8d
call   1040 <fsetxattr@plt>
cmp    $0x0,%rax
jge    11b2 <fxseti+0x82>
xor    %eax,%eax
mov    0x2e38(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <fxseti+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fxseti>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%eax
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsp,%rdx
mov    %eax,%edi
mov    %ecx,%esi
mov    $0x20,%ecx
call   1030 <xset_fill_buf@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1188 <fxseti+0x58>
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %r8d,%r8d
call   1040 <fsetxattr@plt>
test   %rax,%rax
jns    1188 <fxseti+0x58>
mov    0x2e5c(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @fxseti(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca [32 x i8]
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%16 = call i32 @xset_fill_buf(i32 %13, i32 %14, i8* %15, i32 32)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = load i32, i32* %10
store i32 %20, i32* %5
br label %34
21: ; preds = %4
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %11
%24 = load i32, i32* %6
%25 = load i8*, i8** %7
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%27 = load i64, i64* %11
%28 = call i64 @fsetxattr(i32 %24, i8* %25, i8* %26, i64 %27, i32 0)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* @errno
%32 = sub nsw i32 0, %31
store i32 %32, i32* %5
br label %34
33: ; preds = %21
store i32 0, i32* %5
br label %34
34: ; preds = %33, %30, %19
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @fxseti(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = call i32 @xset_fill_buf(i32 %2, i32 %3, i8* %6, i32 32)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = call i64 @strlen(i8* %6)
%11 = call i64 @fsetxattr(i32 %0, i8* %1, i8* %6, i64 %10, i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @errno
%15 = sub nsw i32 0, %14
br label %16
16: ; preds = %9, %4, %13
%17 = phi i32 [ %15, %13 ], [ %7, %4 ], [ 0, %9 ]
ret i32 %17
}