#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 */
struct stat {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int getxattr(char *, char *, char *, int);
int lstat(char *, struct stat *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
char *strerror(int /*<<< orphan*/);
void kse_setcon(char *name) {
  char *buf;
  ssize_t size;
  int ret;
  struct stat stat_buf;
  if (name == NULL) {
    perror("name ");
    exit(-1);
  }
  ret = lstat(name, &stat_buf);
  if (ret == -1) {
    printf("%s lstat error: %s\n", name, strerror(errno));
    return;
  }
  size = 255;
  buf = malloc(size);
  if (buf == NULL) {
    perror("malloc ");
    exit(-1);
  }
  memset(buf, 0, size);
  ret = getxattr(name, "security.kse", buf, 255);
  if (ret < 0) {
  }
  printf("%s : %s\n", name, buf);
  free(buf);
}


x86 assembly (clang, -O0):
<kse_setcon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11bd <kse_setcon+0x2d>
lea    0xe52(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <lstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1205 <kse_setcon+0x75>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
jmp    128f <kse_setcon+0xff>
movl   $0xff,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1239 <kse_setcon+0xa9>
lea    0xdf0(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdcc(%rip),%rsi
mov    $0xff,%ecx
call   1090 <getxattr@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1272 <kse_setcon+0xe2>
jmp    1272 <kse_setcon+0xe2>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kse_setcon>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     122d <kse_setcon+0x9d>
mov    %rdi,%r14
mov    %rsp,%rsi
call   1060 <lstat@plt>
cmp    $0xffffffff,%eax
je     1206 <kse_setcon+0x76>
mov    $0xff,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1236 <kse_setcon+0xa6>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <memset@plt>
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   1090 <getxattr@plt>
lea    0xe43(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdeb(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
lea    0xdcc(%rip),%rdi
jmp    123d <kse_setcon+0xad>
lea    0xddd(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"name \00"
@.str.1 = [20 x i8] c"%s lstat error: %s\0A\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"malloc \00"
@.str.3 = [13 x i8] c"security.kse\00"
@.str.4 = [9 x i8] c"%s : %s\0A\00"
define void @kse_setcon(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %1
%9 = call i32 @lstat(i8* %0, %struct.stat* %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %13)
br label %26
15: ; preds = %8
%16 = tail call dereferenceable_or_null(255) i8* @malloc(i32 255)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %15
%22 = tail call i32 @memset(i8* %16, i32 0, i32 255)
%23 = tail call i32 @getxattr(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %16, i32 255)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %16)
%25 = tail call i32 @free(i8* %16)
br label %26
26: ; preds = %21, %11
ret void
}