// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/netutils.c
// Function: udp_listen
int udp_listen(listen_t* ctx)
{
	sockaddr_t* addr;
	struct sockaddr* sockaddr;
	sock_t sock;

	addr = &ctx->addr;
	sockaddr = (struct sockaddr*)(&addr->addr);

	sock = socket(sockaddr->sa_family, SOCK_DGRAM, IPPROTO_UDP);

	if (sock == -1) {
		loge("create socket error. errno=%d, %s\n", errno, strerror(errno));
		return -1;
	}

	if (setnonblock(sock) != 0) {
		loge("set sock non-block failed\n");
		close(sock);
		return -1;
	}

	if (setreuseaddr(sock) != 0) {
		loge("set sock reuse address failed\n");
		close(sock);
		return -1;
	}

#ifdef WINDOWS
	disable_udp_connreset(sock);
#endif

	if (bind(sock, sockaddr, addr->addrlen) != 0) {
		loge("bind() error: %s errno=%d, %s\n",
			get_sockaddrname(addr), errno, strerror(errno));
		close(sock);
		return -1;
	}

	ctx->usock = sock;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzwl (%rax), %edi
movl $0x2, %esi
movl $0x11, %edx
callq 0x20b0
movl %eax, -0x24(%rbp)
cmpl $-0x1, -0x24(%rbp)
jne 0x428b
jmp 0x422d
movb $0x0, %al
callq 0x2560
cmpl $0x3, (%rax)
jl 0x427d
callq 0x2030
movl (%rax), %eax
movl %eax, -0x28(%rbp)
callq 0x2030
movl (%rax), %edi
callq 0x20d0
movl -0x28(%rbp), %r9d
movl $0x3, %edi
leaq 0x5ec9(%rip), %rsi      # 0xa128
leaq 0x605d(%rip), %rdx      # 0xa2c3
movl $0x20a, %ecx            # imm = 0x20A
leaq 0x6cdb(%rip), %r8       # 0xaf4d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2640
jmp 0x427f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43e3
movl -0x24(%rbp), %edi
callq 0x2fc0
cmpl $0x0, %eax
je 0x42e2
jmp 0x429a
movb $0x0, %al
callq 0x2560
cmpl $0x3, (%rax)
jl 0x42cc
movl $0x3, %edi
leaq 0x5e76(%rip), %rsi      # 0xa128
leaq 0x600a(%rip), %rdx      # 0xa2c3
movl $0x20f, %ecx            # imm = 0x20F
leaq 0x5f84(%rip), %r8       # 0xa249
movb $0x0, %al
callq 0x2640
jmp 0x42ce
movl -0x24(%rbp), %edi
callq 0x23a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43e3
movl -0x24(%rbp), %edi
callq 0x30d0
cmpl $0x0, %eax
je 0x4339
jmp 0x42f1
movb $0x0, %al
callq 0x2560
cmpl $0x3, (%rax)
jl 0x4323
movl $0x3, %edi
leaq 0x5e1f(%rip), %rsi      # 0xa128
leaq 0x5fb3(%rip), %rdx      # 0xa2c3
movl $0x215, %ecx            # imm = 0x215
leaq 0x5f48(%rip), %r8       # 0xa264
movb $0x0, %al
callq 0x2640
jmp 0x4325
movl -0x24(%rbp), %edi
callq 0x23a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43e3
movl -0x24(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x80(%rax), %edx
callq 0x2080
cmpl $0x0, %eax
je 0x43cf
jmp 0x4356
movb $0x0, %al
callq 0x2560
cmpl $0x3, (%rax)
jl 0x43bc
movq -0x18(%rbp), %rdi
callq 0x41d0
movq %rax, -0x38(%rbp)
callq 0x2030
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
callq 0x2030
movl (%rax), %edi
callq 0x20d0
movq -0x38(%rbp), %r9
movl -0x2c(%rbp), %r10d
movl $0x3, %edi
leaq 0x5d8f(%rip), %rsi      # 0xa128
leaq 0x5f23(%rip), %rdx      # 0xa2c3
movl $0x220, %ecx            # imm = 0x220
leaq 0x5ed7(%rip), %r8       # 0xa283
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2640
jmp 0x43be
movl -0x24(%rbp), %edi
callq 0x23a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43e3
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8c(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)