// File: /workspace/github_c_makefile_star2_O1/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 0x151fc
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, 0x1868a(%rip)     # 0x2d718
testq %rax, %rax
je 0x15235
movl $0x2020000, %esi        # imm = 0x2020000
movq %rax, %rdi
callq 0x3620
movq 0x1866d(%rip), %rdi     # 0x2d718
leaq 0xef15(%rip), %rsi      # 0x23fc7
callq 0x3360
cmpl $0x1, %eax
jne 0x1526b
movq 0x18651(%rip), %rdi     # 0x2d718
callq 0x3390
testq %rax, %rax
je 0x1529d
movq %rax, %rbx
movq %rax, %rdi
callq 0x3540
testq %rax, %rax
je 0x152e8
movq %rax, %r14
movq %rsp, %r15
movb $0x0, (%r15)
leaq 0x17bd6(%rip), %r13     # 0x2ccd0
leaq 0xedf3(%rip), %r12      # 0x23ef4
movq %r14, %rdi
callq 0x31b0
testl %eax, %eax
jle 0x1515f
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 0x15140
incl %ebp
movq %r14, %rdi
callq 0x31b0
cmpl %eax, %ebp
jl 0x1510f
jmp 0x1515f
cmpb $0x0, (%rsp)
je 0x15154
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 0x15101
movq %rbx, %rdi
callq 0x31f0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x17d59
cmpl $0x7, (%rax)
jle 0x151ab
leaq 0xeb9f(%rip), %rsi      # 0x23d28
leaq 0xedd2(%rip), %rdx      # 0x23f62
leaq 0xee89(%rip), %r8       # 0x24020
movq %rsp, %r9
movl $0x8, %edi
movl $0x31b, %ecx            # imm = 0x31B
xorl %eax, %eax
callq 0x17d92
movq 0x18566(%rip), %rdi     # 0x2d718
movq %rsp, %rsi
callq 0x3360
cmpl $0x1, %eax
je 0x152d4
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x152d4
leaq 0xeb49(%rip), %rsi      # 0x23d28
leaq 0xed7c(%rip), %rdx      # 0x23f62
leaq 0xede6(%rip), %r8       # 0x23fd3
movl $0x3, %edi
movl $0x31f, %ecx            # imm = 0x31F
jmp 0x152cd
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x152d4
leaq 0xeb10(%rip), %rsi      # 0x23d28
leaq 0xed43(%rip), %rdx      # 0x23f62
leaq 0xed46(%rip), %r8       # 0x23f6c
movl $0x3, %edi
movl $0x2e5, %ecx            # imm = 0x2E5
jmp 0x152cd
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x152d4
leaq 0xead7(%rip), %rsi      # 0x23d28
leaq 0xed0a(%rip), %rdx      # 0x23f62
leaq 0xed39(%rip), %r8       # 0x23f98
movl $0x3, %edi
movl $0x2f1, %ecx            # imm = 0x2F1
jmp 0x152cd
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x152d4
leaq 0xeaa5(%rip), %rsi      # 0x23d28
leaq 0xecd8(%rip), %rdx      # 0x23f62
leaq 0xed42(%rip), %r8       # 0x23fd3
movl $0x3, %edi
movl $0x2f8, %ecx            # imm = 0x2F8
jmp 0x152cd
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x152d4
leaq 0xea73(%rip), %rsi      # 0x23d28
leaq 0xeca6(%rip), %rdx      # 0x23f62
leaq 0xed32(%rip), %r8       # 0x23ff5
movl $0x3, %edi
movl $0x2ff, %ecx            # imm = 0x2FF
xorl %eax, %eax
callq 0x17d92
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 0x17d59
cmpl $0x3, (%rax)
jl 0x1531a
leaq 0xea2d(%rip), %rsi      # 0x23d28
leaq 0xec60(%rip), %rdx      # 0x23f62
leaq 0xecfe(%rip), %r8       # 0x24007
movl $0x3, %edi
movl $0x305, %ecx            # imm = 0x305
xorl %eax, %eax
callq 0x17d92
movq %rbx, %rdi
callq 0x31f0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x152d4