// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocket_p.cpp
// Function: BamTools::Internal::TcpSocket::ReadLine[abi:cxx11](long)
string TcpSocket::ReadLine(int64_t max) {

    // prep result byte buffer
    ByteArray result;
    size_t bufferMax = ((max > static_cast<int64_t>(UINT_MAX))
                        ? UINT_MAX : static_cast<size_t>(max));
    result.Resize(bufferMax);

    // read data
    int64_t readBytes(0);
    if ( result.Size() == 0 ) {

        if ( bufferMax == 0 )
            bufferMax = UINT_MAX;

        result.Resize(1);

        int64_t readResult;
        do {
            result.Resize( static_cast<size_t>(min(bufferMax, result.Size() + DEFAULT_BUFFER_SIZE)) );
            readResult = ReadLine(result.Data()+readBytes, result.Size()-readBytes);
            if ( readResult > 0 || readBytes == 0 )
                readBytes += readResult;
        } while ( readResult == DEFAULT_BUFFER_SIZE && result[static_cast<size_t>(readBytes-1)] != '\n' );

    } else
        readBytes = ReadLine(result.Data(), result.Size());

    // clean up byte buffer
    if ( readBytes <= 0 )
        result.Clear();
    else
        result.Resize(static_cast<size_t>(readBytes));

    // return byte buffer as string
    return string( result.ConstData(), result.Size() );
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x88(%rsp)
movq %rdi, %rax
movq %rax, 0x90(%rsp)
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rdx, 0xf0(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x78440
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, 0xf0(%rsp)
jle 0xe096d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x80(%rsp)
jmp 0xe097d
movq 0xf0(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x744c0
jmp 0xe09a4
movq $0x0, 0xb8(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x75810
movq %rax, 0x78(%rsp)
jmp 0xe09c4
movq 0x78(%rsp), %rax
cmpq $0x0, %rax
jne 0xe0b6c
cmpq $0x0, 0xd0(%rsp)
jne 0xe0a06
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0xd0(%rsp)
jmp 0xe0a06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
jmp 0xe0c97
leaq 0xd8(%rsp), %rdi
movl $0x1, %esi
callq 0x744c0
jmp 0xe0a1a
jmp 0xe0a1c
leaq 0xd8(%rsp), %rdi
callq 0x75810
movq %rax, 0x70(%rsp)
jmp 0xe0a30
movq 0x70(%rsp), %rax
addq $0x10000, %rax          # imm = 0x10000
movq %rax, 0xa8(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x74f40
movq %rax, 0x68(%rsp)
jmp 0xe0a5f
movq 0x68(%rsp), %rax
movq (%rax), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x744c0
jmp 0xe0a76
leaq 0xd8(%rsp), %rdi
callq 0x795d0
movq %rax, 0x60(%rsp)
jmp 0xe0a8a
movq 0x60(%rsp), %rax
movq 0xb8(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x75810
movq %rax, 0x58(%rsp)
jmp 0xe0ab3
movq 0x50(%rsp), %rsi
movq 0x98(%rsp), %rdi
movq 0x58(%rsp), %rdx
movq 0xb8(%rsp), %rax
subq %rax, %rdx
callq 0x769c0
movq %rax, 0x48(%rsp)
jmp 0xe0adc
movq 0x48(%rsp), %rax
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0xb0(%rsp)
jg 0xe0aff
cmpq $0x0, 0xb8(%rsp)
jne 0xe0b17
movq 0xb0(%rsp), %rax
addq 0xb8(%rsp), %rax
movq %rax, 0xb8(%rsp)
jmp 0xe0b19
xorl %eax, %eax
cmpq $0x10000, 0xb0(%rsp) # imm = 0x10000
movb %al, 0x47(%rsp)
jne 0xe0b5e
movq 0xb8(%rsp), %rsi
decq %rsi
leaq 0xd8(%rsp), %rdi
callq 0x7bca0
movq %rax, 0x38(%rsp)
jmp 0xe0b4c
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0xe0a1c
jmp 0xe0bbf
leaq 0xd8(%rsp), %rdi
callq 0x795d0
movq %rax, 0x30(%rsp)
jmp 0xe0b80
leaq 0xd8(%rsp), %rdi
callq 0x75810
movq %rax, 0x28(%rsp)
jmp 0xe0b94
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rsi
movq 0x98(%rsp), %rdi
callq 0x769c0
movq %rax, 0x20(%rsp)
jmp 0xe0bb2
movq 0x20(%rsp), %rax
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jg 0xe0bdb
leaq 0xd8(%rsp), %rdi
callq 0x736b0
jmp 0xe0bd9
jmp 0xe0bf4
movq 0xb8(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x744c0
jmp 0xe0bf2
jmp 0xe0bf4
leaq 0xd8(%rsp), %rdi
callq 0x71e90
movq %rax, 0x18(%rsp)
jmp 0xe0c08
leaq 0xd8(%rsp), %rdi
callq 0x75810
movq %rax, 0x10(%rsp)
jmp 0xe0c1c
leaq 0xa7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x88(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
callq 0x77510
jmp 0xe0c4c
leaq 0xa7(%rsp), %rdi
callq 0x76f80
leaq 0xd8(%rsp), %rdi
callq 0x76060
movq 0x90(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0xa7(%rsp), %rdi
callq 0x76f80
leaq 0xd8(%rsp), %rdi
callq 0x76060
jmp 0xe0ca6
jmp 0xe0ca8
movq 0xc8(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax)