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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
char *strdup(char *);
int smack_get_file(char **label, const char *name) {
  int fd, ret, i;
  char value[255 + 1];
  char path[PATH_MAX];
  snprintf(path, PATH_MAX, "%s%s", "/smack/", name);
  fd = open(path, O_RDONLY);
  if (fd == -1) {
    *label = NULL;
    return -1;
  }
  ret = read(fd, value, 255);
  close(fd);
  if (ret == -1) {
    *label = NULL;
    return -1;
  }
  value[ret] = '\0';
  for (i = ret - 1; i > 0; --i) {
    if (value[i] == ' ')
      value[i] = '\0';
    else
      break;
  }
  *label = strdup(value);
  return 0;
}


x86 assembly (clang, -O0):
<smack_get_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x138(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x150(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x140(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%r8
lea    0xe54(%rip),%rdx
lea    0xe52(%rip),%rcx
call   1030 <snprintf@plt>
mov    -0x150(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11fb <smack_get_file+0xab>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x144(%rbp)
jmp    12c9 <smack_get_file+0x179>
mov    -0x1c(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1245 <smack_get_file+0xf5>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x144(%rbp)
jmp    12c9 <smack_get_file+0x179>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    12a2 <smack_get_file+0x152>
movslq -0x24(%rbp),%rax
movsbl -0x130(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    128a <smack_get_file+0x13a>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
jmp    128f <smack_get_file+0x13f>
jmp    12a2 <smack_get_file+0x152>
jmp    1294 <smack_get_file+0x144>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    125a <smack_get_file+0x10a>
lea    -0x130(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x144(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_get_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r8
mov    %rdi,%r14
mov    %rsp,%r13
mov    0x2e7c(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%esi
lea    0xe70(%rip),%rdx
lea    0xe6e(%rip),%rcx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    $0xffffffff,%r15d
cmp    $0xffffffff,%eax
je     1230 <smack_get_file+0xe0>
mov    %eax,%ebx
lea    -0x130(%rbp),%rsi
mov    %eax,%edi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%r12d
je     1230 <smack_get_file+0xe0>
movslq %r12d,%rax
movb   $0x0,-0x130(%rbp,%rax,1)
cmp    $0x2,%r12d
jl     121f <smack_get_file+0xcf>
mov    %r12d,%eax
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rax),%ecx
cmpb   $0x20,-0x130(%rbp,%rcx,1)
20
jne    121f <smack_get_file+0xcf>
movb   $0x0,-0x130(%rbp,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
ja     1200 <smack_get_file+0xb0>
lea    -0x130(%rbp),%rdi
call   1070 <strdup@plt>
xor    %r15d,%r15d
jmp    1232 <smack_get_file+0xe2>
xor    %eax,%eax
mov    %rax,(%r14)
mov    %r13,%rsp
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [8 x i8] c"/smack/\00"
@O_RDONLY = global i32 0
define i32 @smack_get_file(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %10
%16 = alloca i8, i64 %14
store i64 %14, i64* %11
%17 = load i32, i32* @PATH_MAX
%18 = load i8*, i8** %5
%19 = call i32 @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %16, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = load i8**, i8*** %4
store i8* null, i8** %25
store i32 -1, i32* %3
store i32 1, i32* %12
br label %65
26: ; preds = %2
%27 = load i32, i32* %6
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 255)
store i32 %29, i32* %7
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = load i8**, i8*** %4
store i8* null, i8** %35
store i32 -1, i32* %3
store i32 1, i32* %12
br label %65
36: ; preds = %26
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* %7
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %8
br label %42
42: ; preds = %58, %36
%43 = load i32, i32* %8
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %61
45: ; preds = %42
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %54
store i8 0, i8* %55
br label %57
56: ; preds = %45
br label %61
57: ; preds = %52
br label %58
58: ; preds = %57
%59 = load i32, i32* %8
%60 = add nsw i32 %59, -1
store i32 %60, i32* %8
br label %42
61: ; preds = %56, %42
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%63 = call i8* @strdup(i8* %62)
%64 = load i8**, i8*** %4
store i8* %63, i8** %64
store i32 0, i32* %3
store i32 1, i32* %12
br label %65
65: ; preds = %61, %34, %24
%66 = load i8*, i8** %10
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [8 x i8] c"/smack/\00"
@O_RDONLY = global i32 0
define i32 @smack_get_file(i8** nocapture writeonly %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @PATH_MAX
%10 = call i32 @snprintf(i8* %8, i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %8, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %35, label %14
14: ; preds = %2
%15 = call i32 @read(i32 %12, i8* %4, i32 255)
%16 = call i32 @close(i32 %12)
%17 = icmp eq i32 %15, -1
br i1 %17, label %35, label %18
18: ; preds = %14
%19 = sext i32 %15 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
%21 = icmp sgt i32 %15, 1
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = zext i32 %15 to i64
br label %24
24: ; preds = %22, %31
%25 = phi i64 [ %23, %22 ], [ %26, %31 ]
%26 = add nsw i64 %25, -1
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 32
br i1 %30, label %31, label %33
31: ; preds = %24
store i8 0, i8* %28
%32 = icmp ugt i64 %25, 2
br i1 %32, label %24, label %33
33: ; preds = %31, %24, %18
%34 = call i8* @strdup(i8* %4)
br label %35
35: ; preds = %14, %2, %33
%36 = phi i8* [ %34, %33 ], [ null, %2 ], [ null, %14 ]
%37 = phi i32 [ 0, %33 ], [ -1, %2 ], [ -1, %14 ]
store i8* %36, i8** %0
ret i32 %37
}