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

/* Variables and functions */
int get_pid_stat_val(char *, int, int, char *);
scalar_t__ is_str_conversion_ok(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
unsigned int strtoul(char *, char **, int);
int uinttostr_noalloc(char *, int, int /*<<< orphan*/ const);
int get_pid_core_num(const pid_t pid, unsigned *core) {
  char core_s[64];
  char pid_s[64];
  char *tmp;
  int ret;
  if (core == NULL || pid < 0)
    return -1;
  memset(core_s, 0, sizeof(core_s));
  ret = uinttostr_noalloc(pid_s, sizeof(pid_s), pid);
  if (ret < 0)
    return -1;
  ret = get_pid_stat_val(pid_s, (39), sizeof(core_s), core_s);
  if (ret != 0)
    return -1;
  *core = strtoul(core_s, &tmp, 10);
  if (is_str_conversion_ok(tmp) == 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<get_pid_core_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1177 <get_pid_core_num+0x27>
cmpl   $0x0,-0x8(%rbp)
jge    1183 <get_pid_core_num+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <get_pid_core_num+0xf5>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x40,%esi
call   1070 <uinttostr_noalloc@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
jge    11c6 <get_pid_core_num+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <get_pid_core_num+0xf5>
lea    -0x90(%rbp),%rdi
lea    -0x50(%rbp),%rcx
mov    $0x27,%esi
mov    $0x40,%edx
call   1030 <get_pid_stat_val@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     11ff <get_pid_core_num+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <get_pid_core_num+0xf5>
lea    -0x50(%rbp),%rdi
lea    -0x98(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x98(%rbp),%rdi
call   1050 <is_str_conversion_ok@plt>
cmp    $0x0,%rax
jne    123e <get_pid_core_num+0xee>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <get_pid_core_num+0xf5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pid_core_num>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    $0xffffffff,%ebp
test   %edi,%edi
js     11d8 <get_pid_core_num+0x88>
mov    %rsi,%r14
test   %rsi,%rsi
je     11d8 <get_pid_core_num+0x88>
mov    %edi,%ebx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    0x50(%rsp),%rdi
mov    $0x40,%esi
mov    %ebx,%edx
call   1070 <uinttostr_noalloc@plt>
test   %eax,%eax
js     11d8 <get_pid_core_num+0x88>
lea    0x50(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x27,%esi
mov    $0x40,%edx
call   1030 <get_pid_stat_val@plt>
test   %eax,%eax
jne    11d8 <get_pid_core_num+0x88>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rdi
call   1050 <is_str_conversion_ok@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_pid_core_num(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [64 x i8]
%7 = alloca [64 x i8]
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12, %2
store i32 -1, i32* %3
br label %41
16: ; preds = %12
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 64)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* %4
%21 = call i32 @uinttostr_noalloc(i8* %19, i32 64, i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 -1, i32* %3
br label %41
25: ; preds = %16
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%28 = call i32 @get_pid_stat_val(i8* %26, i32 39, i32 64, i8* %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 -1, i32* %3
br label %41
32: ; preds = %25
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%34 = call i32 @strtoul(i8* %33, i8** %8, i32 10)
%35 = load i32*, i32** %5
store i32 %34, i32* %35
%36 = load i8*, i8** %8
%37 = call i64 @is_str_conversion_ok(i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 -1, i32* %3
br label %41
40: ; preds = %32
store i32 0, i32* %3
br label %41
41: ; preds = %40, %39, %31, %24, %15
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @get_pid_core_num(i32 %0, i32* writeonly %1) {
%3 = alloca [64 x i8]
%4 = alloca [64 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
%9 = icmp eq i32* %1, null
%10 = icmp slt i32 %0, 0
%11 = or i1 %10, %9
br i1 %11, label %25, label %12
12: ; preds = %2
%13 = call i32 @memset(i8* %6, i32 0, i32 64)
%14 = call i32 @uinttostr_noalloc(i8* %7, i32 64, i32 %0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = call i32 @get_pid_stat_val(i8* %7, i32 39, i32 64, i8* %6)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = call i32 @strtoul(i8* %6, i8** %5, i32 10)
store i32 %20, i32* %1
%21 = load i8*, i8** %5
%22 = call i64 @is_str_conversion_ok(i8* %21)
%23 = icmp eq i64 %22, 0
%24 = sext i1 %23 to i32
br label %25
25: ; preds = %19, %16, %12, %2
%26 = phi i32 [ -1, %2 ], [ -1, %12 ], [ -1, %16 ], [ %24, %19 ]
ret i32 %26
}