#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*/ node_str;

/* Variables and functions */
int numa_available();
int /*<<< orphan*/ numa_bind(int /*<<< orphan*/);
int numa_node_of_cpu(int);
int /*<<< orphan*/ numa_parse_nodestring(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int bind2node(int core_id) {
  char node_str[8];
  if (core_id < 0 || numa_available() == -1)
    return -1;
  snprintf(node_str, sizeof(node_str), "%u", numa_node_of_cpu(core_id));
  numa_bind(numa_parse_nodestring(node_str));
  return 0;
}


x86 assembly (clang, -O0):
<bind2node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1175 <bind2node+0x25>
mov    $0x0,%al
call   1070 <numa_available@plt>
cmp    $0xffffffff,%eax
jne    1181 <bind2node+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <bind2node+0x6f>
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <numa_node_of_cpu@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%ecx
mov    $0x8,%esi
lea    0xe5d(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x10(%rbp),%rdi
call   1060 <numa_parse_nodestring@plt>
mov    %eax,%edi
call   1050 <numa_bind@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind2node>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
test   %edi,%edi
js     119b <bind2node+0x4b>
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <numa_available@plt>
cmp    $0xffffffff,%eax
je     119b <bind2node+0x4b>
mov    %ebp,%edi
call   1030 <numa_node_of_cpu@plt>
lea    0xe88(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <numa_parse_nodestring@plt>
mov    %eax,%edi
call   1050 <numa_bind@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
define i32 @bind2node(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [8 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i32 (...) @numa_available()
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %7, %1
store i32 -1, i32* %2
br label %19
11: ; preds = %7
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 @numa_node_of_cpu(i32 %13)
%15 = call i32 @snprintf(i8* %12, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%17 = call i32 @numa_parse_nodestring(i8* %16)
%18 = call i32 @numa_bind(i32 %17)
store i32 0, i32* %2
br label %19
19: ; preds = %11, %10
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
define i32 @bind2node(i32 %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = tail call i32 (...) @numa_available()
%7 = icmp eq i32 %6, -1
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @numa_node_of_cpu(i32 %0)
%10 = call i32 @snprintf(i8* %3, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @numa_parse_nodestring(i8* %3)
%12 = call i32 @numa_bind(i32 %11)
br label %13
13: ; preds = %1, %5, %8
%14 = phi i32 [ 0, %8 ], [ -1, %5 ], [ -1, %1 ]
ret i32 %14
}