#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*/ cs;
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ debug_print(int /*<<< orphan*/ *, int, char *, int);
scalar_t__ sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int processor_bind(int cpu) {
  cpu_set_t cs;
  CPU_ZERO(&cs);
  CPU_SET(cpu, &cs);
  if (sched_setaffinity(0, sizeof(cs), &cs) < 0) {
    debug_print(NULL, 2, "Fail to bind to CPU%d\n", cpu);
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<processor_bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <CPU_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1060 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0xc(%rbp),%rdx
call   1030 <sched_setaffinity@plt>
cmp    $0x0,%rax
jge    119e <processor_bind+0x5e>
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2,%esi
lea    0xe73(%rip),%rdx
call   1050 <debug_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <processor_bind+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processor_bind>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <CPU_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1060 <CPU_SET@plt>
xor    %ebp,%ebp
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1030 <sched_setaffinity@plt>
test   %rax,%rax
jns    1194 <processor_bind+0x54>
lea    0xe80(%rip),%rdx
xor    %edi,%edi
mov    $0x2,%esi
mov    %r14d,%ecx
call   1050 <debug_print@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Fail to bind to CPU%d\0A\00"
define i32 @processor_bind(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = call i32 @CPU_ZERO(i32* %4)
%6 = load i32, i32* %3
%7 = call i32 @CPU_SET(i32 %6, i32* %4)
%8 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i32 @debug_print(i32* null, i32 2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 -1, i32* %2
br label %14
13: ; preds = %1
store i32 0, i32* %2
br label %14
14: ; preds = %13, %10
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
@.str = [23 x i8] c"Fail to bind to CPU%d\0A\00"
define i32 @processor_bind(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @CPU_ZERO(i32* %2)
%5 = call i32 @CPU_SET(i32 %0, i32* %2)
%6 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @debug_print(i32* null, i32 2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %10
10: ; preds = %1, %8
%11 = phi i32 [ -1, %8 ], [ 0, %1 ]
ret i32 %11
}