// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
xorl %eax, %eax
cmpl $0x0, 0x10(%rdi)
jne 0x14339
movq %rdi, %rbx
cmpb $0x0, 0x15(%rdi)
jne 0x14339
cmpb $0x0, 0x14(%rbx)
jne 0x14339
cmpq $0x0, 0x8(%rbx)
je 0x14339
movl %edx, %r12d
movq %rsi, %r14
movq $0x0, 0x8(%rsi)
movq (%rsi), %rax
movb $0x0, (%rax)
movq 0x8(%rbx), %rax
cmpl $0x0, 0x4004(%rax)
jne 0x14160
movq %rbx, %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x13c1c
testl %eax, %eax
jle 0x14337
movq %r14, 0x8(%rsp)
movq 0x8(%rbx), %r14
movl 0x4000(%r14), %ebp
movl 0x4004(%r14), %edx
leal -0x4000(%rbp), %eax
cmpl $0x4000, %ebp           # imm = 0x4000
cmovbl %ebp, %eax
leaq (%rax,%r14), %r15
testl %edx, %edx
movq %rdx, 0x10(%rsp)
je 0x141bc
leaq 0x4000(%r14), %r13
leal (%rdx,%rbp), %ecx
cmpl $0x4000, %ecx           # imm = 0x4000
leal -0x4000(%rdx,%rbp), %edx
cmovbl %ecx, %edx
leal (%r14,%rdx), %ecx
cmpl %eax, %edx
cmoval %ecx, %r13d
subl %r15d, %r13d
jmp 0x141bf
xorl %r13d, %r13d
movsbl %r12b, %esi
movl %r13d, %edx
movq %r15, %rdi
movl %esi, 0x4(%rsp)
callq 0x4310
cmpq %r15, %rax
je 0x141e9
movq %rax, %r12
testq %rax, %rax
je 0x14214
movq 0x8(%rsp), %r14
jmp 0x142d8
leal 0x1(%rbp), %eax
addl $0xffffc001, %ebp       # imm = 0xFFFFC001
cmpl $0x4000, %eax           # imm = 0x4000
cmovbl %eax, %ebp
movl %ebp, 0x4000(%r14)
movq 0x10(%rsp), %rax
decl %eax
movl %eax, 0x4004(%r14)
jmp 0x1431b
movq 0x8(%rsp), %r14
movl 0x4(%rsp), %ebp
movl %r13d, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4070
movq 0x8(%rbx), %rax
movl 0x4000(%rax), %ecx
leal (%rcx,%r13), %edx
cmpl $0x4000, %edx           # imm = 0x4000
leal -0x4000(%rcx,%r13), %ecx
cmovbl %edx, %ecx
movl %ecx, 0x4000(%rax)
subl %r13d, 0x4004(%rax)
jne 0x1426e
movq %rbx, %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x13c1c
testl %eax, %eax
jle 0x14337
movq 0x8(%rbx), %rax
movl 0x4000(%rax), %edx
movl 0x4004(%rax), %esi
leal -0x4000(%rdx), %ecx
cmpl $0x4000, %edx           # imm = 0x4000
cmovbl %edx, %ecx
leaq (%rcx,%rax), %r15
testl %esi, %esi
je 0x142bc
leaq 0x4000(%rax), %r13
leal (%rsi,%rdx), %edi
cmpl $0x4000, %edi           # imm = 0x4000
leal -0x4000(%rsi,%rdx), %edx
cmovbl %edi, %edx
addl %edx, %eax
cmpl %ecx, %edx
cmoval %eax, %r13d
subl %r15d, %r13d
jmp 0x142bf
xorl %r13d, %r13d
movl %r13d, %edx
movq %r15, %rdi
movl %ebp, %esi
callq 0x4310
testq %rax, %rax
je 0x1421d
movq %rax, %r12
subq %r15, %r12
movl %r12d, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4070
movq 0x8(%rbx), %rax
movl 0x4000(%rax), %ecx
movl %r12d, %edx
incl %edx
leal (%rcx,%r12), %esi
incl %esi
cmpl $0x4000, %esi           # imm = 0x4000
leal -0x3fff(%rcx,%r12), %ecx
cmovbl %esi, %ecx
movl %ecx, 0x4000(%rax)
subl %edx, 0x4004(%rax)
movb $0x1, %al
jmp 0x14339
jmp 0x14321
cmpl $0x2, %edx
jne 0x14348
movq %rax, %rdi
callq 0x4130
movb $0x1, 0x15(%rbx)
callq 0x44b0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rdi
callq 0xe564