// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0x910, %edi            # imm = 0x910
callq 0x34d0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x19313
jmp 0x192d3
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x19305
movl $0x3, %edi
leaq 0x1d908(%rip), %rsi     # 0x36bf3
leaq 0x1d938(%rip), %rdx     # 0x36c2a
movl $0x1bb, %ecx            # imm = 0x1BB
leaq 0x1db99(%rip), %r8      # 0x36e97
movb $0x0, %al
callq 0x243b0
jmp 0x19307
movl $0x3, -0x4(%rbp)
jmp 0x1965f
movq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x910, %edx            # imm = 0x910
callq 0x3200
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x18(%rax)
movq 0x10(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movq 0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x28(%rbp), %rax
movl 0x88(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x508(%rax)
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x19670
cmpl $0x0, %eax
je 0x193e5
jmp 0x1939c
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x193ce
movl $0x3, %edi
leaq 0x1d83f(%rip), %rsi     # 0x36bf3
leaq 0x1d86f(%rip), %rdx     # 0x36c2a
movl $0x1cb, %ecx            # imm = 0x1CB
leaq 0x1cbe2(%rip), %r8      # 0x35fa9
movb $0x0, %al
callq 0x243b0
jmp 0x193d0
movq -0x40(%rbp), %rdi
callq 0x3460
movl $0x2, -0x4(%rbp)
jmp 0x1965f
movq -0x40(%rbp), %rax
cmpl $0x0, 0x508(%rax)
jg 0x1943d
jmp 0x193f4
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x19426
movl $0x3, %edi
leaq 0x1d7e7(%rip), %rsi     # 0x36bf3
leaq 0x1d817(%rip), %rdx     # 0x36c2a
movl $0x1d1, %ecx            # imm = 0x1D1
leaq 0x1ce09(%rip), %r8      # 0x36228
movb $0x0, %al
callq 0x243b0
jmp 0x19428
movq -0x40(%rbp), %rdi
callq 0x3460
movl $0x2, -0x4(%rbp)
jmp 0x1965f
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x500(%rcx), %eax
jge 0x195d2
movq -0x40(%rbp), %rax
addq $0x80, %rax
movslq -0x48(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movzwl (%rax), %edi
movl $0x2, %esi
movl $0x11, %edx
callq 0x30e0
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x19522
jmp 0x19490
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1950b
callq 0x3040
movl (%rax), %eax
movl %eax, -0x54(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x3150
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
addq $0x80, %rdi
movslq -0x48(%rbp), %rax
imulq $0x90, %rax, %rax
addq %rax, %rdi
callq 0x198f0
movl -0x54(%rbp), %r9d
movq -0x50(%rbp), %r10
movl $0x3, %edi
leaq 0x1d70b(%rip), %rsi     # 0x36bf3
leaq 0x1d73b(%rip), %rdx     # 0x36c2a
movl $0x1dc, %ecx            # imm = 0x1DC
leaq 0x1d742(%rip), %r8      # 0x36c3d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x1950d
movq -0x40(%rbp), %rdi
callq 0x3460
movl $0x4, -0x4(%rbp)
jmp 0x1965f
movl -0x44(%rbp), %edi
callq 0x24d30
cmpl $0x0, %eax
je 0x195a3
jmp 0x19531
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x19584
movq -0x40(%rbp), %rdi
addq $0x80, %rdi
movslq -0x48(%rbp), %rax
imulq $0x90, %rax, %rax
addq %rax, %rdi
callq 0x198f0
movq %rax, %r9
movl $0x3, %edi
leaq 0x1d689(%rip), %rsi     # 0x36bf3
leaq 0x1d6b9(%rip), %rdx     # 0x36c2a
movl $0x1e3, %ecx            # imm = 0x1E3
leaq 0x1d6e8(%rip), %r8      # 0x36c65
movb $0x0, %al
callq 0x243b0
jmp 0x19586
movl -0x44(%rbp), %edi
callq 0x3680
movq -0x40(%rbp), %rdi
callq 0x3460
movl $0x4, -0x4(%rbp)
jmp 0x1965f
movl -0x44(%rbp), %ecx
movq -0x40(%rbp), %rax
addq $0x80, %rax
movslq -0x48(%rbp), %rdx
imulq $0x90, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x88(%rax)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x19444
jmp 0x195d4
movq -0x40(%rbp), %rax
movq $0x0, 0x68(%rax)
movq -0x40(%rbp), %rax
leaq 0x325(%rip), %rcx       # 0x19910
movq %rcx, 0x70(%rax)
jmp 0x195f1
movq -0x40(%rbp), %rcx
addq $0x58, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x40(%rbp), %rcx
addq $0x58, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x40(%rbp), %rax
leaq 0x324(%rip), %rcx       # 0x19940
movq %rcx, 0x30(%rax)
movq -0x40(%rbp), %rax
leaq 0x4b5(%rip), %rcx       # 0x19ae0
movq %rcx, 0x38(%rax)
movq -0x40(%rbp), %rax
leaq 0x526(%rip), %rcx       # 0x19b60
movq %rcx, 0x40(%rax)
movq -0x40(%rbp), %rax
leaq 0x567(%rip), %rcx       # 0x19bb0
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)