// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/http.c
// Function: http_conn_create
static http_conn_t* http_conn_create(http_ctx_t* ctx, const char* host, sockaddr_t* addr, int use_proxy)
{
	http_conn_t* conn = NULL;
	sock_t sock = -1;
	conn_status cs;
	SSL* ssl;

	ssl = SSL_new(sslctx);
	if (!ssl) {
		loge("SSL_new() error\n");
		return NULL;
	}

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

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

	if (use_proxy && ctx->proxy_num > 0) {
		conn->use_proxy = use_proxy;
		conn->proxy_index = 0;
		cs = tcp_connect(&ctx->proxies->addr, &sock);
	}
	else {
		cs = tcp_connect(addr, &sock);
	}
	if (cs != cs_connected && cs != cs_connecting) {
		loge("tcp_connect() error\n");
		free(conn);
		SSL_free(ssl);
		return NULL;
	}

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

	conn->conn.status = cs;

	conn->ssl = ssl;
	conn->http_ctx = ctx;

	/* set expire */
	http_update_expire(conn);

	SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
	SSL_set_fd(ssl, sock);

	/* Enable the ServerNameIndication extension */
	if (!SSL_set_tlsext_host_name(ssl, host)) {
		loge("SSL_set_tlsext_host_name() error\n");
		close(sock);
		free(conn);
		SSL_free(ssl);
		return NULL;
	}

	logv("http_conn_create()\n");

	return conn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movq 0x1f08b(%rip), %rdi     # 0x41c08
callq 0x33b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x22bd0
jmp 0x22b8f
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x22bc1
movl $0x3, %edi
leaq 0x14875(%rip), %rsi     # 0x3741c
leaq 0x14f26(%rip), %rdx     # 0x37ad4
movl $0x4e4, %ecx            # imm = 0x4E4
leaq 0x14f2b(%rip), %r8      # 0x37ae5
movb $0x0, %al
callq 0x243b0
jmp 0x22bc3
movq $0x0, -0x8(%rbp)
jmp 0x22e64
movl $0x130, %edi            # imm = 0x130
callq 0x34d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x22c31
jmp 0x22be7
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x22c19
movl $0x3, %edi
leaq 0x1481d(%rip), %rsi     # 0x3741c
leaq 0x14ece(%rip), %rdx     # 0x37ad4
movl $0x4ea, %ecx            # imm = 0x4EA
leaq 0x14285(%rip), %r8      # 0x36e97
movb $0x0, %al
callq 0x243b0
jmp 0x22c1b
movq -0x40(%rbp), %rdi
callq 0x3210
movq $0x0, -0x8(%rbp)
jmp 0x22e64
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x130, %edx            # imm = 0x130
callq 0x3200
cmpl $0x0, -0x24(%rbp)
je 0x22c80
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x22c80
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x8, %rdi
leaq -0x34(%rbp), %rsi
callq 0x262d0
movl %eax, -0x38(%rbp)
jmp 0x22c90
movq -0x20(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x262d0
movl %eax, -0x38(%rbp)
cmpl $0x2, -0x38(%rbp)
je 0x22cf1
cmpl $0x1, -0x38(%rbp)
je 0x22cf1
jmp 0x22c9e
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x22cd0
movl $0x3, %edi
leaq 0x14766(%rip), %rsi     # 0x3741c
leaq 0x14e17(%rip), %rdx     # 0x37ad4
movl $0x4fa, %ecx            # imm = 0x4FA
leaq 0x13c38(%rip), %r8      # 0x36901
movb $0x0, %al
callq 0x243b0
jmp 0x22cd2
movq -0x30(%rbp), %rdi
callq 0x3460
movq -0x40(%rbp), %rdi
callq 0x3210
movq $0x0, -0x8(%rbp)
jmp 0x22e64
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
movl -0x34(%rbp), %esi
callq 0x26ae0
cmpl $0x0, %eax
je 0x22d63
jmp 0x22d08
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x22d3a
movl $0x3, %edi
leaq 0x146fc(%rip), %rsi     # 0x3741c
leaq 0x14dad(%rip), %rdx     # 0x37ad4
movl $0x501, %ecx            # imm = 0x501
leaq 0x13be3(%rip), %r8      # 0x36916
movb $0x0, %al
callq 0x243b0
jmp 0x22d3c
movl -0x34(%rbp), %edi
callq 0x3680
movq -0x30(%rbp), %rdi
callq 0x3460
movq -0x40(%rbp), %rdi
callq 0x3210
movq $0x0, -0x8(%rbp)
jmp 0x22e64
movl -0x38(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
callq 0x22360
movq -0x40(%rbp), %rdi
movl $0x21, %esi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3170
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x3230
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x37, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3170
cmpq $0x0, %rax
jne 0x22e26
jmp 0x22dce
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x22e00
movl $0x3, %edi
leaq 0x14636(%rip), %rsi     # 0x3741c
leaq 0x14ce7(%rip), %rdx     # 0x37ad4
movl $0x515, %ecx            # imm = 0x515
leaq 0x14cfd(%rip), %r8      # 0x37af6
movb $0x0, %al
callq 0x243b0
jmp 0x22e02
movl -0x34(%rbp), %edi
callq 0x3680
movq -0x30(%rbp), %rdi
callq 0x3460
movq -0x40(%rbp), %rdi
callq 0x3210
movq $0x0, -0x8(%rbp)
jmp 0x22e64
jmp 0x22e28
movb $0x0, %al
callq 0x242d0
cmpl $0x8, (%rax)
jl 0x22e5a
movl $0x8, %edi
leaq 0x145dc(%rip), %rsi     # 0x3741c
leaq 0x14c8d(%rip), %rdx     # 0x37ad4
movl $0x51c, %ecx            # imm = 0x51C
leaq 0x14cc5(%rip), %r8      # 0x37b18
movb $0x0, %al
callq 0x243b0
jmp 0x22e5c
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop