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

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/, int);
int pthread_setaffinity_np(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int asyncos_pin(pthread_t thread, int cpu) {
  int ret;
  cpu_set_t cpuset;
  CPU_ZERO(&cpuset);
  CPU_SET(cpu, &cpuset);
  ret = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
  if (ret)
    errno = ret;
  fprintf(stderr, "asyncos_pin: thread %ld pinning returns %d.\n", thread, ret);
  return ret;
}


x86 assembly (clang, -O0):
<asyncos_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <CPU_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <CPU_SET@plt>
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
lea    -0x10(%rbp),%rdx
call   1030 <pthread_setaffinity_np@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     118d <asyncos_pin+0x4d>
mov    -0xc(%rbp),%ecx
mov    0x2e4d(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asyncos_pin>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <CPU_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <CPU_SET@plt>
mov    %r14d,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1030 <pthread_setaffinity_np@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1183 <asyncos_pin+0x43>
mov    0x2e57(%rip),%rax
mov    %ebp,(%rax)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@stderr = global i32 0
@.str = [45 x i8] c"asyncos_pin: thread %ld pinning returns %d.\0A\00"
define i32 @asyncos_pin(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i32 @CPU_ZERO(i32* %6)
%8 = load i32, i32* %4
%9 = call i32 @CPU_SET(i32 %8, i32* %6)
%10 = load i32, i32* %3
%11 = call i32 @pthread_setaffinity_np(i32 %10, i32 4, i32* %6)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %5
store i32 %15, i32* @errno
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
@.str = [45 x i8] c"asyncos_pin: thread %ld pinning returns %d.\0A\00"
define i32 @asyncos_pin(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @CPU_ZERO(i32* %3)
%6 = call i32 @CPU_SET(i32 %1, i32* %3)
%7 = call i32 @pthread_setaffinity_np(i32 %0, i32 4, i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 %7, i32* @errno
br label %10
10: ; preds = %9, %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %7)
ret i32 %7
}