#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*/ pthread_attr_t;
typedef int /*<<< orphan*/ cpuset;
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int EPERM;
int errno;
int /*<<< orphan*/ printf(char *, char *, ...);
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setaffinity_np(int /*<<< orphan*/ *, int,
                                int /*<<< orphan*/ *);
int run_threads(int /*<<< orphan*/ *);
char *strerror(int);
int do_affinity_test(void) {
  pthread_attr_t attr;
  ({
    int ret = pthread_attr_init(&attr);
    if (ret != 0) {
      printf("%s:%d: %s returned %d (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/"
             "fbtl/tst-default-attr.c",
             183, "pthread_attr_init", ret, errno);
      return ret;
    }
  });
  cpu_set_t cpuset;
  CPU_ZERO(&cpuset);
  CPU_SET(0, &cpuset);
  ({
    int ret = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
    if (ret != 0) {
      printf("%s:%d: %s returned %d (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/"
             "fbtl/tst-default-attr.c",
             191, "pthread_attr_setaffinity_np", ret, errno);
      return ret;
    }
  });
  int ret = run_threads(&attr);
  if (ret == EPERM) {
    printf("Skipping CPU Affinity test: %s\n", strerror(ret));
    return 0;
  } else if (ret != 0)
    return ret;
  return 0;
}


x86 assembly (clang, -O0):
<do_affinity_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c8 <do_affinity_test+0x58>
mov    -0xc(%rbp),%r8d
mov    0x2e47(%rip),%rax
mov    (%rax),%r9d
lea    0xe5d(%rip),%rdi
lea    0xe7a(%rip),%rsi
mov    $0xb7,%edx
lea    0xf03(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1299 <do_affinity_test+0x129>
lea    -0x10(%rbp),%rdi
call   1070 <CPU_ZERO@plt>
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1090 <CPU_SET@plt>
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
lea    -0x10(%rbp),%rdx
call   1030 <pthread_attr_setaffinity_np@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1235 <do_affinity_test+0xc5>
mov    -0x14(%rbp),%r8d
mov    0x2dda(%rip),%rax
mov    (%rax),%r9d
lea    0xdf0(%rip),%rdi
lea    0xe0d(%rip),%rsi
mov    $0xbf,%edx
lea    0xea8(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1299 <do_affinity_test+0x129>
lea    -0x8(%rbp),%rdi
call   1060 <run_threads@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
jne    1278 <do_affinity_test+0x108>
mov    -0x18(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <do_affinity_test+0x129>
cmpl   $0x0,-0x18(%rbp)
je     128d <do_affinity_test+0x11d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1299 <do_affinity_test+0x129>
jmp    1292 <do_affinity_test+0x122>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_affinity_test>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pthread_attr_init@plt>
test   %eax,%eax
je     11ab <do_affinity_test+0x3b>
mov    %eax,%ebx
mov    0x2e54(%rip),%rax
mov    (%rax),%r9d
lea    0xe6a(%rip),%rdi
lea    0xe87(%rip),%rsi
lea    0xf15(%rip),%rcx
mov    $0xb7,%edx
jmp    11fe <do_affinity_test+0x8e>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <CPU_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <CPU_SET@plt>
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1030 <pthread_attr_setaffinity_np@plt>
test   %eax,%eax
je     1210 <do_affinity_test+0xa0>
mov    %eax,%ebx
mov    0x2dff(%rip),%rax
mov    (%rax),%r9d
lea    0xe15(%rip),%rdi
lea    0xe32(%rip),%rsi
lea    0xed2(%rip),%rcx
mov    $0xbf,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0x8(%rsp),%rdi
call   1060 <run_threads@plt>
mov    %eax,%ebx
mov    0x2dad(%rip),%rax
cmp    (%rax),%ebx
jne    1208 <do_affinity_test+0x98>
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xeb2(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1208 <do_affinity_test+0x98>

LLVM IR (-O0):
@.str = [36 x i8] c"%s:%d: %s returned %d (errno = %d)\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/fbtl/tst-default-attr.c\00"
@.str.2 = [18 x i8] c"pthread_attr_init\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"pthread_attr_setaffinity_np\00"
@EPERM = global i32 0
@.str.4 = [32 x i8] c"Skipping CPU Affinity test: %s\0A\00"
define i32 @do_affinity_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 @pthread_attr_init(i32* %2)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i32, i32* %3
%12 = load i32, i32* @errno
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 183, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %3
store i32 %14, i32* %1
br label %42
15: ; preds = %0
%16 = call i32 @CPU_ZERO(i32* %4)
%17 = call i32 @CPU_SET(i32 0, i32* %4)
%18 = call i32 @pthread_attr_setaffinity_np(i32* %2, i32 4, i32* %4)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* %5
%23 = load i32, i32* @errno
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 191, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %5
store i32 %25, i32* %1
br label %42
26: ; preds = %15
%27 = call i32 @run_threads(i32* %2)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = load i32, i32* @EPERM
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* %6
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %33)
store i32 0, i32* %1
br label %42
35: ; preds = %26
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i32, i32* %6
store i32 %39, i32* %1
br label %42
40: ; preds = %35
br label %41
41: ; preds = %40
store i32 0, i32* %1
br label %42
42: ; preds = %41, %38, %31, %21, %10
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [36 x i8] c"%s:%d: %s returned %d (errno = %d)\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/fbtl/tst-default-attr.c\00"
@.str.2 = [18 x i8] c"pthread_attr_init\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"pthread_attr_setaffinity_np\00"
@EPERM = global i32 0
@.str.4 = [32 x i8] c"Skipping CPU Affinity test: %s\0A\00"
define i32 @do_affinity_test() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i32 @pthread_attr_init(i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 183, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %7)
br label %27
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = call i32 @CPU_ZERO(i32* %2)
%12 = call i32 @CPU_SET(i32 0, i32* %2)
%13 = call i32 @pthread_attr_setaffinity_np(i32* %1, i32 4, i32* %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = load i32, i32* @errno
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 191, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %16)
br label %25
18: ; preds = %9
%19 = call i32 @run_threads(i32* %1)
%20 = load i32, i32* @EPERM
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i8* @strerror(i32 %19)
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %18, %15, %22
%26 = phi i32 [ %13, %15 ], [ 0, %22 ], [ %19, %18 ]
br label %27
27: ; preds = %6, %25
%28 = phi i32 [ %26, %25 ], [ %4, %6 ]
ret i32 %28
}