#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*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int *calloc(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
scalar_t__ numa_available();
int numa_max_node();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ test(int *, int, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int *rcv_fd, nodes;
  if (numa_available() < 0)
    error(1, errno, "no numa api support");
  nodes = numa_max_node() + 1;
  rcv_fd = calloc(nodes, sizeof(int));
  if (!rcv_fd)
    error(1, 0, "failed to allocate array");
  fprintf(stderr, "---- IPv4 UDP ----\n");
  test(rcv_fd, nodes, AF_INET, SOCK_DGRAM);
  fprintf(stderr, "---- IPv6 UDP ----\n");
  test(rcv_fd, nodes, AF_INET6, SOCK_DGRAM);
  fprintf(stderr, "---- IPv4 TCP ----\n");
  test(rcv_fd, nodes, AF_INET, SOCK_STREAM);
  fprintf(stderr, "---- IPv6 TCP ----\n");
  test(rcv_fd, nodes, AF_INET6, SOCK_STREAM);
  free(rcv_fd);
  fprintf(stderr, "SUCCESS\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <numa_available@plt>
cmp    $0x0,%rax
jge    11aa <main+0x3a>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe5b(%rip),%rdx
call   1060 <error@plt>
mov    $0x0,%al
call   1080 <numa_max_node@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e6 <main+0x76>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe33(%rip),%rdx
call   1060 <error@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    0x2dce(%rip),%rax
mov    (%rax),%ecx
call   1090 <test@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
mov    0x2d9b(%rip),%rax
mov    (%rax),%ecx
call   1090 <test@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2d79(%rip),%rax
mov    (%rax),%edx
mov    0x2d48(%rip),%rax
mov    (%rax),%ecx
call   1090 <test@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
mov    0x2d15(%rip),%rax
mov    (%rax),%ecx
call   1090 <test@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1050 <fprintf@plt>
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   1070 <numa_available@plt>
test   %rax,%rax
jns    11a1 <main+0x31>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdx
mov    $0x1,%edi
call   1060 <error@plt>
xor    %eax,%eax
call   1080 <numa_max_node@plt>
mov    %eax,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11d4 <main+0x64>
lea    0xe4c(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <error@plt>
mov    0x2ded(%rip),%r15
mov    (%r15),%edi
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df7(%rip),%r12
mov    (%r12),%edx
mov    0x2de4(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <test@plt>
mov    (%r15),%edi
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db9(%rip),%r13
mov    0x0(%r13),%edx
mov    0x0(%rbp),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <test@plt>
mov    (%r15),%edi
lea    0xe1b(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%r12),%edx
mov    0x2d76(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <test@plt>
mov    (%r15),%edi
lea    0xe08(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x0(%r13),%edx
mov    0x0(%rbp),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <test@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%r15),%edi
lea    0xdf4(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [20 x i8] c"no numa api support\00"
@.str.1 = [25 x i8] c"failed to allocate array\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"---- IPv4 UDP ----\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [20 x i8] c"---- IPv6 UDP ----\0A\00"
@AF_INET6 = global i32 0
@.str.4 = [20 x i8] c"---- IPv4 TCP ----\0A\00"
@SOCK_STREAM = global i32 0
@.str.5 = [20 x i8] c"---- IPv6 TCP ----\0A\00"
@.str.6 = [9 x i8] c"SUCCESS\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @numa_available()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @error(i32 1, i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %6, %0
%10 = call i32 (...) @numa_max_node()
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i32* @calloc(i32 %12, i32 4)
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp ne i32* %14, null
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32*, i32** %2
%22 = load i32, i32* %3
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_DGRAM
%25 = call i32 @test(i32* %21, i32 %22, i32 %23, i32 %24)
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32*, i32** %2
%29 = load i32, i32* %3
%30 = load i32, i32* @AF_INET6
%31 = load i32, i32* @SOCK_DGRAM
%32 = call i32 @test(i32* %28, i32 %29, i32 %30, i32 %31)
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32*, i32** %2
%36 = load i32, i32* %3
%37 = load i32, i32* @AF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = call i32 @test(i32* %35, i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32*, i32** %2
%43 = load i32, i32* %3
%44 = load i32, i32* @AF_INET6
%45 = load i32, i32* @SOCK_STREAM
%46 = call i32 @test(i32* %42, i32 %43, i32 %44, i32 %45)
%47 = load i32*, i32** %2
%48 = call i32 @free(i32* %47)
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [20 x i8] c"no numa api support\00"
@.str.1 = [25 x i8] c"failed to allocate array\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"---- IPv4 UDP ----\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [20 x i8] c"---- IPv6 UDP ----\0A\00"
@AF_INET6 = global i32 0
@.str.4 = [20 x i8] c"---- IPv4 TCP ----\0A\00"
@SOCK_STREAM = global i32 0
@.str.5 = [20 x i8] c"---- IPv6 TCP ----\0A\00"
@.str.6 = [9 x i8] c"SUCCESS\0A\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 = load i32, i32* @errno
%5 = tail call i32 @error(i32 1, i32 %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %3, %0
%7 = tail call i32 (...) @numa_max_node()
%8 = add nsw i32 %7, 1
%9 = tail call i32* @calloc(i32 %8, i32 4)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @test(i32* %9, i32 %8, i32 %16, i32 %17)
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @AF_INET6
%22 = load i32, i32* @SOCK_DGRAM
%23 = tail call i32 @test(i32* %9, i32 %8, i32 %21, i32 %22)
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = tail call i32 @test(i32* %9, i32 %8, i32 %26, i32 %27)
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* @AF_INET6
%32 = load i32, i32* @SOCK_STREAM
%33 = tail call i32 @test(i32* %9, i32 %8, i32 %31, i32 %32)
%34 = tail call i32 @free(i32* %9)
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}