// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rsi, %r15
movq %rdi, %rbx
callq 0x321a0
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x4f60a
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x30(%rbx), %rdi
callq 0x34f30
movq %rbx, %rdi
callq 0x33ae0
testb %al, %al
je 0x4f7eb
cmpq $0x10001, %r15          # imm = 0x10001
movl $0x10000, %r14d         # imm = 0x10000
cmovaeq %r15, %r14
addq 0xb0(%rbx), %r14
leaq 0xc822(%rip), %rsi      # 0x5be64
leaq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x31b30
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x34880
leaq 0x58(%rsp), %rdi
callq 0x33a00
leaq 0x88(%rsp), %rdi
leaq 0x28d04(%rip), %rsi     # 0x78380
callq 0x32d80
movq 0xb0(%rbx), %rsi
movq %rax, %rdi
callq 0x32fb0
pushq $0x2d
popq %rsi
movq %rax, %rdi
callq 0x337b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32fb0
movl $0x88, %edi
callq 0x33130
movq %rax, %r14
leaq 0x78(%rbx), %rdx
leaq 0x28c42(%rip), %rsi     # 0x78300
pushq $0x1
popq %rcx
movq %rax, %rdi
movl %ecx, %r8d
callq 0x310f0
movq %r14, 0x98(%rbx)
leaq 0x38(%rbx), %rdx
leaq 0x28c62(%rip), %rsi     # 0x78340
movq %r14, %rdi
callq 0x33ca0
movq 0x98(%rbx), %r14
leaq 0x90(%rsp), %rsi
leaq 0x58(%rsp), %rdi
callq 0x34870
leaq 0x28c5a(%rip), %rsi     # 0x78360
leaq 0x58(%rsp), %rdx
movq %r14, %rdi
callq 0x33ca0
leaq 0x58(%rsp), %rdi
callq 0x33a00
movq 0x98(%rbx), %rsi
movq (%rsi), %rax
leaq 0x58(%rsp), %rdi
callq *0x10(%rax)
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %r14
movq %rbx, %rdi
movl %r14d, %edx
callq 0x32700
cmpq %r14, %rax
jne 0x4f7f2
movq 0x30(%rbx), %rdi
callq 0x34f30
movq %rbx, %rdi
callq 0x353b0
testb %al, %al
je 0x4f841
movq 0xa0(%rbx), %rdi
callq 0x31b00
cmpl $0xc8, %eax
je 0x4f899
cmpl $0xce, %eax
jne 0x4f918
movq 0xa0(%rbx), %rdi
leaq 0x28c0a(%rip), %rsi     # 0x783a0
callq 0x311d0
movb $0x1, %bpl
testb %al, %al
je 0x4f975
movq 0xa0(%rbx), %rsi
leaq 0x28bec(%rip), %rdx     # 0x783a0
leaq 0x8(%rsp), %rdi
callq 0x313b0
movq 0xb0(%rbx), %r15
leaq 0x8(%rsp), %r14
movq (%r14), %rdi
callq 0x34710
cltq
addq %r15, %rax
movq %rax, 0xc0(%rbx)
movq %r14, %rdi
callq 0x33a00
jmp 0x4f975
xorl %ebp, %ebp
jmp 0x4f989
leaq 0xd44f(%rip), %rsi      # 0x5cc48
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
movq 0x30(%rbx), %rsi
leaq 0x38(%rsp), %rdi
callq 0x337f0
leaq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x34ab0
leaq 0x38(%rsp), %rdi
callq 0x33a00
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4f973
leaq 0xd419(%rip), %rsi      # 0x5cc61
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
movq 0x30(%rbx), %rsi
leaq 0x38(%rsp), %rdi
callq 0x337f0
leaq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x34ab0
leaq 0x38(%rsp), %rdi
callq 0x33a00
leaq 0x8(%rsp), %rdi
callq 0x33a00
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
jmp 0x4f973
movl $0x8000, %r15d          # imm = 0x8000
movl $0x8000, %edi           # imm = 0x8000
callq 0x31080
movq %rax, %r14
xorl %r12d, %r12d
movl $0x8000, %edx           # imm = 0x8000
movq %rax, %rdi
xorl %esi, %esi
callq 0x320d0
movq %r14, 0x28(%rsp)
movq $0x8000, 0x30(%rsp)     # imm = 0x8000
movq 0xb0(%rbx), %rax
movq %rax, %rdx
subq %r12, %rdx
jle 0x4f9f9
cmpq %r15, %rdx
cmovgeq %r15, %rdx
movq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x326b0
movq %rax, %r14
testq %rax, %rax
js 0x4f99b
jne 0x4f913
movq 0x30(%rbx), %rdi
callq 0x33080
testq %rax, %rax
je 0x4f9f2
addq %r14, %r12
jmp 0x4f8cc
leaq 0xd342(%rip), %rsi      # 0x5cc61
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
leaq 0xd25d(%rip), %rsi      # 0x5cb92
leaq 0x38(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
leaq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x34ab0
leaq 0x38(%rsp), %rdi
callq 0x33a00
leaq 0x8(%rsp), %rdi
callq 0x33a00
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
xorl %ebp, %ebp
leaq 0x58(%rsp), %rdi
callq 0x33a00
leaq 0x78(%rsp), %rdi
callq 0x32870
movl %ebp, %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd2bf(%rip), %rsi      # 0x5cc61
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
movq 0x30(%rbx), %rsi
leaq 0x38(%rsp), %rdi
callq 0x337f0
leaq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x34ab0
leaq 0x38(%rsp), %rdi
callq 0x33a00
leaq 0x8(%rsp), %rdi
callq 0x33a00
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
xorl %ebp, %ebp
jmp 0x4fa00
movq 0xb0(%rbx), %rax
cmpq %rax, %r12
sete %bpl
leaq 0x28(%rsp), %rdi
callq 0x34850
jmp 0x4f975
jmp 0x4fad7
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x33a00
jmp 0x4fa2b
jmp 0x4fad7
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4fada
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x33a00
jmp 0x4fa5b
jmp 0x4faef
jmp 0x4faef
jmp 0x4faef
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4faf2
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x33a00
jmp 0x4fa80
jmp 0x4faef
jmp 0x4faef
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4faf2
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x33a00
jmp 0x4faa0
jmp 0x4faef
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4faf2
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x33a00
jmp 0x4fb01
movq %rax, %rbx
movq %r14, %rdi
callq 0x32fa0
jmp 0x4fb01
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x33a00
jmp 0x4fb0b
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x34850
jmp 0x4faf2
jmp 0x4fafe
jmp 0x4fafe
movq %rax, %rbx
jmp 0x4fb0b
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x33a00
jmp 0x4fb01
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x32870
movq %rbx, %rdi
callq 0x34ed0
movq %rax, %rdi
callq 0x39b2f
nop