// File: /workspace/github_c_makefile_star2_O0/mkubecek[P]nperf/server/control.c
// Function: setup_listener
static int setup_listener(struct server_ctrl_config *config)
{
	union sockaddr_any addr = {
		.sa6 = {
			.sin6_family    = AF_INET6,
			.sin6_port      = htons(0),
			.sin6_addr      = IN6ADDR_ANY_INIT,
		}
	};
	unsigned int listen_backlog = config->n_threads;
	socklen_t addr_len = sizeof(addr);
	int val;
	int ret;
	int sd;

	sd = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
	if (sd < 0) {
		ret = -errno;
		perror("socket");
		return ret;
	}

	val = 0;
	ret = setsockopt(sd, SOL_IPV6, IPV6_V6ONLY, &val, sizeof(val));
	if (ret < 0) {
		ret = -errno;
		perror("setsockopt(IPV6_V6ONLY)");
		return ret;
	}
	val = 1;
	ret = setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
	if (ret < 0) {
		ret = -errno;
		perror("setsockopt(SO_REUSEADDR)");
		return ret;
	}

	ret = bind(sd, (struct sockaddr *)&addr.sa, sizeof(addr.sa6));
	if (ret < 0) {
		ret = -errno;
		perror("bind");
		return ret;
	}
	ret = getsockname(sd, &addr.sa, &addr_len);
	if (ret < 0) {
		ret = -errno;
		perror("getsockname");
		return ret;
	}
	ret = sockaddr_get_port(&addr);
	if (ret < 0) {
		fprintf(stderr, "unknown address family %u\n",
			addr.sa.sa_family);
		return -EINVAL;
	}
	config->port = ret;

	if (listen_backlog < MIN_LISTEN_BACKLOG)
		listen_backlog = MIN_LISTEN_BACKLOG;
	if (listen_backlog > MAX_LISTEN_BACKLOG)
		listen_backlog = MAX_LISTEN_BACKLOG;
	ret = listen(sd, listen_backlog);
	if (ret < 0) {
		ret = -errno;
		perror("listen");
		return ret;
	}

	return sd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x1100
movw $0xa, -0x2c(%rbp)
xorl %edi, %edi
callq 0x10a0
movw %ax, -0x2a(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x1c, -0x34(%rbp)
movl $0xa, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x1270
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jge 0x1bf1
callq 0x1040
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x3c(%rbp)
leaq 0x16ff(%rip), %rdi      # 0x32e0
callq 0x11a0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1db3
movl $0x0, -0x38(%rbp)
movl -0x40(%rbp), %edi
movl $0x29, %esi
movl $0x1a, %edx
leaq -0x38(%rbp), %rcx
movl $0x4, %r8d
callq 0x1070
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x1c43
callq 0x1040
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x3c(%rbp)
leaq 0x16b4(%rip), %rdi      # 0x32e7
callq 0x11a0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1db3
movl $0x1, -0x38(%rbp)
movl -0x40(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x38(%rbp), %rcx
movl $0x4, %r8d
callq 0x1070
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x1c95
callq 0x1040
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x3c(%rbp)
leaq 0x167a(%rip), %rdi      # 0x32ff
callq 0x11a0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1db3
movl -0x40(%rbp), %edi
leaq -0x2c(%rbp), %rsi
movl $0x1c, %edx
callq 0x1180
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x1cd5
callq 0x1040
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x3c(%rbp)
leaq 0x1653(%rip), %rdi      # 0x3318
callq 0x11a0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1db3
movl -0x40(%rbp), %edi
leaq -0x2c(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x11d0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x1d14
callq 0x1040
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x3c(%rbp)
leaq 0x1648(%rip), %rdi      # 0x334c
callq 0x11a0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1db3
leaq -0x2c(%rbp), %rdi
callq 0x2160
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x1d4b
movq 0x32cb(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movzwl -0x2c(%rbp), %edx
leaq 0x161d(%rip), %rsi      # 0x3358
movb $0x0, %al
callq 0x1130
movl $0xffffffea, -0x4(%rbp) # imm = 0xFFFFFFEA
jmp 0x1db3
movl -0x3c(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0xe(%rax)
cmpl $0x10, -0x30(%rbp)
jae 0x1d66
movl $0x10, -0x30(%rbp)
cmpl $0x4000, -0x30(%rbp)    # imm = 0x4000
jbe 0x1d76
movl $0x4000, -0x30(%rbp)    # imm = 0x4000
movl -0x40(%rbp), %edi
movl -0x30(%rbp), %esi
callq 0x1140
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x1dad
callq 0x1040
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x3c(%rbp)
leaq 0x157d(%rip), %rdi      # 0x331d
callq 0x11a0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1db3
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)