#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 ENOSYS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int fgetxattr(int, char *, void *, int);
int flistxattr(int, char *, int);
int fsetxattr(int, char *, void *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  ssize_t s;
  char *tok;
  char value[1024];
  char list[1024];
  int rc = 0;
  char *file;
  int fd;
  if (argc < 2) {
    printf("Please enter a file name as argument.\n");
    return -1;
  }
  file = argv[1];
  fd = open(file, O_RDONLY);
  if (fd < 0) {
    printf("Unable to open file %s !", file);
    return -1;
  }
  if (-1 == (s = flistxattr(fd, list, 1024))) {
    perror("flistxattr");
    return 1;
  }
  if (s == 0) {
    printf("No xattrs defined for %s, further testcase useless\n", file);
    return 1;
  }
  tok = strtok(list, "\0");
  s = fgetxattr(fd, tok, (void *)value, 1024);
  if (s == -1) {
    perror("fgetxattr");
    return 1;
  }
  s = fsetxattr(fd, tok, (void *)value, s, 0);
  if (s == -1) {
    printf("User unable to change extended attributes on file %s !\n", argv[1]);
    printf("errno = %i\n", errno);
    rc = 1;
  }
  s = -1;
  errno = ENOSYS;
  if (s == -1) {
    printf("User unable to remove extended attributes file %s !\n", argv[1]);
    printf("errno = %i\n", errno);
    rc = 1;
  }
  close(fd);
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x824(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c7 <main+0x47>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x230>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x834(%rbp)
cmpl   $0x0,-0x834(%rbp)
jge    121f <main+0x9f>
mov    -0x830(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x230>
mov    -0x834(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
call   1030 <flistxattr@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1260 <main+0xe0>
lea    0xdf1(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b0 <main+0x230>
cmpl   $0x0,-0x14(%rbp)
jne    128b <main+0x10b>
mov    -0x830(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b0 <main+0x230>
lea    -0x820(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x834(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    -0x420(%rbp),%rdx
mov    $0x400,%ecx
call   1070 <fgetxattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12e2 <main+0x162>
lea    0xdae(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b0 <main+0x230>
mov    -0x834(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    -0x420(%rbp),%rdx
mov    -0x14(%rbp),%ecx
xor    %r8d,%r8d
call   1040 <fsetxattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1342 <main+0x1c2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%esi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x824(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    0x2c90(%rip),%rax
mov    (%rax),%ecx
mov    0x2c77(%rip),%rax
mov    %ecx,(%rax)
cmpl   $0xffffffff,-0x14(%rbp)
jne    139c <main+0x21c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%esi
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x824(%rbp)
mov    -0x834(%rbp),%edi
call   1060 <close@plt>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
cmp    $0x1,%edi
jg     11b6 <main+0x26>
lea    0xf34(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    12e0 <main+0x150>
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     12b2 <main+0x122>
mov    %eax,%r14d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1030 <flistxattr@plt>
test   %eax,%eax
je     12ca <main+0x13a>
cmp    $0xffffffff,%eax
je     12ec <main+0x15c>
lea    0xf01(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <strtok@plt>
mov    %rax,%rbp
lea    0x400(%rsp),%rdx
mov    %r14d,%edi
mov    %rax,%rsi
mov    $0x400,%ecx
call   1080 <fgetxattr@plt>
cmp    $0xffffffff,%eax
je     12fa <main+0x16a>
lea    0x400(%rsp),%rdx
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%ecx
xor    %r8d,%r8d
call   1050 <fsetxattr@plt>
cmp    $0xffffffff,%eax
jne    1272 <main+0xe2>
mov    0x8(%rbx),%rsi
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    0x2d4e(%rip),%rbp
mov    %eax,0x0(%rbp)
mov    0x8(%rbx),%rsi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp),%esi
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    12db <main+0x14b>
lea    0xd47(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    12e0 <main+0x150>
lea    0xd53(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd26(%rip),%rdi
call   10a0 <perror@plt>
jmp    12db <main+0x14b>
lea    0xd57(%rip),%rdi
call   10a0 <perror@plt>
jmp    12db <main+0x14b>

LLVM IR (-O0):
@.str = [39 x i8] c"Please enter a file name as argument.\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Unable to open file %s !\00"
@.str.2 = [11 x i8] c"flistxattr\00"
@.str.3 = [52 x i8] c"No xattrs defined for %s, further testcase useless\0A\00"
@.str.4 = [2 x i8] zeroinitializer
@.str.5 = [10 x i8] c"fgetxattr\00"
@.str.6 = [56 x i8] c"User unable to change extended attributes on file %s !\0A\00"
@.str.7 = [12 x i8] c"errno = %i\0A\00"
@errno = global i32 0
@ENOSYS = global i32 0
@.str.8 = [53 x i8] c"User unable to remove extended attributes file %s !\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %83
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %11
%21 = load i8*, i8** %11
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %17
%27 = load i8*, i8** %11
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
br label %83
29: ; preds = %17
%30 = load i32, i32* %12
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%32 = call i32 @flistxattr(i32 %30, i8* %31, i32 1024)
store i32 %32, i32* %6
%33 = icmp eq i32 -1, %32
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %83
36: ; preds = %29
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i8*, i8** %11
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %40)
store i32 1, i32* %3
br label %83
42: ; preds = %36
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = call i8* @strtok(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %44, i8** %7
%45 = load i32, i32* %12
%46 = load i8*, i8** %7
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%48 = call i32 @fgetxattr(i32 %45, i8* %46, i8* %47, i32 1024)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %83
53: ; preds = %42
%54 = load i32, i32* %12
%55 = load i8*, i8** %7
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%57 = load i32, i32* %6
%58 = call i32 @fsetxattr(i32 %54, i8* %55, i8* %56, i32 %57, i32 0)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %68
61: ; preds = %53
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @errno
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %66)
store i32 1, i32* %10
br label %68
68: ; preds = %61, %53
store i32 -1, i32* %6
%69 = load i32, i32* @ENOSYS
store i32 %69, i32* @errno
%70 = load i32, i32* %6
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %79
72: ; preds = %68
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0), i8* %75)
%77 = load i32, i32* @errno
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %77)
store i32 1, i32* %10
br label %79
79: ; preds = %72, %68
%80 = load i32, i32* %12
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* %10
store i32 %82, i32* %3
br label %83
83: ; preds = %79, %51, %39, %34, %26, %15
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Unable to open file %s !\00"
@.str.2 = [11 x i8] c"flistxattr\00"
@.str.3 = [52 x i8] c"No xattrs defined for %s, further testcase useless\0A\00"
@.str.4 = [2 x i8] zeroinitializer
@.str.5 = [10 x i8] c"fgetxattr\00"
@.str.6 = [56 x i8] c"User unable to change extended attributes on file %s !\0A\00"
@.str.7 = [12 x i8] c"errno = %i\0A\00"
@errno = global i32 0
@ENOSYS = global i32 0
@.str.8 = [53 x i8] c"User unable to remove extended attributes file %s !\0A\00"
@str = [38 x i8] c"Please enter a file name as argument.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %45
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %45
18: ; preds = %10
%19 = call i32 @flistxattr(i32 %14, i8* %6, i32 1024)
switch i32 %19, label %24 [
i32 -1, label %20
i32 0, label %22
]
20: ; preds = %18
%21 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %45
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %45
24: ; preds = %18
%25 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @fgetxattr(i32 %14, i8* %25, i8* %5, i32 1024)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %45
30: ; preds = %24
%31 = call i32 @fsetxattr(i32 %14, i8* %25, i8* %5, i32 %26, i32 0)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i8*, i8** %11
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @errno
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %33, %30
%39 = load i32, i32* @ENOSYS
store i32 %39, i32* @errno
%40 = load i8*, i8** %11
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @errno
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%44 = call i32 @close(i32 %14)
br label %45
45: ; preds = %38, %28, %22, %20, %16, %8
%46 = phi i32 [ -1, %8 ], [ -1, %16 ], [ 1, %20 ], [ 1, %22 ], [ 1, %28 ], [ 1, %38 ]
ret i32 %46
}