// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/http.c
// Function: http_send
int http_send(http_ctx_t* ctx, sockaddr_t* addr, int use_proxy, http_request_t* request,
	int timeout,
	http_callback_fun_t callback, void* state)
{
	http_conn_t* conn;
	http_response_t* response;
	int r;

	logd("server addr=%s\n", get_sockaddrname(addr));

	response = http_response_create();
	if (!response) {
		loge("http_response_create() error\n");
		return -1;
	}

	if (use_proxy && ctx->proxy_num <= 0) {
		use_proxy = 0;
	}

	conn = http_get_conn(ctx, request->host, addr, use_proxy);
	if (!conn) {
		loge("http_get_conn() error\n");
		http_response_destroy(response);
		return -1;
	}

	if (conn->tag) {
		free(conn->tag);
		conn->tag = NULL;
	}

	if (request->tag) {
		conn->tag = strdup(request->tag);
	}

	if (timeout > 0) {
		request->expire = time(NULL) + timeout;
	}
	else {
		request->expire = 0;
	}

	if (conn->conn.status == cs_connected) {
		if (use_proxy && ctx->proxy_num > 0) {
			r = http_proxy_handshake(ctx, conn);
		}
		else {
			r = http_ssl_handshake(ctx, conn);
		}
		if (r) {
			loge("%s() error\n",
				use_proxy && ctx->proxy_num > 0 ?
				"http_proxy_handshake" : "http_ssl_handshake");
			http_conn_close(conn);
			http_response_destroy(response);
			return -1;
		}
	}

	stream_reset(&conn->conn.ws);

	r = http_request_serialize(&conn->conn.ws, request);
	if (r <= 0) {
		loge("http_request_serialize() error\n");
		http_conn_close(conn);
		http_response_destroy(response);
		return -1;
	}

	http_parser_init(&conn->parser, HTTP_RESPONSE);
	stream_reset(&conn->field.name);
	stream_reset(&conn->field.value);

	conn->parser.data = conn;

	if (conn->conn.status == cs_ssl_handshaked) {
		r = http_conn_send(conn);
		if (r < 0) {
			loge("http_conn_send() error\n");
			http_conn_close(conn);
			http_response_destroy(response);
			return -1;
		}
	}

	request->conn = conn;
	request->callback = callback;
	request->cb_state = state;

	response->conn = conn;

	conn->request = request;
	conn->response = response;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movb $0x0, %al
callq 0x242d0
cmpl $0x7, (%rax)
jl 0x20061
movq -0x18(%rbp), %rdi
callq 0x20440
movq %rax, %r9
movl $0x7, %edi
leaq 0x173d5(%rip), %rsi     # 0x3741c
leaq 0x176e5(%rip), %rdx     # 0x37733
movl $0x77f, %ecx            # imm = 0x77F
leaq 0x176e3(%rip), %r8      # 0x3773d
movb $0x0, %al
callq 0x243b0
jmp 0x20063
callq 0x1efe0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x200b5
jmp 0x20075
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x200a7
movl $0x3, %edi
leaq 0x1738f(%rip), %rsi     # 0x3741c
leaq 0x1769f(%rip), %rdx     # 0x37733
movl $0x783, %ecx            # imm = 0x783
leaq 0x176ad(%rip), %r8      # 0x3774d
movb $0x0, %al
callq 0x243b0
jmp 0x200a9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x20435
cmpl $0x0, -0x1c(%rbp)
je 0x200cc
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jg 0x200cc
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x20460
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2013a
jmp 0x200f1
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x20123
movl $0x3, %edi
leaq 0x17313(%rip), %rsi     # 0x3741c
leaq 0x17623(%rip), %rdx     # 0x37733
movl $0x78d, %ecx            # imm = 0x78D
leaq 0x1764f(%rip), %r8      # 0x3776b
movb $0x0, %al
callq 0x243b0
jmp 0x20125
movq -0x48(%rbp), %rdi
callq 0x1f090
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x20435
movq -0x40(%rbp), %rax
cmpq $0x0, 0x128(%rax)
je 0x20167
movq -0x40(%rbp), %rax
movq 0x128(%rax), %rdi
callq 0x3460
movq -0x40(%rbp), %rax
movq $0x0, 0x128(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x2018d
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3620
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x128(%rax)
cmpl $0x0, -0x2c(%rbp)
jle 0x201b0
xorl %eax, %eax
movl %eax, %edi
callq 0x3330
movq %rax, %rcx
movslq -0x2c(%rbp), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
jmp 0x201bc
movq -0x28(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x40(%rbp), %rax
cmpl $0x2, 0x48(%rax)
jne 0x2028d
cmpl $0x0, -0x1c(%rbp)
je 0x201ec
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x201ec
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x20670
movl %eax, -0x4c(%rbp)
jmp 0x201fc
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x20730
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x2028b
jmp 0x20208
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x2026b
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x4d(%rbp)
je 0x2022d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
setg %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %cl
leaq 0x1756c(%rip), %r9      # 0x377a3
leaq 0x17550(%rip), %rax     # 0x3778e
testb $0x1, %cl
cmovneq %rax, %r9
movl $0x3, %edi
leaq 0x171cb(%rip), %rsi     # 0x3741c
leaq 0x174db(%rip), %rdx     # 0x37733
movl $0x7ac, %ecx            # imm = 0x7AC
leaq 0x1751e(%rip), %r8      # 0x37782
movb $0x0, %al
callq 0x243b0
jmp 0x2026d
movq -0x40(%rbp), %rdi
callq 0x208f0
movq -0x48(%rbp), %rdi
callq 0x1f090
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x20435
jmp 0x2028d
movq -0x40(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x40(%rbp), %rdi
addq $0x10, %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rsi
callq 0x1eee0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jg 0x20315
jmp 0x202c3
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x202f5
movl $0x3, %edi
leaq 0x17141(%rip), %rsi     # 0x3741c
leaq 0x17451(%rip), %rdx     # 0x37733
movl $0x7b7, %ecx            # imm = 0x7B7
leaq 0x174c8(%rip), %r8      # 0x377b6
movb $0x0, %al
callq 0x243b0
jmp 0x202f7
movq -0x40(%rbp), %rdi
callq 0x208f0
movq -0x48(%rbp), %rdi
callq 0x1f090
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x20435
movq -0x40(%rbp), %rdi
addq $0xb0, %rdi
movl $0x1, %esi
callq 0xacf0
movq -0x40(%rbp), %rax
movl $0x0, 0xdc(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0xd8(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0xf4(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0xf0(%rax)
movq -0x40(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x40(%rbp), %rax
cmpl $0x11, 0x48(%rax)
jne 0x203e0
movq -0x40(%rbp), %rdi
callq 0x20940
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x203de
jmp 0x2038f
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x203c1
movl $0x3, %edi
leaq 0x17075(%rip), %rsi     # 0x3741c
leaq 0x17385(%rip), %rdx     # 0x37733
movl $0x7c6, %ecx            # imm = 0x7C6
leaq 0x1741c(%rip), %r8      # 0x377d6
movb $0x0, %al
callq 0x243b0
jmp 0x203c3
movq -0x40(%rbp), %rdi
callq 0x208f0
movq -0x48(%rbp), %rdi
callq 0x1f090
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x20435
jmp 0x203e0
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x40(%rax)
movq 0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0xa8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop