#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 /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
int *calloc(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ stderr;
int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ test(int *, int, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int *rcv_fd, cpus;
  cpus = sysconf(_SC_NPROCESSORS_ONLN);
  if (cpus <= 0)
    error(1, errno, "failed counting cpus");
  rcv_fd = calloc(cpus, sizeof(int));
  if (!rcv_fd)
    error(1, 0, "failed to allocate array");
  fprintf(stderr, "---- IPv4 UDP ----\n");
  test(rcv_fd, cpus, AF_INET, SOCK_DGRAM);
  fprintf(stderr, "---- IPv6 UDP ----\n");
  test(rcv_fd, cpus, AF_INET6, SOCK_DGRAM);
  fprintf(stderr, "---- IPv4 TCP ----\n");
  test(rcv_fd, cpus, AF_INET, SOCK_STREAM);
  fprintf(stderr, "---- IPv6 TCP ----\n");
  test(rcv_fd, cpus, 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    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11a4 <main+0x44>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe61(%rip),%rdx
call   1060 <error@plt>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d3 <main+0x73>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe47(%rip),%rdx
call   1060 <error@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    0x2dd9(%rip),%rax
mov    (%rax),%ecx
call   1080 <test@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
mov    0x2da6(%rip),%rax
mov    (%rax),%ecx
call   1080 <test@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2d8c(%rip),%rax
mov    (%rax),%edx
mov    0x2d53(%rip),%rax
mov    (%rax),%ecx
call   1080 <test@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2d41(%rip),%rax
mov    (%rax),%edx
mov    0x2d20(%rip),%rax
mov    (%rax),%ecx
call   1080 <test@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%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
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1199 <main+0x39>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdx
mov    $0x1,%edi
call   1060 <error@plt>
mov    %ebp,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <main+0x60>
lea    0xe61(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <error@plt>
mov    0x2df9(%rip),%r14
mov    (%r14),%edi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e0b(%rip),%r15
mov    (%r15),%edx
mov    0x2df1(%rip),%r13
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <test@plt>
mov    (%r14),%edi
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dc5(%rip),%r12
mov    (%r12),%edx
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <test@plt>
mov    (%r14),%edi
lea    0xe2f(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%r15),%edx
mov    0x2d82(%rip),%r15
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <test@plt>
mov    (%r14),%edi
lea    0xe1d(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%r12),%edx
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <test@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%r14),%edi
lea    0xe09(%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):
@_SC_NPROCESSORS_ONLN = global i32 0
@errno = global i32 0
@.str = [21 x i8] c"failed counting cpus\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 = load i32, i32* @_SC_NPROCESSORS_ONLN
%5 = call i32 @sysconf(i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = call i32 @error(i32 1, i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %0
%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 = %11
%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, %11
%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):
@_SC_NPROCESSORS_ONLN = global i32 0
@errno = global i32 0
@.str = [21 x i8] c"failed counting cpus\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 = load i32, i32* @_SC_NPROCESSORS_ONLN
%2 = tail call i32 @sysconf(i32 %1)
%3 = icmp slt i32 %2, 1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = tail call i32 @error(i32 1, i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %4, %0
%8 = tail call i32* @calloc(i32 %2, i32 4)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = 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 %12
12: ; preds = %10, %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @test(i32* %8, i32 %2, i32 %15, i32 %16)
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @AF_INET6
%21 = load i32, i32* @SOCK_DGRAM
%22 = tail call i32 @test(i32* %8, i32 %2, i32 %20, i32 %21)
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = tail call i32 @test(i32* %8, i32 %2, i32 %25, i32 %26)
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @AF_INET6
%31 = load i32, i32* @SOCK_STREAM
%32 = tail call i32 @test(i32* %8, i32 %2, i32 %30, i32 %31)
%33 = tail call i32 @free(i32* %8)
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}