// File: /workspace/github_c_makefile_star2_O2/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 0x32f0
testl %eax, %eax
js 0x13e9e
pushq $0xc
popq %rdi
xorl %esi, %esi
callq 0x31a0
movl $0x200002, %edi         # imm = 0x200002
xorl %esi, %esi
callq 0x32f0
callq 0x3100
pushq $0x2
popq %rdi
xorl %esi, %esi
callq 0x31a0
callq 0x31d0
movq %rax, %rdi
callq 0x3510
movq %rax, 0x1a959(%rip)     # 0x2e728
testq %rax, %rax
je 0x13ed3
movl $0x2020000, %esi        # imm = 0x2020000
movq %rax, %rdi
callq 0x3630
movq 0x1a93c(%rip), %rdi     # 0x2e728
leaq 0xe1e0(%rip), %rsi      # 0x21fd3
callq 0x3370
cmpl $0x1, %eax
jne 0x13f08
movq 0x1a920(%rip), %rdi     # 0x2e728
callq 0x33a0
testq %rax, %rax
je 0x13fbc
movq %rax, %rbx
movq %rax, %rdi
callq 0x3550
testq %rax, %rax
je 0x14003
movq %rax, %r14
movq %rsp, %r15
movb $0x0, (%r15)
leaq 0x19ee5(%rip), %r13     # 0x2dd20
movq (%r13), %r12
testq %r12, %r12
je 0x13f3d
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x31c0
cmpl %eax, %ebp
jge 0x13e98
movq %r14, %rdi
movl %ebp, %esi
callq 0x3490
movq %rax, %rdi
callq 0x33d0
movq %rax, %rdi
movq %r12, %rsi
callq 0x34f0
incl %ebp
testl %eax, %eax
jne 0x13e4a
cmpb $0x0, (%rsp)
je 0x13e8d
movq %r15, %rdi
callq 0x3170
movw $0x3a, (%rsp,%rax)
movq %r15, %rdi
movq %r12, %rsi
callq 0x35e0
addq $0x8, %r13
jmp 0x13e3b
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbx
cmpl $0x3, (%rax)
jl 0x13fef
leaq 0xde7c(%rip), %rsi      # 0x21d34
leaq 0xe0af(%rip), %rdx      # 0x21f6e
leaq 0xe0b2(%rip), %r8       # 0x21f78
pushq $0x3
popq %rdi
movl $0x2e5, %ecx            # imm = 0x2E5
jmp 0x13fe8
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbx
cmpl $0x3, (%rax)
jl 0x13fef
leaq 0xde47(%rip), %rsi      # 0x21d34
leaq 0xe07a(%rip), %rdx      # 0x21f6e
leaq 0xe0a9(%rip), %r8       # 0x21fa4
pushq $0x3
popq %rdi
movl $0x2f1, %ecx            # imm = 0x2F1
jmp 0x13fe8
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbx
cmpl $0x3, (%rax)
jl 0x13fef
leaq 0xde12(%rip), %rsi      # 0x21d34
leaq 0xe045(%rip), %rdx      # 0x21f6e
leaq 0xe0af(%rip), %r8       # 0x21fdf
pushq $0x3
popq %rdi
movl $0x2f8, %ecx            # imm = 0x2F8
jmp 0x13fe8
movq %rbx, %rdi
callq 0x3200
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jle 0x13f7a
leaq 0xddda(%rip), %rsi      # 0x21d34
leaq 0xe00d(%rip), %rdx      # 0x21f6e
leaq 0xe0c4(%rip), %r8       # 0x2202c
pushq $0x8
popq %rdi
movq %rsp, %r9
movl $0x31b, %ecx            # imm = 0x31B
xorl %eax, %eax
callq 0x1662e
movq 0x1a7a7(%rip), %rdi     # 0x2e728
movq %rsp, %rsi
callq 0x3370
cmpl $0x1, %eax
je 0x13fef
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbx
cmpl $0x3, (%rax)
jl 0x13fef
leaq 0xdd90(%rip), %rsi      # 0x21d34
leaq 0xdfc3(%rip), %rdx      # 0x21f6e
leaq 0xe02d(%rip), %r8       # 0x21fdf
pushq $0x3
popq %rdi
movl $0x31f, %ecx            # imm = 0x31F
jmp 0x13fe8
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbx
cmpl $0x3, (%rax)
jl 0x13fef
leaq 0xdd62(%rip), %rsi      # 0x21d34
leaq 0xdf95(%rip), %rdx      # 0x21f6e
leaq 0xe021(%rip), %r8       # 0x22001
pushq $0x3
popq %rdi
movl $0x2ff, %ecx            # imm = 0x2FF
xorl %eax, %eax
callq 0x1662e
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 0x165f5
cmpl $0x3, (%rax)
jl 0x14033
leaq 0xdd1e(%rip), %rsi      # 0x21d34
leaq 0xdf51(%rip), %rdx      # 0x21f6e
leaq 0xdfef(%rip), %r8       # 0x22013
pushq $0x3
popq %rdi
movl $0x305, %ecx            # imm = 0x305
xorl %eax, %eax
callq 0x1662e
movq %rbx, %rdi
callq 0x3200
pushq $-0x1
popq %rbx
jmp 0x13fef