// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movl %r9d, %ebp
movq %r8, %r12
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, 0x18(%rsp)
pushq $0x1
popq %rdi
movl $0x910, %esi            # imm = 0x910
callq 0x3250
testq %rax, %rax
je 0x102b3
movq %rax, %rbx
movq 0x70(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x60(%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)
andq $0x0, 0x20(%rsp)
testq %r14, %r14
je 0x104e3
movq %r14, %rdi
callq 0x3620
leaq 0x108b9(%rip), %r14     # 0x20a39
leaq 0x20(%rsp), %r12
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3610
movq %rax, %r13
leaq 0x80(%rbx), %r15
testq %r13, %r13
je 0x102ee
cmpb $0x0, (%r13)
je 0x102ee
movq %r13, %rdi
pushq $0x3d
popq %rsi
callq 0x3150
testq %rax, %rax
je 0x1029e
movq %rax, %rbp
movb $0x0, (%rax)
incq %rbp
movq %r13, %rdi
leaq 0x1136d(%rip), %rsi     # 0x2154a
callq 0x34f0
testl %eax, %eax
je 0x10249
movq %r13, %rdi
leaq 0x1091d(%rip), %rsi     # 0x20b0d
callq 0x34f0
testl %eax, %eax
je 0x10273
movq %r13, %rdi
leaq 0x117da(%rip), %rsi     # 0x219dd
callq 0x34f0
testl %eax, %eax
je 0x1028a
xorl %eax, %eax
callq 0x165f5
cmpl $0x4, (%rax)
jl 0x1029e
movq %rbp, (%rsp)
pushq $0x4
popq %rdi
leaq 0x113e5(%rip), %rsi     # 0x2160f
leaq 0x10829(%rip), %rdx     # 0x20a5a
movl $0x19b, %ecx            # imm = 0x19B
leaq 0x109bf(%rip), %r8      # 0x20bfc
movq %r13, %r9
xorl %eax, %eax
callq 0x1662e
jmp 0x1029e
movq %rbp, %rdi
movq %r15, %rsi
pushq $0x8
popq %rdx
movl $0x90, %ecx
leaq 0x107f9(%rip), %r8      # 0x20a57
callq 0x170aa
testl %eax, %eax
jle 0x10493
movl %eax, 0x500(%rbx)
jmp 0x1029e
movq %rbp, %rdi
leaq 0xf545(%rip), %rsi      # 0x1f7c2
callq 0x34f0
movl %eax, 0x504(%rbx)
jmp 0x1029e
cmpb $0x0, (%rbp)
je 0x1029e
movq %rbp, %rdi
callq 0x3580
movl %eax, 0x508(%rbx)
xorl %edi, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3610
movq %rax, %r13
jmp 0x101a2
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x10354
leaq 0x11345(%rip), %rsi     # 0x2160f
leaq 0x11375(%rip), %rdx     # 0x21646
leaq 0x115db(%rip), %r8      # 0x218b3
pushq $0x3
popq %rbx
movl %ebx, %edi
movl $0x1bb, %ecx            # imm = 0x1BB
xorl %eax, %eax
callq 0x1662e
jmp 0x1051e
movq 0x10(%rsp), %rdi
callq 0x3460
cmpl $0x0, 0x508(%rbx)
jle 0x1035b
xorl %r13d, %r13d
pushq $0x2
popq %r14
pushq $0x11
popq %r12
movslq 0x500(%rbx), %rax
cmpq %rax, %r13
jge 0x1038d
movzwl (%r15), %edi
movl %r14d, %esi
movl %r12d, %edx
callq 0x30d0
cmpl $-0x1, %eax
je 0x103e7
movl %eax, %ebp
movl %eax, %edi
callq 0x16ba5
testl %eax, %eax
jne 0x10442
movl %ebp, 0x88(%r15)
incq %r13
addq $0x90, %r15
jmp 0x1030c
pushq $0x3
jmp 0x1051d
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x10513
leaq 0x1129d(%rip), %rsi     # 0x2160f
leaq 0x112cd(%rip), %rdx     # 0x21646
leaq 0x108da(%rip), %r8      # 0x20c5a
pushq $0x3
popq %rdi
movl $0x1d1, %ecx            # imm = 0x1D1
jmp 0x1050c
andq $0x0, 0x68(%rbx)
leaq 0x196(%rip), %rax       # 0x1052f
movq %rax, 0x70(%rbx)
movq %rbx, %rax
addq $0x58, %rax
movq %rax, 0x58(%rbx)
movq %rax, 0x60(%rbx)
leaq 0x185(%rip), %rax       # 0x10538
movq %rax, 0x30(%rbx)
leaq 0x1ed(%rip), %rax       # 0x105ab
movq %rax, 0x38(%rbx)
leaq 0x632(%rip), %rax       # 0x109fb
movq %rax, 0x40(%rbx)
leaq 0x634(%rip), %rax       # 0x10a08
movq %rax, 0x48(%rbx)
movq 0x18(%rsp), %rax
movq %rbx, (%rax)
xorl %ebx, %ebx
jmp 0x1051e
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x10484
callq 0x3040
movl (%rax), %ebp
movl %ebp, %edi
callq 0x3140
movq %rax, %r14
movq %r15, %rdi
callq 0x16d82
movq %rax, 0x8(%rsp)
movq %r14, (%rsp)
leaq 0x111ef(%rip), %rsi     # 0x2160f
leaq 0x1121f(%rip), %rdx     # 0x21646
leaq 0x1122b(%rip), %r8      # 0x21659
pushq $0x3
popq %rdi
movl $0x1dc, %ecx            # imm = 0x1DC
movl %ebp, %r9d
xorl %eax, %eax
callq 0x1662e
jmp 0x10484
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x1047d
movq %r15, %rdi
callq 0x16d82
leaq 0x111b2(%rip), %rsi     # 0x2160f
leaq 0x111e2(%rip), %rdx     # 0x21646
leaq 0x11216(%rip), %r8      # 0x21681
pushq $0x3
popq %rdi
movl $0x1e3, %ecx            # imm = 0x1E3
movq %rax, %r9
xorl %eax, %eax
callq 0x1662e
movl %ebp, %edi
callq 0x3680
movq %rbx, %rdi
callq 0x3460
pushq $0x4
jmp 0x1051d
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x104d9
cmpb $0x0, (%rbp)
leaq 0x105ad(%rip), %rax     # 0x20a57
cmovneq %rbp, %rax
movq %rax, (%rsp)
leaq 0x11156(%rip), %rsi     # 0x2160f
leaq 0x1059a(%rip), %rdx     # 0x20a5a
leaq 0x1059e(%rip), %r8      # 0x20a65
pushq $0x3
popq %rdi
movl $0x18c, %ecx            # imm = 0x18C
movq %r13, %r9
xorl %eax, %eax
callq 0x1662e
movq 0x10(%rsp), %rdi
callq 0x3460
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x10513
leaq 0x11119(%rip), %rsi     # 0x2160f
leaq 0x11149(%rip), %rdx     # 0x21646
leaq 0x104d7(%rip), %r8      # 0x209db
pushq $0x3
popq %rdi
movl $0x1cb, %ecx            # imm = 0x1CB
xorl %eax, %eax
callq 0x1662e
movq %rbx, %rdi
callq 0x3460
pushq $0x2
popq %rbx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq