#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 uint32_t;

/* Variables and functions */
int numa_max_node();
int numa_num_configured_cpus();
int *placement(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  uint32_t num_cores = numa_num_configured_cpus();
  uint32_t num_nodes = numa_max_node() + 1;
  if (argv[1]) {
    num_cores = num_cores / 2;
  }
  if (num_nodes < 2) {
    num_nodes = 2;
  }
  printf("%d \n", num_nodes);
  for (int j = num_nodes; j < num_cores + 1; j += num_nodes) {
    uint32_t *rr = placement(j, false);
    uint32_t *fill = placement(j, true);
    printf("FILL: ");
    for (int i = 0; i < j; i++) {
      if (i + 1 < j) {
        printf("%d,", fill[i]);
      } else {
        printf("%d", fill[i]);
      }
    }
    printf("\n");
    printf("RR: ");
    for (int i = 0; i < j; i++) {
      if (i + 1 < j) {
        printf("%d,", rr[i]);
      } else {
        printf("%d", rr[i]);
      }
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <numa_num_configured_cpus@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <numa_max_node@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     118a <main+0x4a>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    119b <main+0x5b>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1300 <main+0x1c0>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1050 <placement@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1050 <placement@plt>
mov    %rax,-0x30(%rbp)
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    125c <main+0x11c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jge    1230 <main+0xf0>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1249 <main+0x109>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124e <main+0x10e>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f7 <main+0xb7>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12e4 <main+0x1a4>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jge    12b8 <main+0x178>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d1 <main+0x191>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d6 <main+0x196>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    127f <main+0x13f>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11b2 <main+0x72>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
call   1050 <numa_num_configured_cpus@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <numa_max_node@plt>
cmpq   $0x0,0x8(%rbx)
je     1183 <main+0x33>
mov    %ebp,%ecx
shr    $0x1f,%ecx
add    %ebp,%ecx
sar    %ecx
mov    %ecx,%ebp
test   %eax,%eax
mov    $0x1,%ebx
cmovg  %eax,%ebx
lea    0x1(%rbx),%esi
lea    0xe69(%rip),%rdi
mov    %rsi,0x10(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,%ebx
jge    12b8 <main+0x168>
mov    $0x1,%r15d
mov    0x10(%rsp),%r12
sub    %r12,%r15
mov    %r12,%rax
neg    %rax
mov    %rax,0x18(%rsp)
lea    0xe41(%rip),%r14
lea    0xe3e(%rip),%r13
mov    %ebp,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
xor    %esi,%esi
call   1060 <placement@plt>
mov    %rax,0x20(%rsp)
mov    %r12d,%edi
mov    $0x1,%esi
call   1060 <placement@plt>
mov    %r13,%rbx
mov    %r14,%r13
mov    %rax,%r14
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
cmp    %r12,%rbp
mov    -0x4(%r14,%rbp,4),%esi
mov    %rbx,%rdi
cmovb  %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r15,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x2,%rax
jne    1220 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdba(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %r13,%r14
mov    %rbx,%r13
mov    0x20(%rsp),%rbx
cmp    %r12,%rbp
mov    -0x4(%rbx,%rbp,4),%esi
mov    %r13,%rdi
cmovb  %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r15,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x2,%rax
jne    1270 <main+0x120>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    0x10(%rsp),%r12
add    0x18(%rsp),%r15
mov    0xc(%rsp),%ebp
cmp    %r12d,%ebp
jge    11e0 <main+0x90>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d \0A\00"
@.str.1 = [7 x i8] c"FILL: \00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [5 x i8] c"RR: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (...) @numa_num_configured_cpus()
store i32 %13, i32* %6
%14 = call i32 (...) @numa_max_node()
%15 = add nsw i32 %14, 1
store i32 %15, i32* %7
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* %6
%22 = sdiv i32 %21, 2
store i32 %22, i32* %6
br label %23
23: ; preds = %20, %2
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 2, i32* %7
br label %27
27: ; preds = %26, %23
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %7
store i32 %30, i32* %8
br label %31
31: ; preds = %101, %27
%32 = load i32, i32* %8
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %105
36: ; preds = %31
%37 = load i32, i32* %8
%38 = call i32* @placement(i32 %37, i32 0)
store i32* %38, i32** %9
%39 = load i32, i32* %8
%40 = call i32* @placement(i32 %39, i32 1)
store i32* %40, i32** %10
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %11
br label %42
42: ; preds = %66, %36
%43 = load i32, i32* %11
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %69
46: ; preds = %42
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
%49 = load i32, i32* %8
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %58
51: ; preds = %46
%52 = load i32*, i32** %10
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %65
58: ; preds = %46
%59 = load i32*, i32** %10
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %58, %51
br label %66
66: ; preds = %65
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %42
69: ; preds = %42
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %12
br label %72
72: ; preds = %96, %69
%73 = load i32, i32* %12
%74 = load i32, i32* %8
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %99
76: ; preds = %72
%77 = load i32, i32* %12
%78 = add nsw i32 %77, 1
%79 = load i32, i32* %8
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %88
81: ; preds = %76
%82 = load i32*, i32** %9
%83 = load i32, i32* %12
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
%86 = load i32, i32* %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %86)
br label %95
88: ; preds = %76
%89 = load i32*, i32** %9
%90 = load i32, i32* %12
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %89, i64 %91
%93 = load i32, i32* %92
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %93)
br label %95
95: ; preds = %88, %81
br label %96
96: ; preds = %95
%97 = load i32, i32* %12
%98 = add nsw i32 %97, 1
store i32 %98, i32* %12
br label %72
99: ; preds = %72
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %101
101: ; preds = %99
%102 = load i32, i32* %7
%103 = load i32, i32* %8
%104 = add nsw i32 %103, %102
store i32 %104, i32* %8
br label %31
105: ; preds = %31
%106 = load i32, i32* %3
ret i32 %106
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d \0A\00"
@.str.1 = [7 x i8] c"FILL: \00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [5 x i8] c"RR: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @numa_num_configured_cpus()
%4 = tail call i32 (...) @numa_max_node()
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
%8 = sdiv i32 %3, 2
%9 = select i1 %7, i32 %3, i32 %8
%10 = icmp sgt i32 %4, 1
%11 = select i1 %10, i32 %4, i32 1
%12 = add nuw nsw i32 %11, 1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %11, %9
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = add nuw nsw i32 %11, 1
%17 = zext i32 %16 to i64
br label %19
18: ; preds = %37, %2
ret i32 0
19: ; preds = %15, %37
%20 = phi i64 [ %17, %15 ], [ %39, %37 ]
%21 = trunc i64 %20 to i32
%22 = tail call i32* @placement(i32 %21, i32 0)
%23 = tail call i32* @placement(i32 %21, i32 1)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %28
25: ; preds = %28
%26 = tail call i32 @putchar(i32 10)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %42
28: ; preds = %19, %28
%29 = phi i64 [ 0, %19 ], [ %30, %28 ]
%30 = add nuw nsw i64 %29, 1
%31 = icmp ult i64 %30, %20
%32 = getelementptr inbounds i32, i32* %23, i64 %29
%33 = load i32, i32* %32
%34 = select i1 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %34, i32 %33)
%36 = icmp eq i64 %30, %20
br i1 %36, label %25, label %28
37: ; preds = %42
%38 = tail call i32 @putchar(i32 10)
%39 = add i64 %20, %17
%40 = trunc i64 %39 to i32
%41 = icmp slt i32 %9, %40
br i1 %41, label %18, label %19
42: ; preds = %25, %42
%43 = phi i64 [ 0, %25 ], [ %44, %42 ]
%44 = add nuw nsw i64 %43, 1
%45 = icmp ult i64 %44, %20
%46 = getelementptr inbounds i32, i32* %22, i64 %43
%47 = load i32, i32* %46
%48 = select i1 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %48, i32 %47)
%50 = icmp eq i64 %44, %20
br i1 %50, label %37, label %42
}