// File: zeeev[P]DASVC/bamtools/src/api/internal/io/BamHttp_p.cpp
// Function: BamTools::Internal::BamHttp::SendGetRequest(unsigned long)
bool BamHttp::SendGetRequest(const size_t numBytes) {

    // clear previous data
    ClearResponse();
    if ( m_request )
        delete m_request;
    m_socket->ClearBuffer();

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

    // create range string
    const int64_t endPosition = m_filePosition + std::max(static_cast<size_t>(0x10000), numBytes);
    stringstream range("");
    range << BYTES_PREFIX << m_filePosition << '-' << endPosition;

    // create request
    m_request = new HttpRequestHeader(GET_METHOD, m_filename);
    m_request->SetField(HOST_HEADER,  m_hostname);
    m_request->SetField(RANGE_HEADER, range.str());

    // 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;
    }

    // ensure clean buffer
    m_socket->ClearBuffer();

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

    // check response status code
    const int statusCode = m_response->GetStatusCode();
    switch ( statusCode ) {

        // ranged response, as requested
        case 206 :
            // get content length if available
            if ( m_response->ContainsKey(CONTENT_LENGTH_HEADER) ) {
                const string contentLengthString = m_response->GetValue(CONTENT_LENGTH_HEADER);
                m_rangeEndPosition = m_filePosition + atoi( contentLengthString.c_str() );
            }
            return true;

        // full contents, not range
        case 200 :
        {
            // skip up to current file position
            RaiiBuffer tmp(0x8000);
            int64_t numBytesRead = 0;
            while ( numBytesRead < m_filePosition ) {

                // read data from response
                const int64_t remaining = m_filePosition - numBytesRead;
                const size_t bytesToRead = static_cast<size_t>( (remaining > 0x8000) ? 0x8000 : remaining );
                const int64_t socketBytesRead = ReadFromSocket(tmp.Buffer, bytesToRead);

                // if error
                if ( socketBytesRead < 0 ) {
                    SetErrorString("BamHttp::SendGetRequest", m_socket->GetErrorString());
                    Close();
                    return false;
                }

                // else if EOF
                else if ( socketBytesRead == 0 && m_socket->BufferBytesAvailable() == 0 )
                    break;

                // update byte counter
                numBytesRead += socketBytesRead;
            }

            // return success
            return ( numBytesRead == m_filePosition);
        }

        // any other status codes
        default:
            break;
    }

    // fail on unexpected status code
    SetErrorString("BamHttp::SendGetRequest", "unsupported status code in response");
    Close();
    return false;
}

