// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
xorl %r12d, %r12d
cmpl $0x0, 0x10(%rdi)
jne 0x1417b
movq %rdi, %rbx
cmpb $0x0, 0x15(%rdi)
jne 0x1417b
cmpb $0x0, 0x14(%rbx)
jne 0x1417b
cmpq $0x0, 0x8(%rbx)
je 0x1417b
movl %edx, %r13d
movq $0x0, 0x8(%rsi)
movq %rsi, 0x20(%rsp)
movq (%rsi), %rax
movb $0x0, (%rax)
movq 0x8(%rbx), %rax
movl 0x4004(%rax), %r14d
testl %r14d, %r14d
je 0x13fdf
leaq 0x4000(%rax), %rdi
movl 0x4000(%rax), %ebp
leal -0x4000(%rbp), %ecx
cmpl $0x4000, %ebp           # imm = 0x4000
cmovbl %ebp, %ecx
leaq (%rcx,%rax), %r15
leaq 0x4004(%rax), %rdx
movq %rdx, 0x10(%rsp)
leal (%r14,%rbp), %edx
cmpl $0x4000, %edx           # imm = 0x4000
leal -0x4000(%r14,%rbp), %esi
cmovbl %edx, %esi
addl %esi, %eax
cmpl %ecx, %esi
movq %rdi, 0x18(%rsp)
cmovbel %edi, %eax
subl %r15d, %eax
decl %r14d
movl %eax, %r12d
movsbl %r13b, %esi
movl %r12d, %edx
movq %r15, %rdi
movl %esi, 0xc(%rsp)
callq 0x4310
cmpq %r15, %rax
je 0x14047
movq %rax, %r13
testq %rax, %rax
je 0x1406c
movq 0x20(%rsp), %r14
jmp 0x14135
movq %rbx, %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x13a1c
xorl %r12d, %r12d
testl %eax, %eax
jle 0x1417b
movq 0x8(%rbx), %rax
leaq 0x4004(%rax), %rdx
movl 0x4000(%rax), %ebp
movl 0x4004(%rax), %r14d
leaq 0x4000(%rax), %rdi
leal -0x4000(%rbp), %ecx
cmpl $0x4000, %ebp           # imm = 0x4000
cmovbl %ebp, %ecx
leaq (%rcx,%rax), %r15
testl %r14d, %r14d
movq %rdx, 0x10(%rsp)
jne 0x13f87
movq %rdi, 0x18(%rsp)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x13fb1
leal 0x1(%rbp), %eax
addl $0xffffc001, %ebp       # imm = 0xFFFFC001
cmpl $0x4000, %eax           # imm = 0x4000
cmovbl %eax, %ebp
movq 0x18(%rsp), %rax
movl %ebp, (%rax)
movq 0x10(%rsp), %rax
movl %r14d, (%rax)
jmp 0x14178
movl $0x4000, %ebp           # imm = 0x4000
movq 0x20(%rsp), %r14
movl %r12d, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4070
movq 0x8(%rbx), %r15
movl 0x4000(%r15), %eax
leal (%rax,%r12), %ecx
cmpl $0x4000, %ecx           # imm = 0x4000
leal -0x4000(%rax,%r12), %eax
cmovbl %ecx, %eax
movl 0x4004(%r15), %ecx
movl %eax, 0x4000(%r15)
subl %r12d, %ecx
movl %ecx, 0x4004(%r15)
jne 0x140e5
movq %rbx, %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x13a1c
testl %eax, %eax
jle 0x141a5
movq 0x8(%rbx), %r15
movl 0x4000(%r15), %eax
movl 0x4004(%r15), %ecx
leal -0x4000(%rax), %edx
cmpl $0x4000, %eax           # imm = 0x4000
cmovbl %eax, %edx
testl %ecx, %ecx
je 0x14114
leal (%rcx,%rax), %esi
cmpl %ebp, %esi
leal -0x4000(%rcx,%rax), %r12d
cmovbl %esi, %r12d
cmpl %edx, %r12d
cmovbel %ebp, %r12d
subl %edx, %r12d
jmp 0x14117
xorl %r12d, %r12d
addq %rdx, %r15
movl %r12d, %edx
movq %r15, %rdi
movl 0xc(%rsp), %esi
callq 0x4310
testq %rax, %rax
je 0x14076
movq %rax, %r13
subq %r15, %r13
movl %r13d, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4070
movq 0x8(%rbx), %rax
movl 0x4000(%rax), %ecx
movl %r13d, %edx
incl %edx
leal (%rcx,%r13), %esi
incl %esi
cmpl $0x4000, %esi           # imm = 0x4000
leal -0x3fff(%rcx,%r13), %ecx
cmovbl %esi, %ecx
movl %ecx, 0x4000(%rax)
subl %edx, 0x4004(%rax)
movb $0x1, %r12b
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1418f
cmpl $0x2, %edx
jne 0x141aa
movq %rax, %rdi
callq 0x4130
movb $0x1, 0x15(%rbx)
callq 0x44b0
xorl %r12d, %r12d
jmp 0x1417b
movq %rax, %rdi
callq 0xe590