#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 /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
char *strtok(char *, char const *);
int /*<<< orphan*/ usage();
void do_pin(int argc, char *argv[]) {
  if (argc < 2)
    usage();
  cpu_set_t mask;
  CPU_ZERO(&mask);
  const char *sep = ",";
  char *target = strtok(argv[0], sep);
  while (target) {
    CPU_SET(atoi(target), &mask);
    target = strtok(NULL, sep);
  }
  if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) < 0)
    err(1, "setaffinity");
  execvp(argv[1], &argv[1]);
  err(1, "execvp failed!");
}


x86 assembly (clang, -O0):
<do_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    11a0 <do_pin+0x20>
mov    $0x0,%al
call   1050 <usage@plt>
lea    -0x14(%rbp),%rdi
call   1060 <CPU_ZERO@plt>
lea    0xe50(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11fd <do_pin+0x7d>
mov    -0x28(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
call   10a0 <CPU_SET@plt>
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11c8 <do_pin+0x48>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1030 <sched_setaffinity@plt>
cmp    $0x0,%rax
jge    1228 <do_pin+0xa8>
mov    $0x1,%edi
lea    0xddf(%rip),%rsi
call   1040 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1080 <execvp@plt>
mov    $0x1,%edi
lea    0xdc5(%rip),%rsi
call   1040 <err@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_pin>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     1198 <do_pin+0x18>
xor    %eax,%eax
call   1050 <usage@plt>
lea    0xc(%rsp),%rdi
call   1060 <CPU_ZERO@plt>
mov    (%r14),%rdi
lea    0xe54(%rip),%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11f1 <do_pin+0x71>
lea    0xc(%rsp),%r15
lea    0xe3e(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   10a0 <CPU_SET@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    11d0 <do_pin+0x50>
lea    0xc(%rsp),%rdx
xor    %edi,%edi
mov    $0x4,%esi
call   1030 <sched_setaffinity@plt>
test   %rax,%rax
jns    1218 <do_pin+0x98>
lea    0xdf4(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    0x8(%r14),%rdi
add    $0x8,%r14
mov    %r14,%rsi
call   1080 <execvp@plt>
lea    0xddf(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [12 x i8] c"setaffinity\00"
@.str.2 = [15 x i8] c"execvp failed!\00"
define void @do_pin(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @usage()
br label %12
12: ; preds = %10, %2
%13 = call i32 @CPU_ZERO(i32* %5)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i8*, i8** %6
%18 = call i8* @strtok(i8* %16, i8* %17)
store i8* %18, i8** %7
br label %19
19: ; preds = %22, %12
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = call i32 @atoi(i8* %23)
%25 = call i32 @CPU_SET(i32 %24, i32* %5)
%26 = load i8*, i8** %6
%27 = call i8* @strtok(i8* null, i8* %26)
store i8* %27, i8** %7
br label %19
28: ; preds = %19
%29 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %5)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = call i32 @execvp(i8* %36, i8** %38)
%40 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [12 x i8] c"setaffinity\00"
@.str.2 = [15 x i8] c"execvp failed!\00"
define void @do_pin(i32 %0, i8** %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @usage()
br label %7
7: ; preds = %5, %2
%8 = bitcast i32* %3 to i8*
%9 = call i32 @CPU_ZERO(i32* %3)
%10 = load i8*, i8** %1
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %7, %13
%14 = phi i8* [ %17, %13 ], [ %11, %7 ]
%15 = call i32 @atoi(i8* %14)
%16 = call i32 @CPU_SET(i32 %15, i32* %3)
%17 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %13
19: ; preds = %13, %7
%20 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %3)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @execvp(i8* %26, i8** %25)
%28 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
ret void
}