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

/* Variables and functions */
int /*<<< orphan*/ *CPU_ALLOC(int);
size_t CPU_ALLOC_SIZE(int);
int /*<<< orphan*/ CPU_FREE(int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO_S(size_t, int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ printf(char *, char *, int, char *, int, int);
int pthread_attr_getaffinity_np(int /*<<< orphan*/ *, size_t,
                                int /*<<< orphan*/ *);
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setaffinity_np(int /*<<< orphan*/ *, size_t,
                                int /*<<< orphan*/ *);
int do_test(void) {
  for (int i = 0; i < 10; i++) {
    pthread_attr_t attr;
    cpu_set_t *cpuset = CPU_ALLOC(512);
    size_t cpusetsize = CPU_ALLOC_SIZE(512);
    CPU_ZERO_S(cpusetsize, cpuset);
    ({
      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/Phant0mas/glibc-hurd/refs/"
               "heads/baseline/nptl/tst-pthread-attr-affinity.c",
               49, "pthread_attr_init", ret, errno);
        return ret;
      }
    });
    ({
      int ret = pthread_attr_setaffinity_np(&attr, cpusetsize, 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/Phant0mas/glibc-hurd/refs/"
               "heads/baseline/nptl/tst-pthread-attr-affinity.c",
               50, "pthread_attr_setaffinity_np", ret, errno);
        return ret;
      }
    });
    CPU_FREE(cpuset);
    cpuset = CPU_ALLOC(1);
    cpusetsize = CPU_ALLOC_SIZE(1);
    ({
      int ret = pthread_attr_getaffinity_np(&attr, cpusetsize, 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/Phant0mas/glibc-hurd/refs/"
               "heads/baseline/nptl/tst-pthread-attr-affinity.c",
               55, "pthread_attr_getaffinity_np", ret, errno);
        return ret;
      }
    });
    CPU_FREE(cpuset);
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    12f8 <do_test+0x178>
mov    $0x200,%edi
call   1030 <CPU_ALLOC@plt>
mov    %rax,-0x18(%rbp)
mov    $0x200,%edi
call   1050 <CPU_ALLOC_SIZE@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <CPU_ZERO_S@plt>
lea    -0xc(%rbp),%rdi
call   1070 <pthread_attr_init@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1210 <do_test+0x90>
mov    -0x24(%rbp),%r8d
mov    0x2dfd(%rip),%rax
mov    (%rax),%r9d
lea    0xe13(%rip),%rdi
lea    0xe30(%rip),%rsi
mov    $0x31,%edx
lea    0xec8(%rip),%rcx
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ff <do_test+0x17f>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0xc(%rbp),%rdi
call   1040 <pthread_attr_setaffinity_np@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1266 <do_test+0xe6>
mov    -0x28(%rbp),%r8d
mov    0x2da7(%rip),%rax
mov    (%rax),%r9d
lea    0xdbd(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    $0x32,%edx
lea    0xe84(%rip),%rcx
call   1060 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ff <do_test+0x17f>
mov    -0x18(%rbp),%rdi
call   1080 <CPU_FREE@plt>
mov    $0x1,%edi
call   1030 <CPU_ALLOC@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
call   1050 <CPU_ALLOC_SIZE@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0xc(%rbp),%rdi
call   1090 <pthread_attr_getaffinity_np@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     12e1 <do_test+0x161>
mov    -0x2c(%rbp),%r8d
mov    0x2d2c(%rip),%rax
mov    (%rax),%r9d
lea    0xd42(%rip),%rdi
lea    0xd5f(%rip),%rsi
mov    $0x37,%edx
lea    0xe25(%rip),%rcx
call   1060 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ff <do_test+0x17f>
mov    -0x18(%rbp),%rdi
call   1080 <CPU_FREE@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118f <do_test+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xa,%r12d
lea    0xc(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    $0x200,%edi
call   1030 <CPU_ALLOC@plt>
mov    %rax,%r15
mov    $0x200,%edi
call   1050 <CPU_ALLOC_SIZE@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   10a0 <CPU_ZERO_S@plt>
mov    %r14,%rdi
call   1070 <pthread_attr_init@plt>
test   %eax,%eax
jne    122a <do_test+0xaa>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <pthread_attr_setaffinity_np@plt>
test   %eax,%eax
jne    1252 <do_test+0xd2>
mov    %r15,%rdi
call   1080 <CPU_FREE@plt>
mov    $0x1,%edi
call   1030 <CPU_ALLOC@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1050 <CPU_ALLOC_SIZE@plt>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1090 <pthread_attr_getaffinity_np@plt>
test   %eax,%eax
jne    127a <do_test+0xfa>
mov    %rbx,%rdi
call   1080 <CPU_FREE@plt>
add    $0xffffffff,%r12d
jne    11a0 <do_test+0x20>
xor    %ebp,%ebp
jmp    12a8 <do_test+0x128>
mov    %eax,%ebp
mov    0x2dad(%rip),%rax
mov    (%rax),%r9d
lea    0xdc3(%rip),%rdi
lea    0xde0(%rip),%rsi
lea    0xe7d(%rip),%rcx
mov    $0x31,%edx
jmp    12a0 <do_test+0x120>
mov    %eax,%ebp
mov    0x2d85(%rip),%rax
mov    (%rax),%r9d
lea    0xd9b(%rip),%rdi
lea    0xdb8(%rip),%rsi
lea    0xe67(%rip),%rcx
mov    $0x32,%edx
jmp    12a0 <do_test+0x120>
mov    %eax,%ebp
mov    0x2d5d(%rip),%rax
mov    (%rax),%r9d
lea    0xd73(%rip),%rdi
lea    0xd90(%rip),%rsi
lea    0xe5b(%rip),%rcx
mov    $0x37,%edx
mov    %ebp,%r8d
call   1060 <printf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"%s:%d: %s returned %d (errno = %d)\0A\00"
@.str.1 = [164 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Phant0mas/glibc-hurd/refs/heads/baseline/nptl/tst-pthread-attr-affinity.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"
@.str.4 = [28 x i8] c"pthread_attr_getaffinity_np\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %2
br label %9
9: ; preds = %55, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %58
12: ; preds = %9
%13 = call i32* @CPU_ALLOC(i32 512)
store i32* %13, i32** %4
%14 = call i64 @CPU_ALLOC_SIZE(i32 512)
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = load i32*, i32** %4
%17 = call i32 @CPU_ZERO_S(i64 %15, i32* %16)
%18 = call i32 @pthread_attr_init(i32* %3)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %12
%22 = load i32, i32* %6
%23 = load i32, i32* @errno
%24 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %6
store i32 %25, i32* %1
br label %59
26: ; preds = %12
%27 = load i64, i64* %5
%28 = load i32*, i32** %4
%29 = call i32 @pthread_attr_setaffinity_np(i32* %3, i64 %27, i32* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = load i32, i32* %7
%34 = load i32, i32* @errno
%35 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %33, i32 %34)
%36 = load i32, i32* %7
store i32 %36, i32* %1
br label %59
37: ; preds = %26
%38 = load i32*, i32** %4
%39 = call i32 @CPU_FREE(i32* %38)
%40 = call i32* @CPU_ALLOC(i32 1)
store i32* %40, i32** %4
%41 = call i64 @CPU_ALLOC_SIZE(i32 1)
store i64 %41, i64* %5
%42 = load i64, i64* %5
%43 = load i32*, i32** %4
%44 = call i32 @pthread_attr_getaffinity_np(i32* %3, i64 %42, i32* %43)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %37
%48 = load i32, i32* %8
%49 = load i32, i32* @errno
%50 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %48, i32 %49)
%51 = load i32, i32* %8
store i32 %51, i32* %1
br label %59
52: ; preds = %37
%53 = load i32*, i32** %4
%54 = call i32 @CPU_FREE(i32* %53)
br label %55
55: ; preds = %52
%56 = load i32, i32* %2
%57 = add nsw i32 %56, 1
store i32 %57, i32* %2
br label %9
58: ; preds = %9
store i32 0, i32* %1
br label %59
59: ; preds = %58, %47, %32, %21
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [36 x i8] c"%s:%d: %s returned %d (errno = %d)\0A\00"
@.str.1 = [164 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Phant0mas/glibc-hurd/refs/heads/baseline/nptl/tst-pthread-attr-affinity.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"
@.str.4 = [28 x i8] c"pthread_attr_getaffinity_np\00"
define i32 @do_test() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %0, %30
%4 = phi i32 [ 0, %0 ], [ %32, %30 ]
%5 = call i32* @CPU_ALLOC(i32 512)
%6 = call i64 @CPU_ALLOC_SIZE(i32 512)
%7 = call i32 @CPU_ZERO_S(i64 %6, i32* %5)
%8 = call i32 @pthread_attr_init(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %11)
br label %28
13: ; preds = %3
%14 = call i32 @pthread_attr_setaffinity_np(i32* %1, i64 %6, i32* %5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %17)
br label %28
19: ; preds = %13
%20 = call i32 @CPU_FREE(i32* %5)
%21 = call i32* @CPU_ALLOC(i32 1)
%22 = call i64 @CPU_ALLOC_SIZE(i32 1)
%23 = call i32 @pthread_attr_getaffinity_np(i32* %1, i64 %22, i32* %21)
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %19
%26 = load i32, i32* @errno
%27 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %23, i32 %26)
br label %28
28: ; preds = %25, %16, %10
%29 = phi i32 [ %8, %10 ], [ %14, %16 ], [ %23, %25 ]
br label %34
30: ; preds = %19
%31 = call i32 @CPU_FREE(i32* %21)
%32 = add nuw nsw i32 %4, 1
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %3
34: ; preds = %30, %28
%35 = phi i32 [ %29, %28 ], [ 0, %30 ]
ret i32 %35
}