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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ pthread_self();
scalar_t__ pthread_setaffinity_np(int /*<<< orphan*/, int, unsigned long *);
double waste_time(int);
void *thread_func(void *param) {
  unsigned long mask = 1;
  if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) {
    perror("pthread_setaffinity_np");
  }
  printf("result: %f\n", waste_time(2000));
  mask = 2;
  if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) {
    perror("pthread_setaffinity_np");
  }
  printf("result: %f\n", waste_time(2000));
}


x86 assembly (clang, -O0):
<thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    $0x8,%esi
lea    -0x18(%rbp),%rdx
call   1030 <pthread_setaffinity_np@plt>
cmp    $0x0,%rax
jge    1191 <thread_func+0x41>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    $0x7d0,%edi
call   1050 <waste_time@plt>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
movq   $0x2,-0x18(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    $0x8,%esi
lea    -0x18(%rbp),%rdx
call   1030 <pthread_setaffinity_np@plt>
cmp    $0x0,%rax
jge    11dc <thread_func+0x8c>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
mov    $0x7d0,%edi
call   1050 <waste_time@plt>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_func>:
push   %rax
movq   $0x1,(%rsp)
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rsp,%rdx
mov    %eax,%edi
mov    $0x8,%esi
call   1030 <pthread_setaffinity_np@plt>
test   %rax,%rax
js     11c5 <thread_func+0x75>
mov    $0x7d0,%edi
call   1050 <waste_time@plt>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movq   $0x2,(%rsp)
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rsp,%rdx
mov    %eax,%edi
mov    $0x8,%esi
call   1030 <pthread_setaffinity_np@plt>
test   %rax,%rax
js     11d3 <thread_func+0x83>
mov    $0x7d0,%edi
call   1050 <waste_time@plt>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
pop    %rcx
ret
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
jmp    1174 <thread_func+0x24>
lea    0xe26(%rip),%rdi
call   1070 <perror@plt>
jmp    11ad <thread_func+0x5d>

LLVM IR (-O0):
@.str = [23 x i8] c"pthread_setaffinity_np\00"
@.str.1 = [12 x i8] c"result: %f\0A\00"
define i8* @thread_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 1, i64* %4
%5 = call i32 (...) @pthread_self()
%6 = call i64 @pthread_setaffinity_np(i32 %5, i32 8, i64* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = call double @waste_time(i32 2000)
%12 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %11)
store i64 2, i64* %4
%13 = call i32 (...) @pthread_self()
%14 = call i64 @pthread_setaffinity_np(i32 %13, i32 8, i64* %4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = call double @waste_time(i32 2000)
%20 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %19)
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@.str = [23 x i8] c"pthread_setaffinity_np\00"
@.str.1 = [12 x i8] c"result: %f\0A\00"
define noalias i8* @thread_func(i8* nocapture readnone %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 1, i64* %2
%4 = tail call i32 (...) @pthread_self()
%5 = call i64 @pthread_setaffinity_np(i32 %4, i32 8, i64* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call double @waste_time(i32 2000)
%11 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %10)
store i64 2, i64* %2
%12 = call i32 (...) @pthread_self()
%13 = call i64 @pthread_setaffinity_np(i32 %12, i32 8, i64* %2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = call double @waste_time(i32 2000)
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %18)
ret i8* undef
}