// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/io/drivers/driver_https.cpp
// Function: smooth::IO::DriverHTTPS::DriverHTTPS(smooth::String const&, int, smooth::String const&, int, smooth::String const&, smooth::String const&)
S::IO::DriverHTTPS::DriverHTTPS(const String &proxy, Int httpPort, const String &hostName, Int port, const String &uname, const String &passwd) : Driver()
{
	closeStream = False;

	stream	    = -1;
	size	    = -1;

	if (hostName.Length() > 255) { lastError = IO_ERROR_BADPARAM; return; }

	/* Open TCP/IP socket.
	 */
	stream = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	if (stream == (unsigned) (~0)) { lastError = IO_ERROR_UNEXPECTED; return; }

	closeStream = True;

	/* Get proxy hostname.
	 */
	hostent		*host = gethostbyname(proxy);

	if (host == NIL) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

	/* Connect to proxy.
	 */
	sockaddr_in	 saddr;

	saddr.sin_family = AF_INET;
	saddr.sin_addr	 = *((in_addr *) *host->h_addr_list);
	saddr.sin_port	 = htons((short) httpPort);

	memset(&saddr.sin_zero, 0, sizeof(saddr.sin_zero));

	if (connect(stream, (sockaddr *) &saddr, sizeof(struct sockaddr)) == -1) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

	/* Send connect request.
	 */
	String	 connect = String("CONNECT ").Append(hostName).Append(":").Append(String::FromInt(port)).Append(" HTTP/1.1\n");

	if (uname != NIL) connect.Append("Proxy-authentication: Basic ").Append(String(String(uname).Append(":").Append(passwd)).EncodeBase64()).Append("\n");

	connect.Append("\n");

	if (send(stream, (char *) connect, connect.Length(), 0) < connect.Length()) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

	/* Receive answer.
	 */
	String	 answer;
	char	 c[2] = { 0, 0 };

	while (!(answer.EndsWith("\n\n") || answer.EndsWith("\r\n\r\n")))
	{
		if (recv(stream, c, 1, 0) <= 0) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

		answer.Append(c);
	}

	/* Check if connect attempt was successful.
	 */
	if (answer.SubString(9, 3) != "200") { Close(); lastError = IO_ERROR_UNEXPECTED; return; }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, %r14
movl %r8d, %ebp
movq %rcx, %r15
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, %rbx
callq 0x58560
movq 0xcb389(%rip), %rax     # 0x16bc40
addq $0x10, %rax
movq %rax, (%rbx)
movb $0x0, 0x3c(%rbx)
movl $0xffffffff, 0x38(%rbx) # imm = 0xFFFFFFFF
movq $-0x1, 0x8(%rbx)
movq %r15, %rdi
callq 0x57180
cmpl $0x100, %eax            # imm = 0x100
jl 0xa08ec
movl $0x2, 0x18(%rbx)
jmp 0xa0cb8
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x56660
movl %eax, 0x38(%rbx)
cmpl $-0x1, %eax
je 0xa0b9b
movb $0x1, 0x3c(%rbx)
movq %r13, %rdi
callq 0x585e0
movq %rax, %rdi
callq 0x56530
testq %rax, %rax
je 0xa0b87
leaq 0xa8(%rsp), %rsi
movw $0x2, (%rsi)
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
rolw $0x8, %r12w
movl %eax, 0x4(%rsi)
movw %r12w, 0x2(%rsi)
movq $0x0, 0x8(%rsi)
movl 0x38(%rbx), %edi
movl $0x10, %edx
callq 0x56230
cmpl $-0x1, %eax
je 0xa0b92
leaq 0x71084(%rip), %rsi     # 0x1119f5
movq %rsp, %rdi
callq 0x579f0
movq %rsp, %rdi
movq %r15, %rsi
callq 0x562f0
movq %rax, %r15
leaq 0x52759(%rip), %rsi     # 0xf30e7
leaq 0x18(%rsp), %rdi
callq 0x579f0
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
movq %rax, %r15
movslq %ebp, %rsi
leaq 0x30(%rsp), %rdi
callq 0x56cf0
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
movq %rax, %r15
leaq 0x71032(%rip), %rsi     # 0x1119fe
leaq 0x48(%rsp), %rdi
callq 0x579f0
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x570b0
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
movq %rsp, %rdi
callq 0x59200
movq %r14, %rdi
xorl %esi, %esi
callq 0x56bd0
testb %al, %al
je 0xa0b11
leaq 0x70fda(%rip), %rsi     # 0x111a09
movq %rsp, %rdi
callq 0x579f0
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x562f0
movq %rax, %r15
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x5268c(%rip), %rsi     # 0xf30e7
leaq 0x90(%rsp), %rdi
callq 0x579f0
leaq 0x48(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x562f0
movq 0xf0(%rsp), %rsi
movq %rax, %rdi
callq 0x562f0
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x570b0
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x55860
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
movq %rax, %r14
leaq 0x70f6a(%rip), %rsi     # 0x111a27
leaq 0x78(%rsp), %rdi
callq 0x579f0
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x562f0
leaq 0x78(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
leaq 0x90(%rsp), %rdi
callq 0x59200
leaq 0x48(%rsp), %rdi
callq 0x59200
movq %rsp, %rdi
callq 0x59200
leaq 0x70f0f(%rip), %rsi     # 0x111a27
movq %rsp, %rdi
callq 0x579f0
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x562f0
movq %rsp, %rdi
callq 0x59200
movl 0x38(%rbx), %ebp
leaq 0x60(%rsp), %rdi
callq 0x585e0
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x57180
movslq %eax, %rdx
movl %ebp, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x56130
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x57180
cltq
cmpq %rax, %r14
jge 0xa0ba7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
jmp 0xa0cae
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
jmp 0xa0b9b
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
jmp 0xa0cb8
movq %rsp, %rdi
xorl %esi, %esi
callq 0x58e20
leaq 0x48(%rsp), %r14
movw $0x0, (%r14)
leaq 0x18(%rsp), %r12
movq %rsp, %r13
leaq 0x30(%rsp), %rbp
movq %r12, %rdi
leaq 0x70e53(%rip), %rsi     # 0x111a26
callq 0x579f0
movq %r13, %rdi
movq %r12, %rsi
callq 0x58b10
testb %al, %al
jne 0xa0c53
movq %rbp, %rdi
leaq 0x71775(%rip), %rsi     # 0x112366
callq 0x579f0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x58b10
movl %eax, %r15d
movq %rbp, %rdi
callq 0x59200
movq %r12, %rdi
callq 0x59200
testb %r15b, %r15b
jne 0xa0c5d
movl 0x38(%rbx), %edi
movl $0x1, %edx
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x582d0
testq %rax, %rax
jle 0xa0c96
movq %r12, %rdi
movq %r14, %rsi
callq 0x579f0
movq %r13, %rdi
movq %r12, %rsi
callq 0x562f0
movq %r12, %rdi
callq 0x59200
jmp 0xa0bc9
leaq 0x18(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
movl $0x9, %edx
movl $0x3, %ecx
callq 0x58f50
leaq 0x70dae(%rip), %rsi     # 0x111a29
leaq 0x18(%rsp), %rdi
callq 0x590a0
movl %eax, %ebp
leaq 0x18(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
je 0xa0ca6
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
movq %rsp, %rdi
callq 0x59200
leaq 0x60(%rsp), %rdi
callq 0x59200
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa0da9
jmp 0xa0d9a
jmp 0xa0da9
jmp 0xa0d95
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x59200
jmp 0xa0cf2
jmp 0xa0cef
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x59200
jmp 0xa0d01
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x59200
jmp 0xa0d42
movq %rax, %r14
jmp 0xa0d4f
jmp 0xa0da9
jmp 0xa0da9
jmp 0xa0d95
jmp 0xa0da9
jmp 0xa0d95
jmp 0xa0d27
movq %rax, %r14
jmp 0xa0d63
jmp 0xa0d2e
movq %rax, %r14
jmp 0xa0d6d
jmp 0xa0d35
movq %rax, %r14
jmp 0xa0d77
jmp 0xa0dc2
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x59200
leaq 0x48(%rsp), %rdi
jmp 0xa0da2
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
movq %rsp, %rdi
jmp 0xa0db9
jmp 0xa0dc2
jmp 0xa0da9
jmp 0xa0d9a
jmp 0xa0da9
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x59200
jmp 0xa0d9d
jmp 0xa0d9a
movq %rax, %r14
jmp 0xa0db4
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x59200
jmp 0xa0dac
movq %rax, %r14
movq %rsp, %rdi
callq 0x59200
leaq 0x60(%rsp), %rdi
callq 0x59200
jmp 0xa0dc5
jmp 0xa0dc2
movq %rax, %r14
movq %rbx, %rdi
callq 0x56c30
movq %r14, %rdi
callq 0x57090
nop