// File: /workspace/github_c_makefile_star2_O3/GangZhuo[P]dohclient/src/http.c
// Function: http_init
int http_init(const config_t* conf)
{
	const SSL_METHOD* method;
	SSL* ssl;
	STACK_OF(SSL_CIPHER)* active_ciphers;
	char ciphers[300];

	/* Whitelist of candidate ciphers. */
	static const char* const candidates[] = {
	  "AES128-GCM-SHA256", "AES128-SHA256", "AES256-SHA256", /* strong ciphers */
	  "AES128-SHA", "AES256-SHA", /* strong ciphers, also in older versions */
	  "RC4-SHA", "RC4-MD5", /* backwards compatibility, supposed to be weak */
	  "DES-CBC3-SHA", "DES-CBC3-MD5", /* more backwards compatibility */
	  NULL
	};

	if (SSL_library_init() < 0) {
		loge("Could not initialize the OpenSSL library !\n");
		return -1;
	}

	OpenSSL_add_all_algorithms();
	SSL_load_error_strings();
	ERR_load_BIO_strings();
	ERR_load_crypto_strings();

	method = SSLv23_client_method();

	if ((sslctx = SSL_CTX_new(method)) == NULL) {
		loge("Unable to create a new SSL context structure.\n");
		return -1;
	}

	SSL_CTX_set_options(sslctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION);

	if (SSL_CTX_set_cipher_list(sslctx, "HIGH:MEDIUM") != 1) {
		loge("SSL_CTX_set_cipher_list() error.\n");
		return -1;
	}

	/* Create a dummy SSL session to obtain the cipher list. */
	ssl = SSL_new(sslctx);
	if (ssl == NULL) {
		loge("SSL_new() error.\n");
		return -1;
	}

	active_ciphers = SSL_get_ciphers(ssl);
	if (active_ciphers == NULL) {
		loge("active_ciphers() error.\n");
		SSL_free(ssl);
		return -1;
	}

	/* Actually selected ciphers. */
	ciphers[0] = '\0';
	for (const char* const* c = candidates; *c; ++c) {
		for (int i = 0; i < sk_SSL_CIPHER_num(active_ciphers); ++i) {
			if (strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(active_ciphers, i)),
				*c) == 0) {
				if (*ciphers) {
					strcat(ciphers, ":");
				}
				strcat(ciphers, *c);
				break;
			}
		}
	}

	SSL_free(ssl);

	logv("cipher list: %s\n", ciphers);

	/* Apply final cipher list. */
	if (SSL_CTX_set_cipher_list(sslctx, ciphers) != 1) {
		loge("SSL_CTX_set_cipher_list() error.\n");
		return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
xorl %edi, %edi
xorl %esi, %esi
callq 0x32e0
testl %eax, %eax
js 0x14c68
movl $0xc, %edi
xorl %esi, %esi
callq 0x3190
movl $0x200002, %edi         # imm = 0x200002
xorl %esi, %esi
callq 0x32e0
callq 0x3100
movl $0x2, %edi
xorl %esi, %esi
callq 0x3190
callq 0x31c0
movq %rax, %rdi
callq 0x3500
movq %rax, 0x18c1e(%rip)     # 0x2d718
testq %rax, %rax
je 0x14ca1
movl $0x2020000, %esi        # imm = 0x2020000
movq %rax, %rdi
callq 0x3620
movq 0x18c01(%rip), %rdi     # 0x2d718
leaq 0xf4b5(%rip), %rsi      # 0x23fd3
callq 0x3360
cmpl $0x1, %eax
jne 0x14cd7
movq 0x18be5(%rip), %rdi     # 0x2d718
callq 0x3390
testq %rax, %rax
je 0x14d09
movq %rax, %rbx
movq %rax, %rdi
callq 0x3540
testq %rax, %rax
je 0x14d54
movq %rax, %r14
movq %rsp, %r15
movb $0x0, (%r15)
leaq 0x1816a(%rip), %r13     # 0x2ccd0
leaq 0xf393(%rip), %r12      # 0x23f00
movq %r14, %rdi
callq 0x31b0
testl %eax, %eax
jle 0x14bcb
xorl %ebp, %ebp
movq %r14, %rdi
movl %ebp, %esi
callq 0x3480
movq %rax, %rdi
callq 0x33c0
movq %rax, %rdi
movq %r12, %rsi
callq 0x34e0
testl %eax, %eax
je 0x14bac
incl %ebp
movq %r14, %rdi
callq 0x31b0
cmpl %eax, %ebp
jl 0x14b7b
jmp 0x14bcb
cmpb $0x0, (%rsp)
je 0x14bc0
movq %r15, %rdi
callq 0x3170
movw $0x3a, (%rsp,%rax)
movq %r15, %rdi
movq %r12, %rsi
callq 0x35d0
movq 0x8(%r13), %r12
addq $0x8, %r13
testq %r12, %r12
jne 0x14b6d
movq %rbx, %rdi
callq 0x31f0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x176e5
cmpl $0x7, (%rax)
jle 0x14c17
leaq 0xf13f(%rip), %rsi      # 0x23d34
leaq 0xf372(%rip), %rdx      # 0x23f6e
leaq 0xf429(%rip), %r8       # 0x2402c
movq %rsp, %r9
movl $0x8, %edi
movl $0x31b, %ecx            # imm = 0x31B
xorl %eax, %eax
callq 0x1771e
movq 0x18afa(%rip), %rdi     # 0x2d718
movq %rsp, %rsi
callq 0x3360
cmpl $0x1, %eax
je 0x14d40
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x14d40
leaq 0xf0e9(%rip), %rsi      # 0x23d34
leaq 0xf31c(%rip), %rdx      # 0x23f6e
leaq 0xf386(%rip), %r8       # 0x23fdf
movl $0x3, %edi
movl $0x31f, %ecx            # imm = 0x31F
jmp 0x14d39
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x14d40
leaq 0xf0b0(%rip), %rsi      # 0x23d34
leaq 0xf2e3(%rip), %rdx      # 0x23f6e
leaq 0xf2e6(%rip), %r8       # 0x23f78
movl $0x3, %edi
movl $0x2e5, %ecx            # imm = 0x2E5
jmp 0x14d39
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x14d40
leaq 0xf077(%rip), %rsi      # 0x23d34
leaq 0xf2aa(%rip), %rdx      # 0x23f6e
leaq 0xf2d9(%rip), %r8       # 0x23fa4
movl $0x3, %edi
movl $0x2f1, %ecx            # imm = 0x2F1
jmp 0x14d39
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x14d40
leaq 0xf045(%rip), %rsi      # 0x23d34
leaq 0xf278(%rip), %rdx      # 0x23f6e
leaq 0xf2e2(%rip), %r8       # 0x23fdf
movl $0x3, %edi
movl $0x2f8, %ecx            # imm = 0x2F8
jmp 0x14d39
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x14d40
leaq 0xf013(%rip), %rsi      # 0x23d34
leaq 0xf246(%rip), %rdx      # 0x23f6e
leaq 0xf2d2(%rip), %r8       # 0x24001
movl $0x3, %edi
movl $0x2ff, %ecx            # imm = 0x2FF
xorl %eax, %eax
callq 0x1771e
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x14d86
leaq 0xefcd(%rip), %rsi      # 0x23d34
leaq 0xf200(%rip), %rdx      # 0x23f6e
leaq 0xf29e(%rip), %r8       # 0x24013
movl $0x3, %edi
movl $0x305, %ecx            # imm = 0x305
xorl %eax, %eax
callq 0x1771e
movq %rbx, %rdi
callq 0x31f0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x14d40