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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ numa_available();
int numa_distance(int, int);
int numa_num_configured_nodes();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int numnodes, a, b;
  if (numa_available() < 0) {
    printf("no numa support in kernel\n");
    exit(1);
  }
  numnodes = numa_num_configured_nodes();
  for (a = 0; a < numnodes; a++) {
    printf("%03d: ", a);
    if (numa_distance(a, a) != 10) {
      printf("%d: self distance is not 10 (%d)\n", a, numa_distance(a, a));
      exit(1);
    }
    for (b = 0; b < numnodes; b++) {
      int d1 = numa_distance(a, b);
      int d2 = numa_distance(b, a);
      printf("%03d ", d1);
      if (d1 != d2) {
        printf("\n(%d,%d)->(%d,%d) wrong!\n", a, b, d1, d2);
        exit(1);
      }
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <numa_available@plt>
cmp    $0x0,%rax
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1040 <numa_num_configured_nodes@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1298 <main+0x148>
mov    -0xc(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <numa_distance@plt>
cmp    $0xa,%eax
je     11f8 <main+0xa8>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <numa_distance@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127c <main+0x12c>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <numa_distance@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <numa_distance@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1269 <main+0x119>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    126e <main+0x11e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ff <main+0xaf>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1199 <main+0x49>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <numa_available@plt>
test   %rax,%rax
js     1280 <main+0x110>
xor    %eax,%eax
call   1060 <numa_num_configured_nodes@plt>
test   %eax,%eax
jle    1225 <main+0xb5>
mov    %eax,%r12d
lea    0xe85(%rip),%r15
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
lea    0xe49(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,%edi
mov    %r13d,%esi
call   1070 <numa_distance@plt>
cmp    $0xa,%eax
jne    1258 <main+0xe8>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %ebp,%esi
call   1070 <numa_distance@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r13d,%esi
call   1070 <numa_distance@plt>
mov    %eax,%r14d
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r14d,%ebx
jne    1236 <main+0xc6>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    11e0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13d
cmp    %r12d,%r13d
jne    11b0 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf2(%rip),%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r13d,%edi
mov    %r13d,%esi
call   1070 <numa_distance@plt>
lea    0xd9d(%rip),%rdi
mov    %r13d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"no numa support in kernel\0A\00"
@.str.1 = [7 x i8] c"%03d: \00"
@.str.2 = [34 x i8] c"%d: self distance is not 10 (%d)\0A\00"
@.str.3 = [6 x i8] c"%03d \00"
@.str.4 = [26 x i8] c"\0A(%d,%d)->(%d,%d) wrong!\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 (...) @numa_available()
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 (...) @numa_num_configured_nodes()
store i32 %13, i32* %2
store i32 0, i32* %3
br label %14
14: ; preds = %62, %12
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %65
18: ; preds = %14
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = load i32, i32* %3
%23 = call i32 @numa_distance(i32 %21, i32 %22)
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i32, i32* %3
%27 = load i32, i32* %3
%28 = load i32, i32* %3
%29 = call i32 @numa_distance(i32 %27, i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %18
store i32 0, i32* %4
br label %33
33: ; preds = %57, %32
%34 = load i32, i32* %4
%35 = load i32, i32* %2
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %60
37: ; preds = %33
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = call i32 @numa_distance(i32 %38, i32 %39)
store i32 %40, i32* %5
%41 = load i32, i32* %4
%42 = load i32, i32* %3
%43 = call i32 @numa_distance(i32 %41, i32 %42)
store i32 %43, i32* %6
%44 = load i32, i32* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %56
49: ; preds = %37
%50 = load i32, i32* %3
%51 = load i32, i32* %4
%52 = load i32, i32* %5
%53 = load i32, i32* %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %50, i32 %51, i32 %52, i32 %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %37
br label %57
57: ; preds = %56
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %33
60: ; preds = %33
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %62
62: ; preds = %60
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %14
65: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%03d: \00"
@.str.2 = [34 x i8] c"%d: self distance is not 10 (%d)\0A\00"
@.str.3 = [6 x i8] c"%03d \00"
@.str.4 = [26 x i8] c"\0A(%d,%d)->(%d,%d) wrong!\0A\00"
@str = [26 x i8] c"no numa support in kernel\00"
define i32 @main() {
%1 = tail call i64 (...) @numa_available()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 (...) @numa_num_configured_nodes()
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %34
9: ; preds = %6, %30
%10 = phi i32 [ %32, %30 ], [ 0, %6 ]
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 @numa_distance(i32 %10, i32 %10)
%13 = icmp eq i32 %12, 10
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = tail call i32 @numa_distance(i32 %10, i32 %10)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9, %27
%19 = phi i32 [ %28, %27 ], [ 0, %9 ]
%20 = tail call i32 @numa_distance(i32 %10, i32 %19)
%21 = tail call i32 @numa_distance(i32 %19, i32 %10)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%23 = icmp eq i32 %20, %21
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %10, i32 %19, i32 %20, i32 %21)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = add nuw nsw i32 %19, 1
%29 = icmp eq i32 %28, %7
br i1 %29, label %30, label %18
30: ; preds = %27
%31 = tail call i32 @putchar(i32 10)
%32 = add nuw nsw i32 %10, 1
%33 = icmp eq i32 %32, %7
br i1 %33, label %34, label %9
34: ; preds = %30, %6
ret i32 0
}