// Assembly:
subq $0x488, %rsp            # imm = 0x488
movq %rdi, 0x478(%rsp)
movq %rsi, 0x470(%rsp)
movq 0x478(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x73f50
movq 0xc8(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0xcb21b
movq 0xc8(%rsp), %rax
movq 0x98(%rax), %rax
movq %rax, 0xc0(%rsp)
cmpq $0x0, %rax
je 0xcb219
movq 0xc0(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xcb21b
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x7b680
movq 0xc8(%rsp), %rdi
callq 0x782d0
testb $0x1, %al
jne 0xcb24a
movb $0x0, 0x487(%rsp)
jmp 0xcbdde
movq 0xc8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0xb0(%rsp)
movq $0x10000, 0x460(%rsp) # imm = 0x10000
leaq 0x460(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x78ca0
movq %rax, %rcx
movq 0xb0(%rsp), %rax
movq (%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x468(%rsp)
leaq 0x2b7(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x7b5f0
movq 0xb8(%rsp), %rdx
leaq 0x1fe1d(%rip), %rsi     # 0xeb0dc
leaq 0x2b8(%rsp), %rdi
callq 0x78e70
jmp 0xcb2ce
movl $0x10, %edi
movl $0x8, %esi
callq 0x7b8d0
movl %eax, 0xac(%rsp)
jmp 0xcb2e6
movl 0xac(%rsp), %edx
leaq 0x2d8(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
callq 0x7a4b0
jmp 0xcb304
leaq 0x2b8(%rsp), %rdi
callq 0x7cce8
jmp 0xcb313
leaq 0x2b7(%rsp), %rdi
callq 0x76f80
leaq 0x2e8(%rsp), %rdi
leaq 0x4dae9(%rip), %rsi     # 0x118e18
callq 0x75e40
movq %rax, 0xa0(%rsp)
jmp 0xcb33e
movq 0xa0(%rsp), %rdi
movq 0xc8(%rsp), %rax
movq 0xb0(%rax), %rsi
callq 0x7ba30
movq %rax, 0x98(%rsp)
jmp 0xcb364
movq 0x98(%rsp), %rdi
movl $0x2d, %esi
callq 0x779c0
movq %rax, 0x90(%rsp)
jmp 0xcb380
movq 0x90(%rsp), %rdi
movq 0x468(%rsp), %rsi
callq 0x7ba30
jmp 0xcb397
movl $0x88, %edi
callq 0x76970
movq %rax, 0x88(%rsp)
jmp 0xcb3ab
movq 0x88(%rsp), %rdi
movq 0xc8(%rsp), %rdx
addq $0x78, %rdx
leaq 0x4d9d2(%rip), %rsi     # 0x118d98
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x711c0
jmp 0xcb3d6
movq 0xc8(%rsp), %rdx
movq 0x88(%rsp), %rax
movq %rax, 0x98(%rdx)
movq 0x98(%rdx), %rdi
addq $0x38, %rdx
leaq 0x4d9d9(%rip), %rsi     # 0x118dd8
callq 0x78710
jmp 0xcb406
movq 0xc8(%rsp), %rax
movq 0x98(%rax), %rax
movq %rax, 0x80(%rsp)
leaq 0x280(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x76880
jmp 0xcb434
movq 0x80(%rsp), %rdi
leaq 0x4d9b5(%rip), %rsi     # 0x118df8
leaq 0x280(%rsp), %rdx
callq 0x78710
jmp 0xcb452
leaq 0x280(%rsp), %rdi
callq 0x7cce8
jmp 0xcb461
movq 0xc8(%rsp), %rax
movq 0x98(%rax), %rsi
movq (%rsi), %rax
movq 0x10(%rax), %rax
leaq 0x260(%rsp), %rdi
callq *%rax
jmp 0xcb483
leaq 0x260(%rsp), %rdi
callq 0x74cd0
movq %rax, 0x78(%rsp)
jmp 0xcb497
movq 0x78(%rsp), %rax
movq %rax, 0x258(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x73020
movq %rax, 0x70(%rsp)
jmp 0xcb4b8
movq 0x70(%rsp), %rsi
movq 0xc8(%rsp), %rdi
movl 0x258(%rsp), %edx
callq 0x74c10
movq %rax, 0x68(%rsp)
jmp 0xcb4d8
movq 0x68(%rsp), %rax
cmpq 0x258(%rsp), %rax
je 0xcb6d6
leaq 0x237(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x7b5f0
movq 0x60(%rsp), %rdx
leaq 0x2099d(%rip), %rsi     # 0xebea6
leaq 0x238(%rsp), %rdi
callq 0x78e70
jmp 0xcb518
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x210(%rsp), %rdi
callq 0x77a20
jmp 0xcb533
movq 0xc8(%rsp), %rdi
leaq 0x238(%rsp), %rsi
leaq 0x210(%rsp), %rdx
callq 0x7ab60
jmp 0xcb552
leaq 0x210(%rsp), %rdi
callq 0x7cce8
jmp 0xcb561
leaq 0x238(%rsp), %rdi
callq 0x7cce8
jmp 0xcb570
leaq 0x237(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x487(%rsp)
movl $0x1, 0x20c(%rsp)
jmp 0xcbd9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcb5d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x2b8(%rsp), %rdi
callq 0x7cce8
jmp 0xcb5ce
jmp 0xcb5d0
leaq 0x2b7(%rsp), %rdi
callq 0x76f80
jmp 0xcbdef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcbdcd
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
callq 0x764d0
jmp 0xcbdcd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x7cce8
jmp 0xcb644
jmp 0xcbdcd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcbdbc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcb6c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcb6b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x7cce8
jmp 0xcb6b1
jmp 0xcb6b3
leaq 0x238(%rsp), %rdi
callq 0x7cce8
jmp 0xcb6c2
jmp 0xcb6c4
leaq 0x237(%rsp), %rdi
callq 0x76f80
jmp 0xcbdbc
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x7b680
jmp 0xcb6e9
movq 0xc8(%rsp), %rdi
callq 0x7c1b0
movb %al, 0x5f(%rsp)
jmp 0xcb6fc
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0xcb83b
jmp 0xcb70a
leaq 0x1e7(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x7b5f0
movq 0x50(%rsp), %rdx
leaq 0x20797(%rip), %rsi     # 0xebebf
leaq 0x1e8(%rsp), %rdi
callq 0x78e70
jmp 0xcb737
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x77a20
jmp 0xcb752
movq 0xc8(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
leaq 0x1c0(%rsp), %rdx
callq 0x7ab60
jmp 0xcb771
leaq 0x1c0(%rsp), %rdi
callq 0x7cce8
jmp 0xcb780
leaq 0x1e8(%rsp), %rdi
callq 0x7cce8
jmp 0xcb78f
leaq 0x1e7(%rsp), %rdi
callq 0x76f80
movq 0xc8(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xcb7af
movb $0x0, 0x487(%rsp)
movl $0x1, 0x20c(%rsp)
jmp 0xcbd9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcb829
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcb818
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x7cce8
jmp 0xcb816
jmp 0xcb818
leaq 0x1e8(%rsp), %rdi
callq 0x7cce8
jmp 0xcb827
jmp 0xcb829
leaq 0x1e7(%rsp), %rdi
callq 0x76f80
jmp 0xcbdbc
callq 0x761a0
jmp 0xcb842
callq 0x761a0
jmp 0xcb849
movq 0xc8(%rsp), %rax
movq 0xa0(%rax), %rdi
callq 0x72ee0
movl %eax, 0x4c(%rsp)
jmp 0xcb863
movl 0x4c(%rsp), %eax
movl %eax, 0x1bc(%rsp)
movl 0x1bc(%rsp), %eax
movl %eax, 0x48(%rsp)
subl $0xc8, %eax
je 0xcb989
jmp 0xcb886
movl 0x48(%rsp), %eax
subl $0xce, %eax
jne 0xcbc47
jmp 0xcb897
movq 0xc8(%rsp), %rax
movq 0xa0(%rax), %rdi
leaq 0x4d58b(%rip), %rsi     # 0x118e38
callq 0x71430
movb %al, 0x47(%rsp)
jmp 0xcb8b8
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0xcb8c5
jmp 0xcb971
movq 0xc8(%rsp), %rax
movq 0xa0(%rax), %rsi
leaq 0x4d55d(%rip), %rdx     # 0x118e38
leaq 0x198(%rsp), %rdi
callq 0x71a20
jmp 0xcb8ea
movq 0xc8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0x30(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x73020
movq %rax, 0x38(%rsp)
jmp 0xcb912
movq 0x38(%rsp), %rdi
callq 0x7a180
movq 0x30(%rsp), %rcx
movl %eax, %edx
movq 0xc8(%rsp), %rax
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0xc0(%rax)
leaq 0x198(%rsp), %rdi
callq 0x7cce8
jmp 0xcb947
jmp 0xcb971
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x7cce8
jmp 0xcb96c
jmp 0xcbdbc
movb $0x1, 0x487(%rsp)
movl $0x1, 0x20c(%rsp)
jmp 0xcbd9e
leaq 0x188(%rsp), %rdi
movl $0x8000, %esi           # imm = 0x8000
callq 0x76550
jmp 0xcb99d
movq $0x0, 0x180(%rsp)
movq 0xc8(%rsp), %rcx
movq 0x180(%rsp), %rax
cmpq 0xb0(%rcx), %rax
jge 0xcbbf1
movq 0xc8(%rsp), %rax
movq 0xb0(%rax), %rax
subq 0x180(%rsp), %rax
movq %rax, 0x178(%rsp)
cmpq $0x8000, 0x178(%rsp) # imm = 0x8000
jle 0xcb9ff
movl $0x8000, %eax           # imm = 0x8000
movq %rax, 0x28(%rsp)
jmp 0xcba0c
movq 0x178(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xc8(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x188(%rsp), %rsi
movl 0x170(%rsp), %edx
callq 0x74ac0
movq %rax, 0x20(%rsp)
jmp 0xcba3c
movq 0x20(%rsp), %rax
movq %rax, 0x168(%rsp)
cmpq $0x0, 0x168(%rsp)
jge 0xcbba2
leaq 0x147(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x20449(%rip), %rsi     # 0xebebf
leaq 0x148(%rsp), %rdi
callq 0x78e70
jmp 0xcba85
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x120(%rsp), %rdi
callq 0x77a20
jmp 0xcbaa0
movq 0xc8(%rsp), %rdi
leaq 0x148(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0x7ab60
jmp 0xcbabf
leaq 0x120(%rsp), %rdi
callq 0x7cce8
jmp 0xcbace
leaq 0x148(%rsp), %rdi
callq 0x7cce8
jmp 0xcbadd
leaq 0x147(%rsp), %rdi
callq 0x76f80
movq 0xc8(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xcbafd
movb $0x0, 0x487(%rsp)
movl $0x1, 0x20c(%rsp)
jmp 0xcbc1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcbc33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcbb90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcbb7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x7cce8
jmp 0xcbb7d
jmp 0xcbb7f
leaq 0x148(%rsp), %rdi
callq 0x7cce8
jmp 0xcbb8e
jmp 0xcbb90
leaq 0x147(%rsp), %rdi
callq 0x76f80
jmp 0xcbc33
cmpq $0x0, 0x168(%rsp)
jne 0xcbbd2
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x76780
movq %rax, 0x10(%rsp)
jmp 0xcbbc5
movq 0x10(%rsp), %rax
cmpq $0x0, %rax
jne 0xcbbd2
jmp 0xcbbf1
jmp 0xcbbd4
movq 0x168(%rsp), %rax
addq 0x180(%rsp), %rax
movq %rax, 0x180(%rsp)
jmp 0xcb9a9
movq 0xc8(%rsp), %rcx
movq 0x180(%rsp), %rax
cmpq 0xb0(%rcx), %rax
sete %al
andb $0x1, %al
movb %al, 0x487(%rsp)
movl $0x1, 0x20c(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x7a450
jmp 0xcbc2e
jmp 0xcbd9e
leaq 0x188(%rsp), %rdi
callq 0x7a450
jmp 0xcbc42
jmp 0xcbdbc
jmp 0xcbc49
leaq 0xff(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x20258(%rip), %rsi     # 0xebebf
leaq 0x100(%rsp), %rdi
callq 0x78e70
jmp 0xcbc76
leaq 0xd7(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x7b5f0
movq (%rsp), %rdx
leaq 0x2015e(%rip), %rsi     # 0xebdf0
leaq 0xd8(%rsp), %rdi
callq 0x78e70
jmp 0xcbca1
movq 0xc8(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x7ab60
jmp 0xcbcc0
leaq 0xd8(%rsp), %rdi
callq 0x7cce8
jmp 0xcbccf
leaq 0xd7(%rsp), %rdi
callq 0x76f80
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xcbceb
leaq 0xff(%rsp), %rdi
callq 0x76f80
movq 0xc8(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xcbd0b
movb $0x0, 0x487(%rsp)
movl $0x1, 0x20c(%rsp)
jmp 0xcbd9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcbd8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0xcbd71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x7cce8
jmp 0xcbd6f
jmp 0xcbd71
leaq 0xd7(%rsp), %rdi
callq 0x76f80
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xcbd8d
jmp 0xcbd8f
leaq 0xff(%rsp), %rdi
callq 0x76f80
jmp 0xcbdbc
leaq 0x260(%rsp), %rdi
callq 0x7cce8
jmp 0xcbdad
leaq 0x2d8(%rsp), %rdi
callq 0x74f60
jmp 0xcbdde
leaq 0x260(%rsp), %rdi
callq 0x7cce8
jmp 0xcbdcb
jmp 0xcbdcd
leaq 0x2d8(%rsp), %rdi
callq 0x74f60
jmp 0xcbddc
jmp 0xcbdef
movb 0x487(%rsp), %al
andb $0x1, %al
addq $0x488, %rsp            # imm = 0x488
retq
movq 0x2a8(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)