// File: zeeev[P]DASVC/bamtools/src/api/internal/io/BamHttp_p.cpp
// Function: BamTools::Internal::BamHttp::SendHeadRequest()
bool BamHttp::SendHeadRequest(void) {

    // ensure clean slate
    ClearResponse();
    if ( m_request )
        delete m_request;
    m_socket->ClearBuffer();

    // make sure we're connected
    if ( !EnsureSocketConnection() )
        return false;

    // create request
    m_request = new HttpRequestHeader(HEAD_METHOD, m_filename);
    m_request->SetField(HOST_HEADER, m_hostname);

    // send request
    const string requestHeader = m_request->ToString();
    const size_t headerSize    = requestHeader.size();
    if ( WriteToSocket(requestHeader.c_str(), headerSize) != headerSize ) {
        SetErrorString("BamHttp::SendHeadRequest", m_socket->GetErrorString());
        return false;
    }

    m_socket->ClearBuffer();

    // wait for response from server
    if ( !ReceiveResponse() ) {
        SetErrorString("BamHttp::SendHeadRequest", m_socket->GetErrorString());
        Close();
        return false;
    }
    BT_ASSERT_X(m_response, "BamHttp::SendHeadRequest : null HttpResponse");
    BT_ASSERT_X(m_response->IsValid(), "BamHttp::SendHeadRequest : invalid HttpResponse");

    // get content length if available
    if ( m_response->ContainsKey(CONTENT_LENGTH_HEADER) ) {
        const string contentLengthString = m_response->GetValue(CONTENT_LENGTH_HEADER);
        m_fileEndPosition = atoi( contentLengthString.c_str() ) - 1;
    }

    // return whether we found any errors
    return m_socket->GetError() == TcpSocket::NoError;
}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x158(%rsp)
movq 0x158(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x73f50
movq 0x60(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0xca594
movq 0x60(%rsp), %rax
movq 0x98(%rax), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, %rax
je 0xca592
movq 0x58(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xca594
movq 0x60(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x7b680
movq 0x60(%rsp), %rdi
callq 0x782d0
testb $0x1, %al
jne 0xca5bd
movb $0x0, 0x167(%rsp)
jmp 0xcaa4d
movl $0x88, %edi
callq 0x76970
movq 0x60(%rsp), %rdx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x50(%rsp)
addq $0x78, %rdx
leaq 0x4e7d6(%rip), %rsi     # 0x118db8
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x711c0
jmp 0xca5f2
movq 0x60(%rsp), %rdx
movq 0x50(%rsp), %rax
movq %rax, 0x98(%rdx)
movq 0x98(%rdx), %rdi
addq $0x38, %rdx
leaq 0x4e7c3(%rip), %rsi     # 0x118dd8
callq 0x78710
movq 0x60(%rsp), %rax
movq 0x98(%rax), %rsi
movq (%rsi), %rax
movq 0x10(%rax), %rax
leaq 0x128(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq *%rax
movq 0x40(%rsp), %rdi
callq 0x74cd0
movq %rax, 0x48(%rsp)
jmp 0xca64d
movq 0x48(%rsp), %rax
movq %rax, 0x120(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x73020
movq %rax, 0x38(%rsp)
jmp 0xca66e
movq 0x38(%rsp), %rsi
movq 0x60(%rsp), %rdi
movl 0x120(%rsp), %edx
callq 0x74c10
movq %rax, 0x30(%rsp)
jmp 0xca68b
movq 0x30(%rsp), %rax
cmpq 0x120(%rsp), %rax
je 0xca7f2
leaq 0xff(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x7b5f0
movq 0x28(%rsp), %rdx
leaq 0x217ea(%rip), %rsi     # 0xebea6
leaq 0x100(%rsp), %rdi
callq 0x78e70
jmp 0xca6cb
movq 0x60(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x77a20
jmp 0xca6e3
movq 0x60(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x7ab60
jmp 0xca6ff
leaq 0xd8(%rsp), %rdi
callq 0x7cce8
jmp 0xca70e
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xca71d
leaq 0xff(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x167(%rsp)
movl $0x1, 0xd4(%rsp)
jmp 0xcaa2d
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
callq 0x764d0
jmp 0xcaa5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xcaa3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xca7e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xca7cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x7cce8
jmp 0xca7cd
jmp 0xca7cf
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xca7de
jmp 0xca7e0
leaq 0xff(%rsp), %rdi
callq 0x76f80
jmp 0xcaa3c
movq 0x60(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x7b680
jmp 0xca802
movq 0x60(%rsp), %rdi
callq 0x7c1b0
movb %al, 0x27(%rsp)
jmp 0xca812
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0xca948
jmp 0xca820
leaq 0xaf(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x21668(%rip), %rsi     # 0xebea6
leaq 0xb0(%rsp), %rdi
callq 0x78e70
jmp 0xca84d
movq 0x60(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x88(%rsp), %rdi
callq 0x77a20
jmp 0xca865
movq 0x60(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x7ab60
jmp 0xca881
leaq 0x88(%rsp), %rdi
callq 0x7cce8
jmp 0xca890
leaq 0xb0(%rsp), %rdi
callq 0x7cce8
jmp 0xca89f
leaq 0xaf(%rsp), %rdi
callq 0x76f80
movq 0x60(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xca8bc
movb $0x0, 0x167(%rsp)
movl $0x1, 0xd4(%rsp)
jmp 0xcaa2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xca936
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xca925
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x7cce8
jmp 0xca923
jmp 0xca925
leaq 0xb0(%rsp), %rdi
callq 0x7cce8
jmp 0xca934
jmp 0xca936
leaq 0xaf(%rsp), %rdi
callq 0x76f80
jmp 0xcaa3c
callq 0x761a0
jmp 0xca94f
callq 0x761a0
jmp 0xca956
movq 0x60(%rsp), %rax
movq 0xa0(%rax), %rdi
leaq 0x4e4cf(%rip), %rsi     # 0x118e38
callq 0x71430
movb %al, 0x17(%rsp)
jmp 0xca974
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0xca97e
jmp 0xca9fb
movq 0x60(%rsp), %rax
movq 0xa0(%rax), %rsi
leaq 0x4e4a7(%rip), %rdx     # 0x118e38
leaq 0x68(%rsp), %rdi
callq 0x71a20
jmp 0xca99d
leaq 0x68(%rsp), %rdi
callq 0x73020
movq %rax, 0x8(%rsp)
jmp 0xca9ae
movq 0x8(%rsp), %rdi
callq 0x7a180
movl %eax, %ecx
movq 0x60(%rsp), %rax
decl %ecx
movslq %ecx, %rcx
movq %rcx, 0xb8(%rax)
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xca9d7
jmp 0xca9fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xca9f9
jmp 0xcaa3c
movq 0x60(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x76a10
movl %eax, 0x4(%rsp)
jmp 0xcaa0f
movl 0x4(%rsp), %eax
cmpl $-0x2, %eax
sete %al
andb $0x1, %al
movb %al, 0x167(%rsp)
movl $0x1, 0xd4(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x7cce8
jmp 0xcaa4d
leaq 0x128(%rsp), %rdi
callq 0x7cce8
jmp 0xcaa4b
jmp 0xcaa5e
movb 0x167(%rsp), %al
andb $0x1, %al
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x150(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)