// File: davmac314[P]dinit/src/dinit-iostream.cc
// Function: dio::istream::get_line_nx(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, char)
bool istream::get_line_nx(std::string &dest, char delim) noexcept
{
    if (!good()) {
        return false;
    }
    dest.clear();
    if (buf->get_length() == 0) {
        int r = load_into_buf(buf->get_size());
        if (r <= 0) return false;
    }

    char *ptr = buf->get_ptr(0);
    unsigned len = buf->get_contiguous_length(ptr);
    char *eptr = static_cast<char *>(std::memchr(ptr, delim, len));

    if (eptr == ptr) {
        buf->consume(1);
        return true; // An empty line
    }
    while (eptr == nullptr) {
        // while no delimiter is found, append the entire buffer contents to the 'dest' string and refill the buffer.
        try {
            // dest.append() may throw length_error or bad_alloc
            dest.append(ptr, len);
        }
        catch (const std::exception &e) {
            string_failed = true;
            return false;
        }
        buf->consume(len);

        if (buf->get_length() == 0) {
            int r = load_into_buf(buf->get_size());
            if (r <= 0) return false;
        }

        ptr = buf->get_ptr(0);
        len = buf->get_contiguous_length(ptr);
        eptr = static_cast<char *>(std::memchr(ptr, delim, len));
    }
    unsigned index = eptr - ptr;
    try {
        // dest.append() may throw length_error or bad_alloc
        dest.append(ptr, index);
    }
    catch (const std::exception &e) {
        string_failed = true;
        return false;
    }
    buf->consume(index + 1); // Consume the delimiter character as well
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0x215b0
testb $0x1, %al
jne 0x21842
movb $0x0, -0x1(%rbp)
jmp 0x21ae5
movq -0x18(%rbp), %rdi
callq 0x5550
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
callq 0x21e20
cmpl $0x0, %eax
jne 0x2189c
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
callq 0x221b0
movl %eax, -0x6c(%rbp)
jmp 0x2187c
movl -0x6c(%rbp), %esi
movq -0x68(%rbp), %rdi
callq 0x20e80
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jg 0x2189a
movb $0x0, -0x1(%rbp)
jmp 0x21ae5
jmp 0x2189c
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
xorl %esi, %esi
callq 0x21d50
movq %rax, -0x78(%rbp)
jmp 0x218b9
movq -0x68(%rbp), %rdi
movq -0x78(%rbp), %rax
movq %rax, -0x28(%rbp)
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x21d90
movl %eax, -0x7c(%rbp)
jmp 0x218df
movl -0x7c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
movsbl -0x19(%rbp), %esi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x5470
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x21928
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
movl $0x1, %esi
callq 0x21ea0
movb $0x1, -0x1(%rbp)
jmp 0x21ae5
jmp 0x2192a
cmpq $0x0, -0x38(%rbp)
jne 0x21a68
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x5080
jmp 0x21949
jmp 0x2198f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x21afb
movq -0x40(%rbp), %rdi
callq 0x5150
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, -0x50(%rbp)
movb $0x1, 0x15(%rax)
movb $0x0, -0x1(%rbp)
callq 0x5680
jmp 0x2198a
jmp 0x21ae5
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x21ea0
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
callq 0x21e20
cmpl $0x0, %eax
jne 0x219f8
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
callq 0x221b0
movl %eax, -0x80(%rbp)
jmp 0x219d8
movl -0x80(%rbp), %esi
movq -0x68(%rbp), %rdi
callq 0x20e80
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jg 0x219f6
movb $0x0, -0x1(%rbp)
jmp 0x21ae5
jmp 0x219f8
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
xorl %esi, %esi
callq 0x21d50
movq %rax, -0x88(%rbp)
jmp 0x21a18
movq -0x68(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0x28(%rbp)
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x21d90
movl %eax, -0x8c(%rbp)
jmp 0x21a44
movl -0x8c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
movsbl -0x19(%rbp), %esi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x5470
movq %rax, -0x38(%rbp)
jmp 0x2192a
movl -0x38(%rbp), %eax
movl -0x28(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x58(%rbp), %eax
movl %eax, %edx
callq 0x5080
jmp 0x21a87
jmp 0x21ac6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x21afb
movq -0x40(%rbp), %rdi
callq 0x5150
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, -0x60(%rbp)
movb $0x1, 0x15(%rax)
movb $0x0, -0x1(%rbp)
callq 0x5680
jmp 0x21ac4
jmp 0x21ae5
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x21d10
movq %rax, %rdi
movl -0x58(%rbp), %esi
addl $0x1, %esi
callq 0x21ea0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0x103e0
movq -0x40(%rbp), %rdi
callq 0x103e0
nopw %cs:(%rax,%rax)