// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
callq 0xfcb0
testb %al, %al
je 0xff01
andq $0x0, 0x8(%r14)
movq (%r14), %rax
movb $0x0, (%rax)
movq 0x8(%rbx), %rdi
cmpl $0x0, 0x4004(%rdi)
jne 0xfe09
movq %rbx, %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0xf984
testl %eax, %eax
jle 0xff01
movq 0x8(%rbx), %rdi
movl 0x4000(%rdi), %eax
leal -0x4000(%rax), %r15d
cmpl $0x4000, %eax           # imm = 0x4000
cmovbl %eax, %r15d
addq %rdi, %r15
movq %r15, %rsi
callq 0xffd4
movl %eax, %r12d
movsbl %bpl, %ebp
movl %eax, %edx
movq %r15, %rdi
movl %ebp, %esi
callq 0x4340
cmpq %r15, %rax
je 0xfed9
movq %rax, %r13
testq %rax, %rax
jne 0xfebc
movl %r12d, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4070
movq 0x8(%rbx), %rdi
movl %r12d, %esi
callq 0x1004a
movq 0x8(%rbx), %rdi
cmpl $0x0, 0x4004(%rdi)
jne 0xfe8a
movq %rbx, %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0xf984
testl %eax, %eax
jle 0xff01
movq 0x8(%rbx), %rdi
movl 0x4000(%rdi), %eax
leal -0x4000(%rax), %r15d
cmpl $0x4000, %eax           # imm = 0x4000
cmovbl %eax, %r15d
addq %rdi, %r15
movq %r15, %rsi
callq 0xffd4
movl %eax, %r12d
movl %eax, %edx
movq %r15, %rdi
movl %ebp, %esi
callq 0x4340
jmp 0xfe46
subq %r15, %r13
movl %r13d, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4070
movq 0x8(%rbx), %rdi
incl %r13d
movl %r13d, %esi
jmp 0xfee0
movq 0x8(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x1004a
movb $0x1, %al
jmp 0xff03
jmp 0xfeeb
movq %rax, %rdi
cmpl $0x2, %edx
jne 0xff15
callq 0x4120
movb $0x1, 0x15(%rbx)
callq 0x44e0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rdi
callq 0xac53