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

/* Variables and functions */
int listxattr(char const *, char *, int);
int /*<<< orphan*/ print_xattrib_val(char const *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void list_xattr(const char *path) {
  char list[1000];
  int n = 0;
  int list_len;
  int len;
  list_len = listxattr(path, list, sizeof(list));
  printf("xattribs for %s, result is %d\n", path, list_len);
  while (n < list_len) {
    len = strlen(list + n);
    printf("\"%s\" value ", list + n);
    print_xattrib_val(path, list + n);
    n += (len + 1);
  }
  printf("end\n");
}


x86 assembly (clang, -O0):
<list_xattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x3f4(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x3f0(%rbp),%rsi
mov    $0x3e8,%edx
call   1030 <listxattr@plt>
mov    %eax,-0x3f8(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x3f8(%rbp),%edx
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3f4(%rbp),%eax
cmp    -0x3f8(%rbp),%eax
jge    120d <list_xattr+0xcd>
lea    -0x3f0(%rbp),%rdi
movslq -0x3f4(%rbp),%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3fc(%rbp)
lea    -0x3f0(%rbp),%rsi
movslq -0x3f4(%rbp),%rax
add    %rax,%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x3f0(%rbp),%rsi
movslq -0x3f4(%rbp),%rax
add    %rax,%rsi
call   1060 <print_xattrib_val@plt>
mov    -0x3fc(%rbp),%eax
add    $0x1,%eax
add    -0x3f4(%rbp),%eax
mov    %eax,-0x3f4(%rbp)
jmp    118c <list_xattr+0x4c>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_xattr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rdi,%r15
mov    %rsp,%rsi
mov    $0x3e8,%edx
call   1040 <listxattr@plt>
mov    %eax,%r12d
lea    0xe85(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
test   %r12d,%r12d
jle    11d4 <list_xattr+0x84>
lea    0xe8c(%rip),%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movslq %eax,%rbp
lea    (%rsp,%rbp,1),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <print_xattrib_val@plt>
lea    0x1(%rbp,%r13,1),%eax
cmp    %r12d,%eax
jl     11a0 <list_xattr+0x50>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"xattribs for %s, result is %d\0A\00"
@.str.1 = [12 x i8] c"\22%s\22 value \00"
@.str.2 = [5 x i8] c"end\0A\00"
define void @list_xattr(i8* %0) {
%2 = alloca i8*
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%7 = load i8*, i8** %2
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%9 = call i32 @listxattr(i8* %7, i8* %8, i32 1000)
store i32 %9, i32* %5
%10 = load i8*, i8** %2
%11 = load i32, i32* %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11)
br label %13
13: ; preds = %17, %1
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %38
17: ; preds = %13
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %6
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %2
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = call i32 @print_xattrib_val(i8* %28, i8* %32)
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
%36 = load i32, i32* %4
%37 = add nsw i32 %36, %35
store i32 %37, i32* %4
br label %13
38: ; preds = %13
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"xattribs for %s, result is %d\0A\00"
@.str.1 = [12 x i8] c"\22%s\22 value \00"
@str = [4 x i8] c"end\00"
define void @list_xattr(i8* %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = call i32 @listxattr(i8* %0, i8* %3, i32 1000)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %4)
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %17
7: ; preds = %1, %7
%8 = phi i32 [ %15, %7 ], [ 0, %1 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %9
%11 = call i32 @strlen(i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%13 = call i32 @print_xattrib_val(i8* %0, i8* %10)
%14 = add nsw i32 %8, 1
%15 = add i32 %14, %11
%16 = icmp slt i32 %15, %4
br i1 %16, label %7, label %17
17: ; preds = %7, %1
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
ret void
}