// File: /workspace/github_c_makefile_star2_O1/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 $0x910, %edi            # imm = 0x910
callq 0x34b0
testq %rax, %rax
je 0x11224
movq %rax, %rbx
movl $0x910, %edx            # imm = 0x910
movq %rax, %rdi
xorl %esi, %esi
callq 0x31e0
movq %r13, (%rbx)
movq %r15, 0x8(%rbx)
movq %r12, 0x10(%rbx)
movl %ebp, 0x18(%rbx)
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rbx)
movq 0x78(%rsp), %rax
movq %rax, 0x28(%rbx)
movq 0x80(%rsp), %rax
movq %rax, 0x50(%rbx)
movl 0x88(%r15), %eax
movl %eax, 0x508(%rbx)
movq $0x0, 0x18(%rsp)
testq %r14, %r14
je 0x11261
movq %r14, %rdi
callq 0x3610
leaq 0x11aa4(%rip), %rsi     # 0x22a31
leaq 0x18(%rsp), %rdx
movq %rax, 0x20(%rsp)
movq %rax, %rdi
callq 0x3600
testq %rax, %rax
je 0x11153
movq %rax, %r12
leaq 0x80(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x11a73(%rip), %r13     # 0x22a31
leaq 0x18(%rsp), %rbp
leaq 0x12570(%rip), %r15     # 0x2353a
cmpb $0x0, (%r12)
je 0x11153
movq %r12, %rdi
movl $0x3d, %esi
callq 0x3150
testq %rax, %rax
je 0x1113a
movq %rax, %r14
movb $0x0, (%rax)
incq %r14
movq %r12, %rdi
movq %r15, %rsi
callq 0x34e0
testl %eax, %eax
je 0x11073
movq %r12, %rdi
leaq 0x11af8(%rip), %rsi     # 0x22b05
callq 0x34e0
testl %eax, %eax
je 0x110a7
movq %r12, %rdi
leaq 0x129a9(%rip), %rsi     # 0x239cd
callq 0x34e0
testl %eax, %eax
je 0x110be
xorl %eax, %eax
callq 0x17d59
cmpl $0x4, (%rax)
jl 0x1113a
movq %r14, (%rsp)
movl $0x4, %edi
leaq 0x125ae(%rip), %rsi     # 0x235ff
leaq 0x119fa(%rip), %rdx     # 0x22a52
movl $0x19b, %ecx            # imm = 0x19B
leaq 0x11b90(%rip), %r8      # 0x22bf4
movq %r12, %r9
xorl %eax, %eax
callq 0x17d92
jmp 0x1113a
movq %r13, %rbp
movq %r15, %r13
movq %r14, %rdi
movq 0x28(%rsp), %rsi
movl $0x8, %edx
movl $0x90, %ecx
leaq 0x119bd(%rip), %r8      # 0x22a4f
callq 0x18825
movl %eax, %r15d
testl %eax, %eax
jle 0x110d4
movl %r15d, 0x500(%rbx)
jmp 0x11126
movq %r14, %rdi
leaq 0x10731(%rip), %rsi     # 0x217e2
callq 0x34e0
movl %eax, 0x504(%rbx)
jmp 0x1113a
cmpb $0x0, (%r14)
je 0x1113a
movq %r14, %rdi
callq 0x3570
movl %eax, 0x508(%rbx)
jmp 0x1113a
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1111c
cmpb $0x0, (%r14)
leaq 0x11964(%rip), %rax     # 0x22a4f
cmoveq %rax, %r14
movq %r14, (%rsp)
movl $0x3, %edi
leaq 0x12500(%rip), %rsi     # 0x235ff
leaq 0x1194c(%rip), %rdx     # 0x22a52
movl $0x18c, %ecx            # imm = 0x18C
leaq 0x1194b(%rip), %r8      # 0x22a5d
movq %r12, %r9
xorl %eax, %eax
callq 0x17d92
movq 0x20(%rsp), %rdi
callq 0x3450
testl %r15d, %r15d
movq %r13, %r15
movq %rbp, %r13
leaq 0x18(%rsp), %rbp
jle 0x11261
xorl %edi, %edi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3600
movq %rax, %r12
testq %rax, %rax
jne 0x10fca
movq 0x20(%rsp), %rdi
callq 0x3450
cmpl $0x0, 0x508(%rbx)
jle 0x1128e
cmpl $0x0, 0x500(%rbx)
jle 0x111c7
leaq 0x80(%rbx), %r14
xorl %r15d, %r15d
movzwl (%r14), %edi
movl $0x2, %esi
movl $0x11, %edx
callq 0x30d0
cmpl $-0x1, %eax
je 0x112de
movl %eax, %ebp
movl %eax, %edi
callq 0x182cf
testl %eax, %eax
jne 0x1133b
movl %ebp, 0x88(%r14)
incq %r15
movslq 0x500(%rbx), %rax
addq $0x90, %r14
cmpq %rax, %r15
jl 0x1117d
movq $0x0, 0x68(%rbx)
leaq 0x1bb(%rip), %rax       # 0x11391
movq %rax, 0x70(%rbx)
movq %rbx, %rax
addq $0x58, %rax
movq %rax, 0x58(%rbx)
movq %rax, 0x60(%rbx)
leaq 0x1aa(%rip), %rax       # 0x1139a
movq %rax, 0x30(%rbx)
leaq 0x20b(%rip), %rax       # 0x11406
movq %rax, 0x38(%rbx)
leaq 0x720(%rip), %rax       # 0x11926
movq %rax, 0x40(%rbx)
leaq 0x722(%rip), %rax       # 0x11933
movq %rax, 0x48(%rbx)
movq 0x30(%rsp), %rax
movq %rbx, (%rax)
xorl %ebx, %ebx
jmp 0x112cd
xorl %eax, %eax
callq 0x17d59
movl $0x3, %ebx
cmpl $0x3, (%rax)
jl 0x112cd
leaq 0x123bf(%rip), %rsi     # 0x235ff
leaq 0x123ef(%rip), %rdx     # 0x23636
leaq 0x12655(%rip), %r8      # 0x238a3
movl $0x3, %edi
movl $0x1bb, %ecx            # imm = 0x1BB
xorl %eax, %eax
callq 0x17d92
jmp 0x112cd
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x112c0
leaq 0x1238b(%rip), %rsi     # 0x235ff
leaq 0x123bb(%rip), %rdx     # 0x23636
leaq 0x11751(%rip), %r8      # 0x229d3
movl $0x3, %edi
movl $0x1cb, %ecx            # imm = 0x1CB
jmp 0x112b9
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x112c0
leaq 0x1235e(%rip), %rsi     # 0x235ff
leaq 0x1238e(%rip), %rdx     # 0x23636
leaq 0x119a3(%rip), %r8      # 0x22c52
movl $0x3, %edi
movl $0x1d1, %ecx            # imm = 0x1D1
xorl %eax, %eax
callq 0x17d92
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
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1137f
callq 0x3040
movl (%rax), %ebp
movl %ebp, %edi
callq 0x3140
movq %rax, %r15
movq %r14, %rdi
callq 0x184d9
movq %rax, 0x8(%rsp)
movq %r15, (%rsp)
leaq 0x122e8(%rip), %rsi     # 0x235ff
leaq 0x12318(%rip), %rdx     # 0x23636
leaq 0x12324(%rip), %r8      # 0x23649
movl $0x3, %edi
movl $0x1dc, %ecx            # imm = 0x1DC
movl %ebp, %r9d
xorl %eax, %eax
callq 0x17d92
jmp 0x1137f
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x11378
movq %r14, %rdi
callq 0x184d9
leaq 0x122a9(%rip), %rsi     # 0x235ff
leaq 0x122d9(%rip), %rdx     # 0x23636
leaq 0x1230d(%rip), %r8      # 0x23671
movl $0x3, %edi
movl $0x1e3, %ecx            # imm = 0x1E3
movq %rax, %r9
xorl %eax, %eax
callq 0x17d92
movl %ebp, %edi
callq 0x3670
movq %rbx, %rdi
callq 0x3450
movl $0x4, %ebx
jmp 0x112cd