#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 /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
char *strdup(char *);
int smack_get_ambient(char **label) {
  int fd, ret;
  char value[255 + 1];
  fd = open("/smack/"
            "ambient",
            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';
  *label = strdup(value);
  return 0;
}


x86 assembly (clang, -O0):
<smack_get_ambient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1188 <smack_get_ambient+0x48>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <smack_get_ambient+0xb1>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c8 <smack_get_ambient+0x88>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <smack_get_ambient+0xb1>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_get_ambient>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1050 <open@plt>
mov    $0xffffffff,%r15d
cmp    $0xffffffff,%eax
je     11a5 <smack_get_ambient+0x65>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xff,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebp
je     11a7 <smack_get_ambient+0x67>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1060 <strdup@plt>
xor    %r15d,%r15d
jmp    11a7 <smack_get_ambient+0x67>
xor    %eax,%eax
mov    %rax,(%r14)
mov    %r15d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/smack/ambient\00"
@O_RDONLY = global i32 0
define i32 @smack_get_ambient(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
store i8** %0, i8*** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i8**, i8*** %3
store i8* null, i8** %12
store i32 -1, i32* %2
br label %30
13: ; preds = %1
%14 = load i32, i32* %4
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 255)
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = load i8**, i8*** %3
store i8* null, i8** %22
store i32 -1, i32* %2
br label %30
23: ; preds = %13
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = call i8* @strdup(i8* %27)
%29 = load i8**, i8*** %3
store i8* %28, i8** %29
store i32 0, i32* %2
br label %30
30: ; preds = %23, %21, %11
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [15 x i8] c"/smack/ambient\00"
@O_RDONLY = global i32 0
define i32 @smack_get_ambient(i8** nocapture writeonly %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = call i32 @read(i32 %5, i8* %3, i32 255)
%9 = tail call i32 @close(i32 %5)
%10 = icmp eq i32 %8, -1
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i8* @strdup(i8* %3)
br label %15
15: ; preds = %7, %1, %11
%16 = phi i8* [ %14, %11 ], [ null, %1 ], [ null, %7 ]
%17 = phi i32 [ 0, %11 ], [ -1, %1 ], [ -1, %7 ]
store i8* %16, i8** %0
ret i32 %17
}