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

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IREAD;
int S_IWRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ list_xattr(char *);
int open(char *, int, int);
int /*<<< orphan*/ print_xattrib_val(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ removexattr(char *, char *);
int setxattr(char *, char *, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ unlink(char *);
void basic_xattr_test(const char *mountpt) {
  char name[100];
  int h;
  int result;
  int val1;
  strcpy(name, mountpt);
  strcat(name, "/");
  strcat(name, "xfile");
  unlink(name);
  h = open(name, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
  close(h);
  printf("Start\n");
  list_xattr(name);
  printf("Add an attribute\n");
  val1 = 0x123456;
  result = setxattr(name, "foo", &val1, sizeof(val1), 0);
  printf("wrote attribute foo: result %d\n", result);
  list_xattr(name);
  printf("Add an attribute\n");
  val1 = 0x7890;
  result = setxattr(name, "bar", &val1, sizeof(val1), 0);
  printf("wrote attribute bar: result %d\n", result);
  list_xattr(name);
  printf("Get non-existanrt attribute\n");
  print_xattrib_val(name, "not here");
  printf("Delete non existing attribute\n");
  removexattr(name, "not here");
  list_xattr(name);
  printf("Remove foo\n");
  removexattr(name, "foo");
  list_xattr(name);
  printf("Remove bar\n");
  removexattr(name, "bar");
  list_xattr(name);
}


x86 assembly (clang, -O0):
<basic_xattr_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x70(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    0x2dd6(%rip),%rax
or     (%rax),%esi
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
mov    0x2dbc(%rip),%rax
or     (%rax),%edx
call   10a0 <open@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%edi
call   1070 <close@plt>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1060 <list_xattr@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x123456,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xdc4(%rip),%rsi
lea    -0x7c(%rbp),%rdx
mov    $0x4,%ecx
xor    %r8d,%r8d
call   10c0 <setxattr@plt>
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1060 <list_xattr@plt>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x7890,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xd9a(%rip),%rsi
lea    -0x7c(%rbp),%rdx
mov    $0x4,%ecx
xor    %r8d,%r8d
call   10c0 <setxattr@plt>
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1060 <list_xattr@plt>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   1090 <print_xattrib_val@plt>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xd76(%rip),%rsi
call   1080 <removexattr@plt>
lea    -0x70(%rbp),%rdi
call   1060 <list_xattr@plt>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xcea(%rip),%rsi
call   1080 <removexattr@plt>
lea    -0x70(%rbp),%rdi
call   1060 <list_xattr@plt>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xce7(%rip),%rsi
call   1080 <removexattr@plt>
lea    -0x70(%rbp),%rdi
call   1060 <list_xattr@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_xattr_test>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2e00(%rip),%rax
mov    0x2df1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dce(%rip),%rax
or     (%rax),%esi
mov    0x2dad(%rip),%rax
mov    0x2db6(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,%edi
call   1080 <close@plt>
lea    0xe1d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1070 <list_xattr@plt>
lea    0xe0f(%rip),%r15
mov    %r15,%rdi
call   1050 <puts@plt>
movl   $0x123456,0xc(%rsp)
lea    0xe4a(%rip),%r14
lea    0xc(%rsp),%r12
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    $0x4,%ecx
xor    %r8d,%r8d
call   10d0 <setxattr@plt>
lea    0xd87(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <list_xattr@plt>
mov    %r15,%rdi
call   1050 <puts@plt>
movl   $0x7890,0xc(%rsp)
lea    0xe0b(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    $0x4,%ecx
xor    %r8d,%r8d
call   10d0 <setxattr@plt>
lea    0xd62(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <list_xattr@plt>
lea    0xd8a(%rip),%rdi
call   1050 <puts@plt>
lea    0xd5e(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <print_xattrib_val@plt>
lea    0xd88(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <removexattr@plt>
mov    %rbx,%rdi
call   1070 <list_xattr@plt>
lea    0xd87(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <removexattr@plt>
mov    %rbx,%rdi
call   1070 <list_xattr@plt>
lea    0xd73(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <removexattr@plt>
mov    %rbx,%rdi
call   1070 <list_xattr@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c"xfile\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str.2 = [7 x i8] c"Start\0A\00"
@.str.3 = [18 x i8] c"Add an attribute\0A\00"
@.str.4 = [4 x i8] c"foo\00"
@.str.5 = [32 x i8] c"wrote attribute foo: result %d\0A\00"
@.str.6 = [4 x i8] c"bar\00"
@.str.7 = [32 x i8] c"wrote attribute bar: result %d\0A\00"
@.str.8 = [29 x i8] c"Get non-existanrt attribute\0A\00"
@.str.9 = [9 x i8] c"not here\00"
@.str.10 = [31 x i8] c"Delete non existing attribute\0A\00"
@.str.11 = [12 x i8] c"Remove foo\0A\00"
@.str.12 = [12 x i8] c"Remove bar\0A\00"
define void @basic_xattr_test(i8* %0) {
%2 = alloca i8*
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = call i32 @unlink(i8* %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* @O_CREAT
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = load i32, i32* @O_RDWR
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IREAD
%23 = load i32, i32* @S_IWRITE
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %16, i32 %21, i32 %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%30 = call i32 @list_xattr(i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 1193046, i32* %6
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%33 = call i32 @setxattr(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %6, i32 4, i32 0)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%37 = call i32 @list_xattr(i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 30864, i32* %6
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%40 = call i32 @setxattr(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %6, i32 4, i32 0)
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%44 = call i32 @list_xattr(i8* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%47 = call i32 @print_xattrib_val(i8* %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0))
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%50 = call i32 @removexattr(i8* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%52 = call i32 @list_xattr(i8* %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%55 = call i32 @removexattr(i8* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%57 = call i32 @list_xattr(i8* %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%60 = call i32 @removexattr(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%62 = call i32 @list_xattr(i8* %61)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c"xfile\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str.4 = [4 x i8] c"foo\00"
@.str.5 = [32 x i8] c"wrote attribute foo: result %d\0A\00"
@.str.6 = [4 x i8] c"bar\00"
@.str.7 = [32 x i8] c"wrote attribute bar: result %d\0A\00"
@.str.9 = [9 x i8] c"not here\00"
@str = [6 x i8] c"Start\00"
@str.14 = [17 x i8] c"Add an attribute\00"
@str.15 = [28 x i8] c"Get non-existanrt attribute\00"
@str.16 = [30 x i8] c"Delete non existing attribute\00"
@str.17 = [11 x i8] c"Remove foo\00"
@str.18 = [11 x i8] c"Remove bar\00"
define void @basic_xattr_test(i8* %0) {
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i32 @strcpy(i8* %4, i8* %0)
%7 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @unlink(i8* %4)
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %11, %10
%13 = load i32, i32* @O_RDWR
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IREAD
%16 = load i32, i32* @S_IWRITE
%17 = or i32 %16, %15
%18 = call i32 @open(i8* %4, i32 %14, i32 %17)
%19 = call i32 @close(i32 %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%21 = call i32 @list_xattr(i8* %4)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.14, i64 0, i64 0))
store i32 1193046, i32* %3
%23 = call i32 @setxattr(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %3, i32 4, i32 0)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = call i32 @list_xattr(i8* %4)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.14, i64 0, i64 0))
store i32 30864, i32* %3
%27 = call i32 @setxattr(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %3, i32 4, i32 0)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = call i32 @list_xattr(i8* %4)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.15, i64 0, i64 0))
%31 = call i32 @print_xattrib_val(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.16, i64 0, i64 0))
%33 = call i32 @removexattr(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%34 = call i32 @list_xattr(i8* %4)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.17, i64 0, i64 0))
%36 = call i32 @removexattr(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @list_xattr(i8* %4)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.18, i64 0, i64 0))
%39 = call i32 @removexattr(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @list_xattr(i8* %4)
ret void
}