#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*/ dis_issbuf(char *);
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.kse", buf, size);
  if (ret == -1) {
    perror("getxattr: ");
  } else
    printf("xattr %s\n", buf);
  dis_issbuf(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     119f <main+0x2f>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11b7 <main+0x47>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movl   $0x100,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e1 <main+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <main+0xd9>
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
lea    0xe0b(%rip),%rsi
call   1080 <getxattr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1228 <main+0xb8>
lea    0xdff(%rip),%rdi
call   1070 <perror@plt>
jmp    123a <main+0xca>
mov    -0x18(%rbp),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <dis_issbuf@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   %rbx
push   %rax
cmp    $0x2,%edi
jl     120d <main+0x8d>
mov    %rsi,%rbp
cmpq   $0x0,0x8(%rsi)
je     120d <main+0x8d>
mov    $0x100,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11f1 <main+0x71>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    0x8(%rbp),%rdi
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdx
mov    $0x100,%ecx
call   1090 <getxattr@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11ff <main+0x7f>
lea    0xe3b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <dis_issbuf@plt>
jmp    11f6 <main+0x76>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe07(%rip),%rdi
call   1080 <perror@plt>
jmp    11e7 <main+0x67>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"one arg needed\0A\00"
@.str.1 = [13 x i8] c"security.kse\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 %46
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 = call i32 @getxattr(i8* %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %42
39: ; preds = %25
%40 = load i8*, i8** %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %37
%43 = load i8*, i8** %6
%44 = call i32 @dis_issbuf(i8* %43)
%45 = load i32, i32* %8
store i32 %45, i32* %3
br label %46
46: ; preds = %42, %24
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"security.kse\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 %25, 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 ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 256)
%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 = %21, %19
%24 = tail call i32 @dis_issbuf(i8* %12)
br label %25
25: ; preds = %11, %23
%26 = phi i32 [ %17, %23 ], [ -1, %11 ]
ret i32 %26
}