#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 */
typedef int ssize_t;
typedef int pid_t;
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int smack_new_label_from_proc(char *, char **);
int snprintf(char *, int, char *, int);
ssize_t smack_new_label_from_process(pid_t pid, char **label) {
  char path[sizeof("/proc/%d/attr/current") + 20];
  int ret;
  ret = snprintf(path, sizeof(path), "/proc/%d/attr/current", pid);
  if (ret < 0 || ret >= (int)sizeof(path))
    return -1;
  return smack_new_label_from_proc(path, label);
}


x86 assembly (clang, -O0):
<smack_new_label_from_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x2a,%esi
lea    0xebe(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jl     115e <smack_new_label_from_process+0x3e>
cmpl   $0x2a,-0x44(%rbp)
jl     116a <smack_new_label_from_process+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    117a <smack_new_label_from_process+0x5a>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <smack_new_label_from_proc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_new_label_from_process>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %edi,%ecx
lea    0xecf(%rip),%rdx
mov    %rsp,%rdi
mov    $0x2a,%esi
call   1030 <snprintf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x29,%ecx
ja     1155 <smack_new_label_from_process+0x35>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1040 <smack_new_label_from_proc@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"/proc/%d/attr/current\00"
define i32 @smack_new_label_from_process(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [42 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [42 x i8], [42 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 @snprintf(i8* %8, i32 42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 42
br i1 %15, label %16, label %17
16: ; preds = %13, %2
store i32 -1, i32* %3
br label %21
17: ; preds = %13
%18 = getelementptr inbounds [42 x i8], [42 x i8]* %6, i64 0, i64 0
%19 = load i8**, i8*** %5
%20 = call i32 @smack_new_label_from_proc(i8* %18, i8** %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %17, %16
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [22 x i8] c"/proc/%d/attr/current\00"
define i32 @smack_new_label_from_process(i32 %0, i8** %1) {
%3 = alloca [42 x i8]
%4 = getelementptr inbounds [42 x i8], [42 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = icmp ugt i32 %5, 41
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @smack_new_label_from_proc(i8* %4, i8** %1)
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ %8, %7 ], [ -1, %2 ]
ret i32 %10
}