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

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ pthread_self();
scalar_t__ pthread_setaffinity_np(int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void thread_bind(int cpu) {
  cpu_set_t cpu_set;
  CPU_ZERO(&cpu_set);
  CPU_SET(cpu, &cpu_set);
  if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpu_set) !=
      0) {
    fprintf(stderr, "Error: cpu[%d] bind failed.\n", cpu);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<thread_bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <CPU_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1080 <CPU_SET@plt>
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1030 <pthread_setaffinity_np@plt>
cmp    $0x0,%rax
je     11c0 <thread_bind+0x60>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe4c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_bind>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <CPU_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <CPU_SET@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1030 <pthread_setaffinity_np@plt>
test   %rax,%rax
jne    119e <thread_bind+0x3e>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Error: cpu[%d] bind failed.\0A\00"
define void @thread_bind(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @CPU_ZERO(i32* %3)
%5 = load i32, i32* %2
%6 = call i32 @CPU_SET(i32 %5, i32* %3)
%7 = call i32 (...) @pthread_self()
%8 = call i64 @pthread_setaffinity_np(i32 %7, i32 4, i32* %3)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %1
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Error: cpu[%d] bind failed.\0A\00"
define void @thread_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 i32 (...) @pthread_self()
%7 = call i64 @pthread_setaffinity_np(i32 %6, i32 4, i32* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0)
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %1
ret void
}