// File: /workspace/github_cpp_makefile_star2_O1/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 0x47f7e
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0xa0(%rbx)
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x47f90
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x30(%rbx), %rdi
callq 0x28c60
movq 0x30(%rbx), %rdi
callq 0x27370
testb %al, %al
jne 0x47fb6
movq %rbx, %rdi
callq 0x28840
testb %al, %al
je 0x48215
cmpq $0x10001, %r15          # imm = 0x10001
movl $0x10000, %r14d         # imm = 0x10000
cmovaeq %r15, %r14
addq 0xb0(%rbx), %r14
leaq 0x30(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xdeb0(%rip), %rdx      # 0x55e8f
leaq 0x20(%rsp), %rdi
movq %rdx, %rsi
callq 0x26750
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl $0x18, %edx
callq 0x28750
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x4800f
callq 0x27560
leaq 0x70(%rsp), %rdi
movq 0x258c5(%rip), %rsi     # 0x6d8e0
movq 0x258c6(%rip), %rdx     # 0x6d8e8
callq 0x27a70
movq 0xb0(%rbx), %rsi
movq %rax, %rdi
callq 0x27570
leaq 0x20(%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 0x257f2(%rip), %rsi     # 0x6d860
movq %rax, %rdi
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x260c0
movq %r14, 0x98(%rbx)
leaq 0x38(%rbx), %rdx
leaq 0x2580d(%rip), %rsi     # 0x6d8a0
movq %r14, %rdi
callq 0x27ea0
movq 0x98(%rbx), %r14
leaq 0x78(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x28740
leaq 0x25808(%rip), %rsi     # 0x6d8c0
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x27ea0
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x480d4
callq 0x27560
movq 0x98(%rbx), %rsi
movq (%rsi), %rax
leaq 0x20(%rsp), %rdi
callq *0x10(%rax)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r14
movq %rbx, %rdi
movl %r14d, %edx
callq 0x27010
cmpq %r14, %rax
jne 0x481ae
movq 0x30(%rbx), %rdi
callq 0x28c60
movq %rbx, %rdi
callq 0x28fa0
testb %al, %al
je 0x4821c
movq 0xa0(%rbx), %rdi
callq 0x26740
cmpl $0xc8, %eax
je 0x48288
cmpl $0xce, %eax
jne 0x48380
movq 0xa0(%rbx), %rdi
leaq 0x257b3(%rip), %rsi     # 0x6d900
callq 0x26170
movb $0x1, %bpl
testb %al, %al
je 0x483f8
movq 0xa0(%rbx), %rsi
leaq 0x25795(%rip), %rdx     # 0x6d900
movq %rsp, %rdi
callq 0x26270
movq 0xb0(%rbx), %r15
leaq 0x10(%rsp), %r13
movq -0x10(%r13), %r14
movq %r14, %rdi
callq 0x28650
cltq
addq %r15, %rax
movq %rax, 0xc0(%rbx)
cmpq %r13, %r14
je 0x481a4
movq %r14, %rdi
callq 0x27560
leaq 0x30(%rsp), %r12
jmp 0x483f8
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xea5b(%rip), %rsi      # 0x56c19
leaq 0xea6c(%rip), %rdx      # 0x56c31
movq %rsp, %rdi
callq 0x26750
movq 0x30(%rbx), %rsi
leaq 0x40(%rsp), %rdi
callq 0x27b50
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x288c0
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x481fe
callq 0x27560
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x483f6
callq 0x27560
jmp 0x483f6
xorl %ebp, %ebp
jmp 0x48411
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xea06(%rip), %rsi      # 0x56c32
leaq 0xea16(%rip), %rdx      # 0x56c49
movq %rsp, %rdi
callq 0x26750
movq 0x30(%rbx), %rsi
leaq 0x40(%rsp), %rdi
callq 0x27b50
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x288c0
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4826c
callq 0x27560
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x4827a
callq 0x27560
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
jmp 0x483f6
movl $0x8000, %ebp           # imm = 0x8000
movl $0x8000, %edi           # imm = 0x8000
callq 0x26070
movq %rax, %r14
xorl %r13d, %r13d
movl $0x8000, %edx           # imm = 0x8000
movq %rax, %rdi
xorl %esi, %esi
callq 0x26bc0
movq 0xb0(%rbx), %rdx
subq %r13, %rdx
jle 0x4842b
cmpq %rbp, %rdx
cmovgeq %rbp, %rdx
movq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x26bd0
movq %rax, %r15
testq %rax, %rax
js 0x482f3
jne 0x482eb
movq 0x30(%rbx), %rdi
callq 0x27620
testq %rax, %rax
je 0x48378
addq %r15, %r13
xorl %r15d, %r15d
jmp 0x4836a
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %rsp, %r15
movq %r15, %rdi
leaq 0xe929(%rip), %rsi      # 0x56c32
leaq 0xe939(%rip), %rdx      # 0x56c49
callq 0x26750
movq 0x30(%rbx), %rsi
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x27b50
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x288c0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x48348
callq 0x27560
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4835b
callq 0x27560
movq (%rbx), %rax
movl $0x1, %r15d
movq %rbx, %rdi
callq *0x10(%rax)
testl %r15d, %r15d
je 0x482ac
jmp 0x48425
movl $0x4, %r15d
jmp 0x4836a
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xe8a2(%rip), %rsi      # 0x56c32
leaq 0xe8b2(%rip), %rdx      # 0x56c49
movq %rsp, %rdi
callq 0x26750
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xe7b4(%rip), %rsi      # 0x56b63
leaq 0xe7d0(%rip), %rdx      # 0x56b86
leaq 0x40(%rsp), %rdi
callq 0x26750
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x288c0
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x483df
callq 0x27560
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x483ed
callq 0x27560
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
xorl %ebp, %ebp
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x48407
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
cmpl $0x4, %r15d
jne 0x48438
cmpq 0xb0(%rbx), %r13
sete %bpl
jmp 0x4843a
xorl %ebp, %ebp
leaq 0x30(%rsp), %r12
movq %r14, %rdi
callq 0x27e70
jmp 0x483f8
jmp 0x48515
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
jne 0x484b8
jmp 0x484c2
jmp 0x484bf
jmp 0x48515
jmp 0x48515
jmp 0x484a7
jmp 0x484bf
jmp 0x48515
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x4848e
callq 0x27560
jmp 0x4848e
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4850b
callq 0x27560
jmp 0x4850b
jmp 0x48508
jmp 0x48515
movq %rax, %rbx
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x484c2
callq 0x27560
jmp 0x484c2
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x48518
callq 0x27560
jmp 0x48518
jmp 0x48515
jmp 0x4852e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
jne 0x48527
jmp 0x48531
jmp 0x4852e
movq %rax, %rbx
movq %r14, %rdi
jmp 0x48527
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x4853b
callq 0x27560
jmp 0x4853b
movq %rax, %rbx
jmp 0x4853b
movq %rax, %rbx
movq %r14, %rdi
callq 0x27e70
jmp 0x48518
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x48531
callq 0x27560
jmp 0x48531
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x270d0
movq %rbx, %rdi
callq 0x28c20
movq %rax, %rdi
callq 0x2f0bd
nop