#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, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
unsigned long gettime();
int sched_getcpu();
int /*<<< orphan*/ sched_setaffinity(int /*<<< orphan*/, int,
                                     int /*<<< orphan*/ *);
void *work(void *arg) {
  cpu_set_t *mask = (cpu_set_t *)arg;
  unsigned long start = gettime();
  int core;
  sched_setaffinity(0, sizeof(*mask), mask);
  CPU_ZERO(mask);
  while (gettime() < start + (10 * (1000000000ul))) {
    core = sched_getcpu();
    CPU_SET(core, mask);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <gettime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
mov    $0x4,%esi
call   1030 <sched_setaffinity@plt>
mov    -0x10(%rbp),%rdi
call   1040 <CPU_ZERO@plt>
mov    $0x0,%al
call   1070 <gettime@plt>
movabs $0x2540be400,%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jae    11c1 <work+0x71>
mov    $0x0,%al
call   1050 <sched_getcpu@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <CPU_SET@plt>
jmp    1188 <work+0x38>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %eax,%eax
call   1070 <gettime@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    $0x4,%esi
mov    %r15,%rdx
call   1030 <sched_setaffinity@plt>
mov    %r15,%rdi
call   1040 <CPU_ZERO@plt>
xor    %eax,%eax
call   1070 <gettime@plt>
movabs $0x2540be400,%rbx
add    %r14,%rbx
cmp    %rbx,%rax
jae    11bd <work+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <sched_getcpu@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1060 <CPU_SET@plt>
xor    %eax,%eax
call   1070 <gettime@plt>
cmp    %rbx,%rax
jb     11a0 <work+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @work(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %3
%8 = call i64 (...) @gettime()
store i64 %8, i64* %4
%9 = load i32*, i32** %3
%10 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %9)
%11 = load i32*, i32** %3
%12 = call i32 @CPU_ZERO(i32* %11)
br label %13
13: ; preds = %18, %1
%14 = call i64 (...) @gettime()
%15 = load i64, i64* %4
%16 = add i64 %15, 10000000000
%17 = icmp ult i64 %14, %16
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = call i32 (...) @sched_getcpu()
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i32*, i32** %3
%22 = call i32 @CPU_SET(i32 %20, i32* %21)
br label %13
23: ; preds = %13
ret i8* null
}

LLVM IR (-O2):
define noalias i8* @work(i8* %0) {
%2 = bitcast i8* %0 to i32*
%3 = tail call i64 (...) @gettime()
%4 = tail call i32 @sched_setaffinity(i32 0, i32 4, i32* %2)
%5 = tail call i32 @CPU_ZERO(i32* %2)
%6 = tail call i64 (...) @gettime()
%7 = add i64 %3, 10000000000
%8 = icmp ult i64 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %1, %9
%10 = tail call i32 (...) @sched_getcpu()
%11 = tail call i32 @CPU_SET(i32 %10, i32* %2)
%12 = tail call i64 (...) @gettime()
%13 = icmp ult i64 %12, %7
br i1 %13, label %9, label %14
14: ; preds = %9, %1
ret i8* null
}