// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, %r14
movl %r8d, 0x34(%rsp)
movq %rcx, 0x28(%rsp)
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, %rbp
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0x142f8
movq %r12, %rdi
callq 0x16d82
leaq 0xda5c(%rip), %rsi      # 0x21d34
leaq 0xdd6a(%rip), %rdx      # 0x22049
leaq 0xdd6d(%rip), %r8       # 0x22053
pushq $0x7
popq %rdi
movl $0x77f, %ecx            # imm = 0x77F
movq %rax, %r9
xorl %eax, %eax
callq 0x1662e
callq 0x1389e
testq %rax, %rax
je 0x1431d
movq %r14, 0x40(%rsp)
testl %ebx, %ebx
movq %rax, 0x18(%rsp)
je 0x14359
xorl %r13d, %r13d
cmpl $0x0, 0x18(%rbp)
cmovgl %ebx, %r13d
jmp 0x1435c
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbx
cmpl $0x3, (%rax)
jl 0x14855
leaq 0xd9fd(%rip), %rsi      # 0x21d34
leaq 0xdd0b(%rip), %rdx      # 0x22049
leaq 0xdd1e(%rip), %r8       # 0x22063
pushq $0x3
popq %rdi
movl $0x783, %ecx            # imm = 0x783
xorl %eax, %eax
callq 0x1662e
jmp 0x14855
xorl %r13d, %r13d
movq 0x28(%rsp), %r14
movq 0x10(%r14), %rax
movq %rax, 0x38(%rsp)
leaq 0x48(%rsp), %rbx
andq $0x0, 0x88(%rbx)
movl $0x88, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x32c0
movl %r13d, 0x88(%rbx)
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x38ef
testq %rax, %rax
je 0x14412
movq %rax, %rbp
addq $-0x40, %rax
movq -0x40(%rbp), %r15
cmpq %rax, %r15
je 0x14416
addq $-0x90, %r15
movq %r15, %rdi
callq 0x16511
movq 0x128(%r15), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %rbx
movl 0x34(%rsp), %ebp
je 0x143e4
callq 0x3460
andq $0x0, 0x128(%r15)
movq 0x50(%r14), %rdi
testq %rdi, %rdi
je 0x143f9
callq 0x3620
movq %rax, 0x128(%r15)
testl %ebp, %ebp
jle 0x14509
xorl %edi, %edi
callq 0x3320
movl %ebp, %ecx
addq %rax, %rcx
jmp 0x1450b
xorl %ebp, %ebp
jmp 0x1441d
addq $-0xd0, %rbp
orl $-0x1, 0xc(%rsp)
movq 0x1a2ff(%rip), %rdi     # 0x2e728
callq 0x33a0
testq %rax, %rax
je 0x144d0
movq %rax, %rbx
pushq $0x1
popq %rdi
movl $0x130, %esi            # imm = 0x130
callq 0x3250
testq %rax, %rax
je 0x14532
movq %rax, %r15
movq %rbx, 0x20(%rsp)
movq %r12, %rdi
testl %r13d, %r13d
je 0x1447f
movq 0x10(%rsp), %rax
cmpl $0x0, 0x18(%rax)
movq %r12, %rdi
jle 0x1447f
movl %r13d, 0x8(%r15)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
addq $0x8, %rdi
leaq 0xc(%rsp), %rsi
callq 0x179ae
movl %eax, %ebx
leal -0x3(%rbx), %eax
cmpl $-0x3, %eax
ja 0x14637
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x1468b
leaq 0xd886(%rip), %rsi      # 0x21d34
leaq 0xdf0c(%rip), %rdx      # 0x223c1
leaq 0xce61(%rip), %r8       # 0x2131d
pushq $0x3
popq %rdi
movl $0x4fa, %ecx            # imm = 0x4FA
xorl %eax, %eax
callq 0x1662e
jmp 0x1468b
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x1469d
leaq 0xd84d(%rip), %rsi      # 0x21d34
leaq 0xded3(%rip), %rdx      # 0x223c1
leaq 0xdedd(%rip), %r8       # 0x223d2
pushq $0x3
popq %rdi
movl $0x4e4, %ecx            # imm = 0x4E4
xorl %eax, %eax
callq 0x1662e
jmp 0x1469d
xorl %ecx, %ecx
movq %rcx, 0x60(%r14)
cmpl $0x2, 0x48(%r15)
jne 0x145aa
testl %r13d, %r13d
je 0x1456a
cmpl $0x0, 0x18(%rbx)
jle 0x1456a
movq %rbx, %rdi
movq %r15, %rsi
callq 0x149cb
jmp 0x14572
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x14562
leaq 0xd7ef(%rip), %rsi      # 0x21d34
leaq 0xde75(%rip), %rdx      # 0x223c1
leaq 0xd360(%rip), %r8       # 0x218b3
pushq $0x3
popq %rdi
movl $0x4ea, %ecx            # imm = 0x4EA
xorl %eax, %eax
callq 0x1662e
movq %rbx, %rdi
jmp 0x14698
movq %r15, %rdi
callq 0x155d6
testl %eax, %eax
je 0x145aa
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x14840
testl %r13d, %r13d
je 0x14815
cmpl $0x0, 0x18(%rbx)
leaq 0xdb0a(%rip), %rax      # 0x220a4
leaq 0xdb18(%rip), %r9       # 0x220b9
cmovgq %rax, %r9
jmp 0x1481c
leaq 0x30(%r15), %rdi
andq $0x0, 0x38(%r15)
movq %r14, %rsi
callq 0x137ea
testl %eax, %eax
jle 0x14706
leaq 0xb0(%r15), %rdi
pushq $0x1
popq %rsi
callq 0x75d3
andq $0x0, 0xd8(%r15)
andq $0x0, 0xf0(%r15)
movq %r15, 0xc8(%r15)
cmpl $0x11, 0x48(%r15)
jne 0x14600
movq %r15, %rdi
callq 0x1579d
testl %eax, %eax
js 0x147e3
movq 0x110(%rsp), %rax
movq %r15, 0x38(%r14)
movq 0x40(%rsp), %rcx
movq %rcx, 0x40(%r14)
movq %rax, 0x48(%r14)
movq 0x18(%rsp), %rax
movq %r15, 0x38(%rax)
movq %r14, 0xa0(%r15)
movq %rax, 0xa8(%r15)
xorl %ebx, %ebx
jmp 0x14855
movq %r15, %r14
addq $0x10, %r14
movl 0xc(%rsp), %esi
movq %r14, %rdi
callq 0x17f7d
testl %eax, %eax
je 0x14738
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x14682
leaq 0xd6cf(%rip), %rsi      # 0x21d34
leaq 0xdd55(%rip), %rdx      # 0x223c1
leaq 0xccbf(%rip), %r8       # 0x21332
pushq $0x3
popq %rdi
movl $0x501, %ecx            # imm = 0x501
xorl %eax, %eax
callq 0x1662e
movl 0xc(%rsp), %edi
callq 0x3680
movq %r15, %rdi
callq 0x3460
movq 0x20(%rsp), %rdi
callq 0x3200
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x146cd
leaq 0xd684(%rip), %rsi      # 0x21d34
leaq 0xdc9c(%rip), %rdx      # 0x22353
leaq 0xdca3(%rip), %r8       # 0x22361
pushq $0x3
popq %rdi
movl $0x550, %ecx            # imm = 0x550
xorl %eax, %eax
callq 0x1662e
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x14848
leaq 0xd650(%rip), %rsi      # 0x21d34
leaq 0xd95e(%rip), %rdx      # 0x22049
leaq 0xd98f(%rip), %r8       # 0x22081
pushq $0x3
popq %rdi
movl $0x78d, %ecx            # imm = 0x78D
xorl %eax, %eax
callq 0x1662e
jmp 0x14848
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x14840
leaq 0xd617(%rip), %rsi      # 0x21d34
leaq 0xd925(%rip), %rdx      # 0x22049
leaq 0xd9a1(%rip), %r8       # 0x220cc
pushq $0x3
popq %rdi
movl $0x7b7, %ecx            # imm = 0x7B7
jmp 0x1480c
movl %ebx, 0x48(%r15)
movq 0x20(%rsp), %rbx
movq %rbx, 0x78(%r15)
movq 0x10(%rsp), %rax
movq %rax, (%r15)
movq %r15, %rdi
callq 0x1610e
pushq $0x21
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x3160
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x3220
pushq $0x37
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq 0x38(%rsp), %rcx
callq 0x3160
movq %rax, %rbx
xorl %eax, %eax
callq 0x165f5
movl (%rax), %eax
testq %rbx, %rbx
je 0x14869
cmpl $0x8, %eax
jl 0x147c1
leaq 0xd590(%rip), %rsi      # 0x21d34
leaq 0xdc16(%rip), %rdx      # 0x223c1
leaq 0xdc53(%rip), %r8       # 0x22405
pushq $0x8
popq %rdi
movl $0x51c, %ecx            # imm = 0x51C
xorl %eax, %eax
callq 0x1662e
testq %rbp, %rbp
je 0x14894
movq %rbp, 0x88(%r15)
movq %r15, %rdi
callq 0x16593
movq 0x28(%rsp), %r14
jmp 0x143c2
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x14840
leaq 0xd53e(%rip), %rsi      # 0x21d34
leaq 0xd84c(%rip), %rdx      # 0x22049
leaq 0xd8e8(%rip), %r8       # 0x220ec
pushq $0x3
popq %rdi
movl $0x7c6, %ecx            # imm = 0x7C6
xorl %eax, %eax
callq 0x1662e
jmp 0x14840
leaq 0xd89d(%rip), %r9       # 0x220b9
leaq 0xd511(%rip), %rsi      # 0x21d34
leaq 0xd81f(%rip), %rdx      # 0x22049
leaq 0xd867(%rip), %r8       # 0x22098
pushq $0x3
popq %rdi
movl $0x7ac, %ecx            # imm = 0x7AC
xorl %eax, %eax
callq 0x1662e
movq %r15, %rdi
callq 0x15740
movq 0x18(%rsp), %rdi
callq 0x13901
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %eax
jl 0x14682
leaq 0xd4bb(%rip), %rsi      # 0x21d34
leaq 0xdb41(%rip), %rdx      # 0x223c1
leaq 0xdb5c(%rip), %r8       # 0x223e3
pushq $0x3
popq %rdi
movl $0x515, %ecx            # imm = 0x515
jmp 0x1467b
pushq $0x1
popq %rdi
movl $0xf8, %esi
callq 0x3250
testq %rax, %rax
je 0x14956
movq %rax, %rbp
addq $0xa0, %rax
movq %rax, 0xa0(%rbp)
movq %rax, 0xa8(%rbp)
leaq 0xb0(%rbp), %rax
movq %rax, 0xb0(%rbp)
movq %rax, 0xb8(%rbp)
leaq 0x90(%rbp), %rax
movq %rax, 0x90(%rbp)
movq %rax, 0x98(%rbp)
movl $0x88, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x32c0
movl %r13d, 0x88(%rbp)
movq %rbp, %rsi
addq $0xd0, %rsi
movq %rbp, 0xd0(%rbp)
movq 0x10(%rsp), %rdi
callq 0x378c
xorl %eax, %eax
callq 0x165f5
cmpl $0x8, (%rax)
jl 0x147ca
leaq 0xd400(%rip), %rsi      # 0x21d34
leaq 0xdade(%rip), %rdx      # 0x22419
leaq 0xdaed(%rip), %r8       # 0x2242f
pushq $0x8
popq %rdi
movl $0x533, %ecx            # imm = 0x533
xorl %eax, %eax
callq 0x1662e
jmp 0x147ca
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x14986
leaq 0xd3cb(%rip), %rsi      # 0x21d34
leaq 0xdaa9(%rip), %rdx      # 0x22419
leaq 0xcf3c(%rip), %r8       # 0x218b3
pushq $0x3
popq %rdi
movl $0x526, %ecx            # imm = 0x526
xorl %eax, %eax
callq 0x1662e
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x149b6
leaq 0xd39b(%rip), %rsi      # 0x21d34
leaq 0xd9b3(%rip), %rdx      # 0x22353
leaq 0xd9d4(%rip), %r8       # 0x2237b
pushq $0x3
popq %rdi
movl $0x557, %ecx            # imm = 0x557
xorl %eax, %eax
callq 0x1662e
movq %r14, %rdi
callq 0x1803b
movq %r15, %rdi
callq 0x3460
jmp 0x146cd