// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/channel_tcp.c
// Function: reqconn_new
static reqconn_t *reqconn_new(tcpreq_t *req, int upstream, int proxy_index)
{
	reqconn_t *conn;
	sock_t sock = -1;
	conn_status cs;
	channel_tcp_t* c = req->ctx;

	conn = (reqconn_t*)malloc(sizeof(reqconn_t));
	if (!conn) {
		loge("alloc\n");
		return NULL;
	}

	memset(conn, 0, sizeof(reqconn_t));

	conn->req = req;
	conn->upstream = upstream;

	if (proxy_index >= 0 && proxy_index < c->proxy_num) {
		conn->use_proxy = TRUE;
		conn->proxy_index = proxy_index;
		cs = tcp_connect(&c->proxies[proxy_index].addr, &sock);
	}
	else {
		cs = tcp_connect(c->upstreams + upstream, &sock);
	}
	if (cs != cs_connected && cs != cs_connecting) {
		loge("tcp_connect() error\n");
		free(conn);
		return NULL;
	}

	if (conn_init(&conn->conn, sock)) {
		loge("conn_init() error\n");
		close(sock);
		free(conn);
		return NULL;
	}

	conn->conn.status = cs;

	return conn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x98, %edi
callq 0x34d0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x166dd
jmp 0x1669c
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x166ce
movl $0x3, %edi
leaq 0x2017c(%rip), %rsi     # 0x36830
leaq 0x2023a(%rip), %rdx     # 0x368f5
movl $0x41, %ecx
leaq 0x207d0(%rip), %r8      # 0x36e97
movb $0x0, %al
callq 0x243b0
jmp 0x166d0
movq $0x0, -0x8(%rbp)
jmp 0x16843
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x98, %edx
callq 0x3200
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x88(%rax)
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x90(%rax)
cmpl $0x0, -0x18(%rbp)
jl 0x16758
movl -0x18(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x16758
movq -0x20(%rbp), %rax
movl $0x1, 0x68(%rax)
movl -0x18(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x18(%rbp), %rax
imulq $0xf8, %rax, %rax
addq %rax, %rdi
addq $0x8, %rdi
leaq -0x24(%rbp), %rsi
callq 0x262d0
movl %eax, -0x28(%rbp)
jmp 0x1677a
movq -0x30(%rbp), %rdi
addq $0x70, %rdi
movslq -0x14(%rbp), %rax
imulq $0x88, %rax, %rax
addq %rax, %rdi
leaq -0x24(%rbp), %rsi
callq 0x262d0
movl %eax, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
je 0x167cf
cmpl $0x1, -0x28(%rbp)
je 0x167cf
jmp 0x16788
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x167ba
movl $0x3, %edi
leaq 0x20090(%rip), %rsi     # 0x36830
leaq 0x2014e(%rip), %rdx     # 0x368f5
movl $0x53, %ecx
leaq 0x2014e(%rip), %r8      # 0x36901
movb $0x0, %al
callq 0x243b0
jmp 0x167bc
movq -0x20(%rbp), %rdi
callq 0x3460
movq $0x0, -0x8(%rbp)
jmp 0x16843
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x26ae0
cmpl $0x0, %eax
je 0x16831
jmp 0x167e2
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x16814
movl $0x3, %edi
leaq 0x20036(%rip), %rsi     # 0x36830
leaq 0x200f4(%rip), %rdx     # 0x368f5
movl $0x59, %ecx
leaq 0x20109(%rip), %r8      # 0x36916
movb $0x0, %al
callq 0x243b0
jmp 0x16816
movl -0x24(%rbp), %edi
callq 0x3680
movq -0x20(%rbp), %rdi
callq 0x3460
movq $0x0, -0x8(%rbp)
jmp 0x16843
movl -0x28(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)