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

/* Variables and functions */
int EINTR;
int ENAMETOOLONG;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int PATH_MAX;
int check_xattr_support_impl(char *);
int close(int);
int errno;
int open(char *, int, int);
int /*<<< orphan*/ unlink(char *);
scalar_t__ zsnprintf(char *, int, char *, char const *);
int check_xattr_support(const char *base) {
  int ret, fd;
  char fname[PATH_MAX];
  if (zsnprintf(fname, sizeof(fname), "%s/.xattr.test", base))
    return -ENAMETOOLONG;
  fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0644);
  if (fd < 0)
    return -errno;
  do {
    ret = close(fd);
  } while ((ret == -1) && (errno == EINTR));
  ;
  ret = check_xattr_support_impl(fname);
  unlink(fname);
  return ret;
}


x86 assembly (clang, -O0):
<check_xattr_support>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe6b(%rip),%rdx
call   1060 <zsnprintf@plt>
cmp    $0x0,%rax
je     11be <check_xattr_support+0x6e>
xor    %eax,%eax
mov    0x2e0b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1272 <check_xattr_support+0x122>
mov    -0x38(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    0x2e1e(%rip),%rax
or     (%rax),%esi
mov    0x2dcd(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    120e <check_xattr_support+0xbe>
xor    %eax,%eax
mov    0x2dcb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1272 <check_xattr_support+0x122>
jmp    1213 <check_xattr_support+0xc3>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x14(%rbp)
mov    %al,-0x39(%rbp)
jne    1245 <check_xattr_support+0xf5>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    0x2d83(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1213 <check_xattr_support+0xc3>
mov    -0x38(%rbp),%rdi
call   1050 <check_xattr_support_impl@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,-0x14(%rbp)
call   1030 <unlink@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_xattr_support>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rcx
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe7e(%rip),%rdx
mov    %r14,%rdi
call   1060 <zsnprintf@plt>
test   %rax,%rax
je     119c <check_xattr_support+0x4c>
mov    0x2e22(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    1207 <check_xattr_support+0xb7>
mov    0x2e55(%rip),%rax
mov    0x2e46(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df3(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     1216 <check_xattr_support+0xc6>
mov    %eax,%ebx
mov    0x2df7(%rip),%r15
mov    0x2de8(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    11f5 <check_xattr_support+0xa5>
mov    (%r12),%eax
cmp    %eax,(%r15)
je     11e0 <check_xattr_support+0x90>
mov    %r14,%rdi
call   1050 <check_xattr_support_impl@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    %ebx,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dab(%rip),%rax
jmp    1196 <check_xattr_support+0x46>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [15 x i8] c"%s/.xattr.test\00"
@ENAMETOOLONG = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@errno = global i32 0
@EINTR = global i32 0
define i32 @check_xattr_support(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = trunc i64 %10 to i32
%14 = load i8*, i8** %3
%15 = call i64 @zsnprintf(i8* %12, i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i32, i32* @ENAMETOOLONG
%19 = sub nsw i32 0, %18
store i32 %19, i32* %2
store i32 1, i32* %8
br label %49
20: ; preds = %1
%21 = load i32, i32* @O_CREAT
%22 = load i32, i32* @O_TRUNC
%23 = or i32 %21, %22
%24 = load i32, i32* @O_WRONLY
%25 = or i32 %23, %24
%26 = call i32 @open(i8* %12, i32 %25, i32 420)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32, i32* @errno
%31 = sub nsw i32 0, %30
store i32 %31, i32* %2
store i32 1, i32* %8
br label %49
32: ; preds = %20
br label %33
33: ; preds = %43, %32
%34 = load i32, i32* %5
%35 = call i32 @close(i32 %34)
store i32 %35, i32* %4
br label %36
36: ; preds = %33
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* @errno
%41 = load i32, i32* @EINTR
%42 = icmp eq i32 %40, %41
br label %43
43: ; preds = %39, %36
%44 = phi i1 [ false, %36 ], [ %42, %39 ]
br i1 %44, label %33, label %45
45: ; preds = %43
%46 = call i32 @check_xattr_support_impl(i8* %12)
store i32 %46, i32* %4
%47 = call i32 @unlink(i8* %12)
%48 = load i32, i32* %4
store i32 %48, i32* %2
store i32 1, i32* %8
br label %49
49: ; preds = %45, %29, %17
%50 = load i8*, i8** %6
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [15 x i8] c"%s/.xattr.test\00"
@ENAMETOOLONG = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@errno = global i32 0
@EINTR = global i32 0
define i32 @check_xattr_support(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i64 @zsnprintf(i8* %4, i32 %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @ENAMETOOLONG
%9 = sub nsw i32 0, %8
br label %31
10: ; preds = %1
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %12, %11
%14 = load i32, i32* @O_WRONLY
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %4, i32 %15, i32 420)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* @errno
%20 = sub nsw i32 0, %19
br label %31
21: ; preds = %10, %21
%22 = call i32 @close(i32 %16)
%23 = icmp eq i32 %22, -1
%24 = load i32, i32* @errno
%25 = load i32, i32* @EINTR
%26 = icmp eq i32 %24, %25
%27 = select i1 %23, i1 %26, i1 false
br i1 %27, label %21, label %28
28: ; preds = %21
%29 = call i32 @check_xattr_support_impl(i8* %4)
%30 = call i32 @unlink(i8* %4)
br label %31
31: ; preds = %28, %18, %7
%32 = phi i32 [ %9, %7 ], [ %20, %18 ], [ %29, %28 ]
ret i32 %32
}