// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rsi, %r15
movq %rdi, %rbx
movq 0xa0(%rdi), %rdi
testq %rdi, %rdi
je 0x47eda
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0xa0(%rbx)
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x47eec
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x30(%rbx), %rdi
callq 0x28c50
movq 0x30(%rbx), %rdi
callq 0x27370
testb %al, %al
jne 0x47f12
movq %rbx, %rdi
callq 0x28830
testb %al, %al
je 0x48170
cmpq $0x10001, %r15          # imm = 0x10001
movl $0x10000, %r14d         # imm = 0x10000
cmovaeq %r15, %r14
addq 0xb0(%rbx), %r14
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xdf54(%rip), %rdx      # 0x55e8f
leaq 0x40(%rsp), %rdi
movq %rdx, %rsi
callq 0x26750
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x18, %edx
callq 0x28740
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x47f6b
callq 0x27560
leaq 0x70(%rsp), %rdi
movq 0x25961(%rip), %rsi     # 0x6d8d8
movq 0x25962(%rip), %rdx     # 0x6d8e0
callq 0x27a70
movq 0xb0(%rbx), %rsi
movq %rax, %rdi
callq 0x27570
leaq 0x40(%rsp), %rsi
movb $0x2d, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x27a70
movq %rax, %rdi
movq %r14, %rsi
callq 0x27570
movl $0x88, %edi
callq 0x276b0
movq %rax, %r14
leaq 0x78(%rbx), %rdx
leaq 0x2588e(%rip), %rsi     # 0x6d858
movq %rax, %rdi
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x260c0
movq %r14, 0x98(%rbx)
leaq 0x38(%rbx), %rdx
leaq 0x258a9(%rip), %rsi     # 0x6d898
movq %r14, %rdi
callq 0x27e90
movq 0x98(%rbx), %r14
leaq 0x78(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x28730
leaq 0x258a4(%rip), %rsi     # 0x6d8b8
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
callq 0x27e90
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x48030
callq 0x27560
movq 0x98(%rbx), %rsi
movq (%rsi), %rax
leaq 0x40(%rsp), %rdi
callq *0x10(%rax)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %r14
movq %rbx, %rdi
movl %r14d, %edx
callq 0x27010
cmpq %r14, %rax
jne 0x48109
movq 0x30(%rbx), %rdi
callq 0x28c50
movq %rbx, %rdi
callq 0x28f90
testb %al, %al
je 0x48177
movq 0xa0(%rbx), %rdi
callq 0x26740
cmpl $0xc8, %eax
je 0x481e3
cmpl $0xce, %eax
jne 0x48264
movq 0xa0(%rbx), %rdi
leaq 0x2584f(%rip), %rsi     # 0x6d8f8
callq 0x26170
movb $0x1, %bpl
testb %al, %al
je 0x482dc
movq 0xa0(%rbx), %rsi
leaq 0x25831(%rip), %rdx     # 0x6d8f8
movq %rsp, %rdi
callq 0x26270
movq 0xb0(%rbx), %r15
leaq 0x10(%rsp), %r13
movq -0x10(%r13), %r14
movq %r14, %rdi
callq 0x28640
cltq
addq %r15, %rax
movq %rax, 0xc0(%rbx)
cmpq %r13, %r14
je 0x482dc
movq %r14, %rdi
callq 0x27560
jmp 0x482dc
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xeb00(%rip), %rsi      # 0x56c19
leaq 0xeb11(%rip), %rdx      # 0x56c31
movq %rsp, %rdi
callq 0x26750
movq 0x30(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x27b40
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x288b0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x48159
callq 0x27560
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x482da
callq 0x27560
jmp 0x482da
xorl %ebp, %ebp
jmp 0x482f5
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xeaab(%rip), %rsi      # 0x56c32
leaq 0xeabb(%rip), %rdx      # 0x56c49
movq %rsp, %rdi
callq 0x26750
movq 0x30(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x27b40
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x288b0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x481c7
callq 0x27560
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x481d5
callq 0x27560
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
jmp 0x482da
movl $0x8000, %edi           # imm = 0x8000
callq 0x26070
movq %rax, %r14
xorl %r13d, %r13d
movl $0x8000, %ebp           # imm = 0x8000
movl $0x8000, %edx           # imm = 0x8000
movq %rax, %rdi
xorl %esi, %esi
callq 0x26bc0
movq 0xb0(%rbx), %rdx
testq %rdx, %rdx
jle 0x4837b
xorl %r13d, %r13d
subq %r13, %rdx
cmpq %rbp, %rdx
cmovgeq %rbp, %rdx
movq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x26bd0
movq %rax, %r15
testq %rax, %rax
js 0x48309
jne 0x48250
movq 0x30(%rbx), %rdi
callq 0x27620
testq %rax, %rax
je 0x48374
addq %r15, %r13
movq 0xb0(%rbx), %rdx
cmpq %rdx, %r13
jl 0x4821a
jmp 0x4837b
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xe9be(%rip), %rsi      # 0x56c32
leaq 0xe9ce(%rip), %rdx      # 0x56c49
movq %rsp, %rdi
callq 0x26750
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xe8d0(%rip), %rsi      # 0x56b63
leaq 0xe8ec(%rip), %rdx      # 0x56b86
leaq 0x20(%rsp), %rdi
callq 0x26750
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x288b0
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x482c3
callq 0x27560
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x482d1
callq 0x27560
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
xorl %ebp, %ebp
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x482eb
callq 0x27560
leaq 0x60(%rsp), %rdi
callq 0x270d0
movl %ebp, %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xe919(%rip), %rsi      # 0x56c32
leaq 0xe929(%rip), %rdx      # 0x56c49
movq %rsp, %rdi
callq 0x26750
movq 0x30(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x27b40
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x288b0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x48359
callq 0x27560
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x48367
callq 0x27560
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
xorl %ebp, %ebp
jmp 0x48382
movq 0xb0(%rbx), %rdx
cmpq %rdx, %r13
sete %bpl
movq %r14, %rdi
callq 0x27e60
jmp 0x482dc
jmp 0x4840a
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x483ac
callq 0x27560
jmp 0x483ac
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4840d
callq 0x27560
jmp 0x4840d
jmp 0x4840a
jmp 0x4843e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
jne 0x483ee
jmp 0x483f8
jmp 0x483f5
jmp 0x4843e
jmp 0x4843e
jmp 0x483dd
jmp 0x483f5
jmp 0x4843e
jmp 0x4843e
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x483f8
callq 0x27560
jmp 0x483f8
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x48441
callq 0x27560
jmp 0x48441
jmp 0x4843e
movq %rax, %rbx
movq %r14, %rdi
callq 0x27e60
jmp 0x48441
jmp 0x48452
jmp 0x4843e
jmp 0x48452
movq %rax, %rbx
movq %r14, %rdi
jmp 0x4844b
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x4845f
callq 0x27560
jmp 0x4845f
movq %rax, %rbx
jmp 0x4845f
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x48455
callq 0x27560
jmp 0x48455
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x270d0
movq %rbx, %rdi
callq 0x28c10
movq %rax, %rdi
callq 0x2f047
nop