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

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void pin_process(pid_t pid, int cpu) {
  cpu_set_t cpu_set;
  CPU_ZERO(&cpu_set);
  CPU_SET(cpu, &cpu_set);
  do {
    if (!(sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set) != -1)) {
      fprintf(stderr, "%s:%i: %s\n  %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/andysan/perf_tools/refs/heads/master/"
              "perfrecord.c",
              274, "sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set) != -1",
              strerror(errno));
      abort();
    }
  } while (0);
}


x86 assembly (clang, -O0):
<pin_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <CPU_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1080 <CPU_SET@plt>
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
lea    -0xc(%rbp),%rdx
call   1040 <sched_setaffinity@plt>
cmp    $0xffffffff,%eax
jne    11e3 <pin_process+0x83>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%r9
lea    0xe3c(%rip),%rsi
lea    0xe45(%rip),%rdx
mov    $0x112,%ecx
lea    0xec5(%rip),%r8
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11e8 <pin_process+0x88>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pin_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1060 <CPU_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1080 <CPU_SET@plt>
mov    %ebp,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1040 <sched_setaffinity@plt>
cmp    $0xffffffff,%eax
je     11a0 <pin_process+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e39(%rip),%rax
mov    (%rax),%ebx
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe42(%rip),%rsi
lea    0xe4b(%rip),%rdx
lea    0xed0(%rip),%r8
mov    %ebx,%edi
mov    $0x112,%ecx
mov    %rax,%r9
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"%s:%i: %s\0A %s\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/andysan/perf_tools/refs/heads/master/perfrecord.c\00"
@.str.2 = [58 x i8] c"sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set) != -1\00"
@errno = global i32 0
define void @pin_process(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i32 @CPU_ZERO(i32* %5)
%7 = load i32, i32* %4
%8 = call i32 @CPU_SET(i32 %7, i32* %5)
br label %9
9: ; preds = %2
%10 = load i32, i32* %3
%11 = call i32 @sched_setaffinity(i32 %10, i32 4, i32* %5)
%12 = icmp ne i32 %11, -1
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 274, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %9
br label %20
20: ; preds = %19
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"%s:%i: %s\0A %s\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/andysan/perf_tools/refs/heads/master/perfrecord.c\00"
@.str.2 = [58 x i8] c"sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set) != -1\00"
@errno = global i32 0
define void @pin_process(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 @sched_setaffinity(i32 %0, i32 4, i32* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 274, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %2
ret void
}