#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 ssize_t;

/* Variables and functions */
int EINVAL;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int listxattr(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int llistxattr(char *, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  char *path, *buf;
  ssize_t ret_buf, ret_null, error_s;
  int ret = 0;
  if (argc != 2) {
    usage(argv[0]);
    exit(1);
  }
  path = argv[1];
  ret_null = listxattr(path, NULL, 0);
  if (ret_null < 0) {
    fprintf(stderr,
            "listxattr(%s, NULL, 0) failed "
            "with %i: %s\n",
            path, errno, strerror(errno));
    ret = errno;
    goto out;
  }
  if (ret_null < 2) {
    fprintf(stderr,
            "listxattr(%s, NULL, 0) returned"
            "a sizes less than 2",
            path);
    ret = EINVAL;
    goto out;
  }
  error_s = ret_null - 1;
  buf = (char *)malloc(error_s);
  if (buf == NULL) {
    fprintf(stderr, "malloc(%zi) failed with %i: %s\n", error_s, errno,
            strerror(errno));
    ret = errno;
    goto out;
  }
  ret_buf = llistxattr(path, buf, error_s);
  if (ret_buf != -1) {
    fprintf(stderr,
            "llistxattr(%s, %p, %zi) passed with %zi but "
            "should have failed with -1\n",
            path, buf, error_s, ret_buf);
    ret = EINVAL;
    goto free;
  }
free:
  free(buf);
out:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bd <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <listxattr@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    123f <main+0xbf>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    %rax,%r8
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    134f <main+0x1cf>
cmpl   $0x2,-0x28(%rbp)
jge    1275 <main+0xf5>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    134f <main+0x1cf>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12ec <main+0x16c>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    %rax,%r8
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    134f <main+0x1cf>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <llistxattr@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     1341 <main+0x1c1>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1346 <main+0x1c6>
jmp    1346 <main+0x1c6>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    12b0 <main+0x130>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <listxattr@plt>
test   %eax,%eax
js     11d3 <main+0x53>
mov    %eax,%ebp
cmp    $0x1,%eax
ja     120f <main+0x8f>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%ebx
jmp    12a3 <main+0x123>
mov    0x2e06(%rip),%rax
mov    (%rax),%r14d
mov    0x2df4(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xe0b(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%ebx
jmp    12a3 <main+0x123>
add    $0xffffffff,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1261 <main+0xe1>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1040 <llistxattr@plt>
cmp    $0xffffffff,%eax
je     1299 <main+0x119>
mov    0x2da6(%rip),%rcx
mov    (%rcx),%edi
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%ebx
jmp    129b <main+0x11b>
mov    0x2d78(%rip),%rax
mov    (%rax),%r14d
mov    0x2d66(%rip),%r15
mov    (%r15),%ebx
mov    %ebx,%edi
call   10a0 <strerror@plt>
lea    0xddb(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%ebx
jmp    12a3 <main+0x123>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rdi
call   1080 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"listxattr(%s, NULL, 0) failed with %i: %s\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"listxattr(%s, NULL, 0) returneda sizes less than 2\00"
@EINVAL = global i32 0
@.str.2 = [32 x i8] c"malloc(%zi) failed with %i: %s\0A\00"
@.str.3 = [72 x i8] c"llistxattr(%s, %p, %zi) passed with %zi but should have failed with -1\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @usage(i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = call i32 @listxattr(i8* %24, i32* null, i32 0)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %6
%31 = load i32, i32* @errno
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %30, i32 %31, i8* %33)
%35 = load i32, i32* @errno
store i32 %35, i32* %11
br label %79
36: ; preds = %20
%37 = load i32, i32* %9
%38 = icmp slt i32 %37, 2
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %6
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EINVAL
store i32 %43, i32* %11
br label %79
44: ; preds = %36
%45 = load i32, i32* %9
%46 = sub nsw i32 %45, 1
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %7
%50 = load i8*, i8** %7
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %60
52: ; preds = %44
%53 = load i32, i32* @stderr
%54 = load i32, i32* %10
%55 = load i32, i32* @errno
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %55, i8* %57)
%59 = load i32, i32* @errno
store i32 %59, i32* %11
br label %79
60: ; preds = %44
%61 = load i8*, i8** %6
%62 = load i8*, i8** %7
%63 = load i32, i32* %10
%64 = call i32 @llistxattr(i8* %61, i8* %62, i32 %63)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp ne i32 %65, -1
br i1 %66, label %67, label %75
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %6
%70 = load i8*, i8** %7
%71 = load i32, i32* %10
%72 = load i32, i32* %8
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i8* %69, i8* %70, i32 %71, i32 %72)
%74 = load i32, i32* @EINVAL
store i32 %74, i32* %11
br label %76
75: ; preds = %60
br label %76
76: ; preds = %75, %67
%77 = load i8*, i8** %7
%78 = call i32 @free(i8* %77)
br label %79
79: ; preds = %76, %52, %39, %28
%80 = load i32, i32* %11
ret i32 %80
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"listxattr(%s, NULL, 0) failed with %i: %s\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"listxattr(%s, NULL, 0) returneda sizes less than 2\00"
@EINVAL = global i32 0
@.str.2 = [32 x i8] c"malloc(%zi) failed with %i: %s\0A\00"
@.str.3 = [72 x i8] c"llistxattr(%s, %p, %zi) passed with %zi but should have failed with -1\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @listxattr(i8* %10, i32* null, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %15, i8* %16)
%18 = load i32, i32* @errno
br label %46
19: ; preds = %8
%20 = icmp ult i32 %11, 2
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%24 = load i32, i32* @EINVAL
br label %46
25: ; preds = %19
%26 = add nsw i32 %11, -1
%27 = tail call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = icmp eq i64 %27, 0
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %32, i8* %33)
%35 = load i32, i32* @errno
br label %46
36: ; preds = %25
%37 = tail call i32 @llistxattr(i8* %10, i8* %28, i32 %26)
%38 = icmp eq i32 %37, -1
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i8* %10, i8* %28, i32 %26, i32 %37)
%42 = load i32, i32* @EINVAL
br label %43
43: ; preds = %36, %39
%44 = phi i32 [ %42, %39 ], [ 0, %36 ]
%45 = tail call i32 @free(i8* %28)
br label %46
46: ; preds = %43, %30, %21, %13
%47 = phi i32 [ %18, %13 ], [ %24, %21 ], [ %35, %30 ], [ %44, %43 ]
ret i32 %47
}