// File: /workspace/github_c_makefile_star2_O3/GangZhuo[P]dohclient/src/channel_udp.c
// Function: channel_udp_create
int channel_udp_create(
	channel_t** pctx,
	const char* name,
	const char* args,
	const config_t* conf,
	const proxy_t* proxies,
	const int proxy_num,
	const chnroute_ctx chnr,
	const chnroute_ctx blacklist,
	void* data)
{
	channel_udp_t* ctx;
	sock_t sock;
	int i;

	ctx = (channel_udp_t*)malloc(sizeof(channel_udp_t));
	if (!ctx) {
		loge("alloc\n");
		return CHANNEL_ALLOC;
	}

	memset(ctx, 0, sizeof(channel_udp_t));

	ctx->name = name;
	ctx->conf = conf;
	ctx->proxies = proxies;
	ctx->proxy_num = proxy_num;
	ctx->chnr = chnr;
	ctx->blacklist = blacklist;
	ctx->data = data;
	ctx->timeout = conf->timeout;

	if (parse_args(ctx, args)) {
		loge("parse_args() error\n");
		free(ctx);
		return CHANNEL_WRONG_ARG;
	}

	if (ctx->timeout <= 0) {
		loge("invalid \"timeout\"\n");
		free(ctx);
		return CHANNEL_WRONG_ARG;
	}

	for (i = 0; i < ctx->upstream_num; i++) {

		sock = socket(ctx->upstreams[i].addr.addr.ss_family, SOCK_DGRAM, IPPROTO_UDP);

		if (sock == -1) {
			loge("create socket error. errno=%d, %s - %s\n",
				errno, strerror(errno), get_sockaddrname(&ctx->upstreams[i].addr));
			free(ctx);
			return CHANNEL_CREATE_SOCKET;
		}

		if (setnonblock(sock) != 0) {
			loge("set sock non-block failed - %s\n",
				get_sockaddrname(&ctx->upstreams[i].addr));
			close(sock);
			free(ctx);
			return CHANNEL_CREATE_SOCKET;
		}

#ifdef WINDOWS
		disable_udp_connreset(sock);
#endif

		ctx->upstreams[i].sock = sock;
	}

	rbtree_init(&ctx->reqdic, rbcmp);
	dllist_init(&ctx->reqs);

	ctx->fdset = fdset;
	ctx->step = step;
	ctx->query = query;
	ctx->destroy = destroy;

	*pctx = (channel_t*)ctx;

	return CHANNEL_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %ebp
movq %r8, %r12
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, 0x30(%rsp)
movl $0x1, %edi
movl $0x910, %esi            # imm = 0x910
callq 0x3240
testq %rax, %rax
je 0x10c8f
movq %rax, %rbx
movq 0x80(%rsp), %rax
movq 0x78(%rsp), %rcx
movq 0x70(%rsp), %rdx
movq %r13, (%rbx)
movq %r15, 0x8(%rbx)
movq %r12, 0x10(%rbx)
movl %ebp, 0x18(%rbx)
movq %rdx, 0x20(%rbx)
movq %rcx, 0x28(%rbx)
movq %rax, 0x50(%rbx)
movl 0x88(%r15), %eax
movl %eax, 0x508(%rbx)
movq $0x0, 0x20(%rsp)
testq %r14, %r14
je 0x10e09
movq %r14, %rdi
callq 0x3610
leaq 0x11fd0(%rip), %rsi     # 0x22a39
leaq 0x20(%rsp), %rdx
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0x3600
testq %rax, %rax
je 0x10bbe
movq %rax, %rbp
leaq 0x80(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x11f9f(%rip), %r14     # 0x22a39
leaq 0x20(%rsp), %r15
leaq 0x12aa4(%rip), %r12     # 0x2354a
cmpb $0x0, (%rbp)
je 0x10bbe
movq %rbp, %rdi
movl $0x3d, %esi
callq 0x3150
testq %rax, %rax
je 0x10ba5
movq %rax, %r13
movb $0x0, (%rax)
incq %r13
movq %rbp, %rdi
movq %r12, %rsi
callq 0x34e0
testl %eax, %eax
je 0x10b4b
movq %rbp, %rdi
leaq 0x12025(%rip), %rsi     # 0x22b0d
callq 0x34e0
testl %eax, %eax
je 0x10b79
movq %rbp, %rdi
leaq 0x12ede(%rip), %rsi     # 0x239dd
callq 0x34e0
testl %eax, %eax
je 0x10b90
xorl %eax, %eax
callq 0x176e5
cmpl $0x4, (%rax)
jl 0x10ba5
movq %r13, (%rsp)
movl $0x4, %edi
leaq 0x12ae3(%rip), %rsi     # 0x2360f
leaq 0x11f27(%rip), %rdx     # 0x22a5a
movl $0x19b, %ecx            # imm = 0x19B
leaq 0x120bd(%rip), %r8      # 0x22bfc
movq %rbp, %r9
xorl %eax, %eax
callq 0x1771e
jmp 0x10ba5
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movl $0x8, %edx
movl $0x90, %ecx
leaq 0x11ef3(%rip), %r8      # 0x22a57
callq 0x181bf
testl %eax, %eax
jle 0x10db6
movl %eax, 0x500(%rbx)
jmp 0x10ba5
movq %r13, %rdi
leaq 0x10c3f(%rip), %rsi     # 0x217c2
callq 0x34e0
movl %eax, 0x504(%rbx)
jmp 0x10ba5
cmpb $0x0, (%r13)
je 0x10ba5
movq %r13, %rdi
callq 0x3570
movl %eax, 0x508(%rbx)
xorl %edi, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3600
movq %rax, %rbp
testq %rax, %rax
jne 0x10aa6
movq 0x18(%rsp), %rdi
callq 0x3450
cmpl $0x0, 0x508(%rbx)
jle 0x10ccf
cmpl $0x0, 0x500(%rbx)
jle 0x10c32
leaq 0x80(%rbx), %r14
xorl %r15d, %r15d
movzwl (%r14), %edi
movl $0x2, %esi
movl $0x11, %edx
callq 0x30d0
cmpl $-0x1, %eax
je 0x10d03
movl %eax, %ebp
movl %eax, %edi
callq 0x17c6b
testl %eax, %eax
jne 0x10d60
movl %ebp, 0x88(%r14)
incq %r15
movslq 0x500(%rbx), %rax
addq $0x90, %r14
cmpq %rax, %r15
jl 0x10be8
movq $0x0, 0x68(%rbx)
leaq 0x218(%rip), %rax       # 0x10e59
movq %rax, 0x70(%rbx)
movq %rbx, %rax
addq $0x58, %rax
movq %rax, 0x58(%rbx)
movq %rax, 0x60(%rbx)
leaq 0x207(%rip), %rax       # 0x10e62
movq %rax, 0x30(%rbx)
leaq 0x268(%rip), %rax       # 0x10ece
movq %rax, 0x38(%rbx)
leaq 0x745(%rip), %rax       # 0x113b6
movq %rax, 0x40(%rbx)
leaq 0x747(%rip), %rax       # 0x113c3
movq %rax, 0x48(%rbx)
movq 0x30(%rsp), %rax
movq %rbx, (%rax)
xorl %ebx, %ebx
jmp 0x10e48
xorl %eax, %eax
callq 0x176e5
movl $0x3, %ebx
cmpl $0x3, (%rax)
jl 0x10e48
leaq 0x12964(%rip), %rsi     # 0x2360f
leaq 0x12994(%rip), %rdx     # 0x23646
leaq 0x12bfa(%rip), %r8      # 0x238b3
movl $0x3, %edi
movl $0x1bb, %ecx            # imm = 0x1BB
xorl %eax, %eax
callq 0x1771e
jmp 0x10e48
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x10e3b
leaq 0x12929(%rip), %rsi     # 0x2360f
leaq 0x12959(%rip), %rdx     # 0x23646
leaq 0x11f66(%rip), %r8      # 0x22c5a
movl $0x3, %edi
movl $0x1d1, %ecx            # imm = 0x1D1
jmp 0x10e34
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x10da4
callq 0x3040
movl (%rax), %ebp
movl %ebp, %edi
callq 0x3140
movq %rax, %r15
movq %r14, %rdi
callq 0x17e75
movq %rax, 0x8(%rsp)
movq %r15, (%rsp)
leaq 0x128d3(%rip), %rsi     # 0x2360f
leaq 0x12903(%rip), %rdx     # 0x23646
leaq 0x1290f(%rip), %r8      # 0x23659
movl $0x3, %edi
movl $0x1dc, %ecx            # imm = 0x1DC
movl %ebp, %r9d
xorl %eax, %eax
callq 0x1771e
jmp 0x10da4
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x10d9d
movq %r14, %rdi
callq 0x17e75
leaq 0x12894(%rip), %rsi     # 0x2360f
leaq 0x128c4(%rip), %rdx     # 0x23646
leaq 0x128f8(%rip), %r8      # 0x23681
movl $0x3, %edi
movl $0x1e3, %ecx            # imm = 0x1E3
movq %rax, %r9
xorl %eax, %eax
callq 0x1771e
movl %ebp, %edi
callq 0x3670
movq %rbx, %rdi
callq 0x3450
movl $0x4, %ebx
jmp 0x10e48
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x10dff
cmpb $0x0, (%r13)
leaq 0x11c89(%rip), %rax     # 0x22a57
cmovneq %r13, %rax
movq %rax, (%rsp)
leaq 0x12832(%rip), %rsi     # 0x2360f
leaq 0x11c76(%rip), %rdx     # 0x22a5a
leaq 0x11c7a(%rip), %r8      # 0x22a65
movl $0x3, %edi
movl $0x18c, %ecx            # imm = 0x18C
movq %rbp, %r9
xorl %eax, %eax
callq 0x1771e
movq 0x18(%rsp), %rdi
callq 0x3450
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x10e3b
leaq 0x127f3(%rip), %rsi     # 0x2360f
leaq 0x12823(%rip), %rdx     # 0x23646
leaq 0x11bb1(%rip), %r8      # 0x229db
movl $0x3, %edi
movl $0x1cb, %ecx            # imm = 0x1CB
xorl %eax, %eax
callq 0x1771e
movq %rbx, %rdi
callq 0x3450
movl $0x2, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq