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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int pin_to_cpu(int);
int /*<<< orphan*/ print_cpu_mask();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int switch_cpu(int cpu, int verbose) {
  int new_cpu;
  if (cpu < 0)
    return 0;
  if (verbose) {
    printf("Default possible CPUs:\n");
    print_cpu_mask();
    printf("Running on CPU %d, want to run on CPU %d...\n", ({
             int val = 0;
             val;
           }),
           cpu);
  }
  new_cpu = pin_to_cpu(cpu);
  if (new_cpu != cpu) {
    fprintf(stderr,
            "err: desired CPU %d does not match current "
            "CPU %d\n",
            cpu, new_cpu);
    return -1;
  }
  if (verbose) {
    printf("New possible CPUs:\n");
    print_cpu_mask();
    printf("Running on CPU %d\n", new_cpu);
  }
  return 0;
}


x86 assembly (clang, -O0):
<switch_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1164 <switch_cpu+0x24>
movl   $0x0,-0x4(%rbp)
jmp    1219 <switch_cpu+0xd9>
cmpl   $0x0,-0xc(%rbp)
je     11a4 <switch_cpu+0x64>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <print_cpu_mask@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <pin_to_cpu@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11e2 <switch_cpu+0xa2>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe74(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <switch_cpu+0xd9>
cmpl   $0x0,-0xc(%rbp)
je     1212 <switch_cpu+0xd2>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <print_cpu_mask@plt>
mov    -0x10(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<switch_cpu>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %edi,%edi
js     11e3 <switch_cpu+0x93>
mov    %edi,%ebx
test   %esi,%esi
je     11ba <switch_cpu+0x6a>
lea    0xf1c(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <print_cpu_mask@plt>
lea    0xe81(%rip),%rdi
xor    %esi,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1030 <pin_to_cpu@plt>
cmp    %ebx,%eax
jne    11c5 <switch_cpu+0x75>
lea    0xed7(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <print_cpu_mask@plt>
lea    0xeb1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11e3 <switch_cpu+0x93>
mov    %ebx,%edi
call   1030 <pin_to_cpu@plt>
cmp    %ebx,%eax
je     11e3 <switch_cpu+0x93>
mov    0x2e14(%rip),%rcx
mov    (%rcx),%edi
lea    0xe58(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ecx
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Default possible CPUs:\0A\00"
@.str.1 = [45 x i8] c"Running on CPU %d, want to run on CPU %d...\0A\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"err: desired CPU %d does not match current CPU %d\0A\00"
@.str.3 = [20 x i8] c"New possible CPUs:\0A\00"
@.str.4 = [19 x i8] c"Running on CPU %d\0A\00"
define i32 @switch_cpu(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %42
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (...) @print_cpu_mask()
store i32 0, i32* %7
%18 = load i32, i32* %7
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20)
br label %22
22: ; preds = %15, %12
%23 = load i32, i32* %4
%24 = call i32 @pin_to_cpu(i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i32, i32* %4
%31 = load i32, i32* %6
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31)
store i32 -1, i32* %3
br label %42
33: ; preds = %22
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (...) @print_cpu_mask()
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %36, %33
store i32 0, i32* %3
br label %42
42: ; preds = %41, %28, %11
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str.1 = [45 x i8] c"Running on CPU %d, want to run on CPU %d...\0A\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"err: desired CPU %d does not match current CPU %d\0A\00"
@.str.4 = [19 x i8] c"Running on CPU %d\0A\00"
@str = [19 x i8] c"New possible CPUs:\00"
@str.5 = [23 x i8] c"Default possible CPUs:\00"
define i32 @switch_cpu(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 0
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = tail call i32 @pin_to_cpu(i32 %0)
%8 = icmp eq i32 %7, %0
br i1 %8, label %23, label %15
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
%11 = tail call i32 (...) @print_cpu_mask()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %0)
%13 = tail call i32 @pin_to_cpu(i32 %0)
%14 = icmp eq i32 %13, %0
br i1 %14, label %19, label %15
15: ; preds = %9, %6
%16 = phi i32 [ %13, %9 ], [ %7, %6 ]
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %16)
br label %23
19: ; preds = %9
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 (...) @print_cpu_mask()
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %23
23: ; preds = %6, %19, %2, %15
%24 = phi i32 [ -1, %15 ], [ 0, %2 ], [ 0, %19 ], [ 0, %6 ]
ret i32 %24
}