#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 PATH_MAX;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
int /*<<< orphan*/ strlen(char const *);
int write(int, char const *, int /*<<< orphan*/);
int smack_set_file(const char *label, const char *name) {
  int fd, ret;
  char path[PATH_MAX];
  snprintf(path, PATH_MAX, "%s%s", "/smack/", name);
  fd = open(path, 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_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%r8
lea    0xe60(%rip),%rdx
lea    0xe5e(%rip),%rcx
call   1050 <snprintf@plt>
mov    -0x40(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11de <smack_set_file+0x8e>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1239 <smack_set_file+0xe9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
cmpl   $0xffffffff,-0x20(%rbp)
jne    122b <smack_set_file+0xdb>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1239 <smack_set_file+0xe9>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_set_file>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%r8
mov    %rdi,%r14
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe7f(%rip),%rdx
lea    0xe7d(%rip),%rcx
mov    %rbx,%rdi
call   1050 <snprintf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11d3 <smack_set_file+0x83>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
cmp    $0xffffffff,%r14d
sete   %al
neg    %eax
jmp    11d8 <smack_set_file+0x88>
mov    $0xffffffff,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
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_WRONLY = global i32 0
define i32 @smack_set_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i32, i32* @PATH_MAX
%16 = load i8*, i8** %5
%17 = call i32 @snprintf(i8* %14, i32 %15, 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* %16)
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* %14, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %10
br label %35
23: ; preds = %2
%24 = load i32, i32* %6
%25 = load i8*, i8** %4
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @write(i32 %24, i8* %25, i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %6
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %23
store i32 -1, i32* %3
store i32 1, i32* %10
br label %35
34: ; preds = %23
store i32 0, i32* %3
store i32 1, i32* %10
br label %35
35: ; preds = %34, %33, %22
%36 = load i8*, i8** %8
%37 = load i32, i32* %3
ret i32 %37
}

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_WRONLY = global i32 0
define i32 @smack_set_file(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @snprintf(i8* %5, i32 %3, 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)
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* %5, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = call i32 @strlen(i8* %0)
%12 = call i32 @write(i32 %8, i8* %0, i32 %11)
%13 = call i32 @close(i32 %8)
%14 = icmp eq i32 %12, -1
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %10, %2
%17 = phi i32 [ -1, %2 ], [ %15, %10 ]
ret i32 %17
}