#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 /*<<< orphan*/ exit(int);
int getxattr(char *, char *, char *, int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char *buf;
  ssize_t size;
  ssize_t ret;
  if (argc < 2 || argv[1] == NULL) {
    printf("one arg needed\n");
    exit(-1);
  }
  size = 256;
  buf = malloc(size);
  if (!buf)
    return -1;
  memset(buf, 0, size);
  ret = getxattr(argv[1], "security.selinux", buf, size - 1);
  if (ret == -1) {
    perror("getxattr: ");
  } else
    printf("xattr %s\n", buf);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     118f <main+0x2f>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11a7 <main+0x47>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
movl   $0x100,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <main+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <main+0xd3>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
lea    0xe18(%rip),%rsi
call   1070 <getxattr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    121b <main+0xbb>
lea    0xe10(%rip),%rdi
call   1060 <perror@plt>
jmp    122d <main+0xcd>
mov    -0x18(%rbp),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jl     11f3 <main+0x83>
mov    %rsi,%rbp
cmpq   $0x0,0x8(%rsi)
je     11f3 <main+0x83>
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11dd <main+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   1080 <getxattr@plt>
cmp    $0xffffffff,%eax
je     11e5 <main+0x75>
mov    %eax,%ebp
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe25(%rip),%rdi
call   1070 <perror@plt>
jmp    11dd <main+0x6d>
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"one arg needed\0A\00"
@.str.1 = [17 x i8] c"security.selinux\00"
@.str.2 = [11 x i8] c"getxattr: \00"
@.str.3 = [10 x i8] c"xattr %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11, %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %11
store i32 256, i32* %7
%20 = load i32, i32* %7
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 -1, i32* %3
br label %45
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = call i32 @memset(i8* %26, i32 0, i32 %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = sub nsw i32 %33, 1
%35 = call i32 @getxattr(i8* %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %34)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %25
%39 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %43
40: ; preds = %25
%41 = load i8*, i8** %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %38
%44 = load i32, i32* %8
store i32 %44, i32* %3
br label %45
45: ; preds = %43, %24
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"security.selinux\00"
@.str.2 = [11 x i8] c"getxattr: \00"
@.str.3 = [10 x i8] c"xattr %s\0A\00"
@str = [15 x i8] c"one arg needed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %4, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %4
%12 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%13 = icmp eq i8* %12, null
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = tail call i32 @memset(i8* %12, i32 0, i32 256)
%16 = load i8*, i8** %5
%17 = tail call i32 @getxattr(i8* %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 255)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %23
21: ; preds = %14
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %23
23: ; preds = %19, %21, %11
%24 = phi i32 [ -1, %11 ], [ %17, %21 ], [ -1, %19 ]
ret i32 %24
}