#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_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int write(int, char const *, int /*<<< orphan*/);
int smack_set_ambient(const char *label) {
  int fd, ret;
  fd = open("/smack/"
            "ambient",
            O_WRONLY);
  if (fd == -1)
    return -1;
  ret = write(fd, label, strlen(label));
  close(fd);
  if (ret == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<smack_set_ambient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117a <smack_set_ambient+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <smack_set_ambient+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c0 <smack_set_ambient+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <smack_set_ambient+0x87>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_set_ambient>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     118b <smack_set_ambient+0x4b>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebx
sete   %al
neg    %eax
jmp    1190 <smack_set_ambient+0x50>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/smack/ambient\00"
@O_WRONLY = global i32 0
define i32 @smack_set_ambient(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %23
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write(i32 %12, i8* %13, i32 %15)
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 %22
21: ; preds = %11
store i32 -1, i32* %2
br label %23
22: ; preds = %11
store i32 0, i32* %2
br label %23
23: ; preds = %22, %21, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [15 x i8] c"/smack/ambient\00"
@O_WRONLY = global i32 0
define i32 @smack_set_ambient(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @write(i32 %3, i8* %0, i32 %6)
%8 = tail call i32 @close(i32 %3)
%9 = icmp eq i32 %7, -1
%10 = sext i1 %9 to i32
br label %11
11: ; preds = %5, %1
%12 = phi i32 [ -1, %1 ], [ %10, %5 ]
ret i32 %12
}