#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*/ value;
typedef int ssize_t;
typedef int /*<<< orphan*/ mask;
typedef int int64_t;
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*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, int);
int read(int, int *, int);
int /*<<< orphan*/ sched_setaffinity(int /*<<< orphan*/, int,
                                     int /*<<< orphan*/ *);
int start_counter();
int /*<<< orphan*/ timing_computation();
int main() {
  int64_t value = -1;
  cpu_set_t mask;
  CPU_ZERO(&mask);
  CPU_SET(0, &mask);
  assert(!sched_setaffinity(0, sizeof(mask), &mask));
  while (1) {
    int fd = start_counter();
    timing_computation();
    ssize_t nread = read(fd, &value, sizeof(value));
    assert(nread == sizeof(value));
    close(fd);
    printf("%lld\n", value);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   10a0 <CPU_ZERO@plt>
xor    %edi,%edi
lea    -0xc(%rbp),%rsi
call   10b0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0xc(%rbp),%rdx
call   1060 <sched_setaffinity@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    $0x0,%al
call   1030 <start_counter@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1090 <timing_computation@plt>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
mov    %al,-0x15(%rbp)
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%esi
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
jmp    11dc <main+0x4c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0x8(%rsp)
ff
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <CPU_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10b0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1060 <sched_setaffinity@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x8(%rsp),%r14
lea    0xe21(%rip),%rbx
nop
xor    %eax,%eax
call   1030 <start_counter@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <timing_computation@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
jmp    11e0 <main+0x50>

LLVM IR (-O0):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
%6 = call i32 @CPU_ZERO(i32* %3)
%7 = call i32 @CPU_SET(i32 0, i32* %3)
%8 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %3)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
br label %13
13: ; preds = %0, %13
%14 = call i32 (...) @start_counter()
store i32 %14, i32* %4
%15 = call i32 (...) @timing_computation()
%16 = load i32, i32* %4
%17 = call i32 @read(i32 %16, i32* %2, i32 4)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = icmp eq i64 %19, 4
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %2
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %13
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%4 = bitcast i32* %2 to i8*
%5 = call i32 @CPU_ZERO(i32* %2)
%6 = call i32 @CPU_SET(i32 0, i32* %2)
%7 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %2)
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
br label %11
11: ; preds = %11, %0
%12 = call i32 (...) @start_counter()
%13 = call i32 (...) @timing_computation()
%14 = call i32 @read(i32 %12, i32* %1, i32 4)
%15 = icmp eq i32 %14, 4
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i32 @close(i32 %12)
%19 = load i32, i32* %1
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %11
}