// File: /workspace/github_cpp_makefile_star2_O3/night-shift[P]Srl/src/lib/PJson.cpp
// Function: Srl::PJson::write(Srl::Value const&, Srl::Lib::MemBlock const&, Srl::Lib::Out&)
void PJson::write(const Value& value, const MemBlock& name, Out& out)
{
    auto type = value.type();
    this->insert_spacing(type, out);

    this->scope_closed = false;

    if(this->scope_type != Type::Null &&
       this->scope_type != Type::Array &&
       type != Type::Scope_End) {

        insert_in_quotes(out, name);
        out.write(':');

        if(!this->compact) {
            out.write(' ');
        }
    }

    if(TpTools::is_scope(type)) {

        auto c = type == Type::Array ? '[' : '{';

        out.write(c);
        this->scope_stack.push(type);
        this->scope_closed = true;
        this->scope_type = type;

        return;
    }

    if(type == Type::Scope_End) {

        assert(!this->scope_stack.empty());

        auto c = this->scope_type == Type::Array ? ']' : '}';

        out.write(c);
        this->scope_stack.pop();

        this->scope_type = !this->scope_stack.empty()
            ? this->scope_stack.top()
            : Type::Null;

        return;
    }

    if(TpTools::is_scalar(type)) {
        out.write(value.data(), value.size());

    } else {
        bool escape = type != Type::Binary;
        insert_in_quotes(out, { value.data(), value.size() }, escape);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movb 0x14(%rsi), %bpl
movb %bpl, 0xf(%rsp)
movzbl %bpl, %esi
movq %rcx, %rdx
callq 0xb3e0
movb $0x0, 0x61(%r14)
movb 0x60(%r14), %al
cmpb $0xb, %al
je 0x14cf6
cmpb $0xf, %al
sete %al
cmpb $0x10, %bpl
sete %cl
orb %al, %cl
jne 0x14cf6
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x14f9f
leaq 0x10(%rsp), %rsi
movb $0x3a, (%rsi)
movq %rbx, %rdi
callq 0xb500
cmpb $0x0, 0x8(%r14)
jne 0x14cf6
leaq 0x10(%rsp), %rsi
movb $0x20, (%rsi)
movq %rbx, %rdi
callq 0xb500
movl %ebp, %eax
andb $-0x2, %al
cmpb $0xe, %al
jne 0x14d3c
cmpb $0xf, %bpl
setne %al
shlb $0x5, %al
orb $0x5b, %al
leaq 0x10(%rsp), %rsi
movb %al, (%rsi)
movq %rbx, %rdi
callq 0xb500
movq 0x40(%r14), %rax
movq 0x50(%r14), %rcx
decq %rcx
cmpq %rcx, %rax
je 0x14dad
movb %bpl, (%rax)
incq %rax
movq %rax, 0x40(%r14)
jmp 0x14dc1
cmpb $0x10, %bpl
jne 0x14d9a
movq 0x40(%r14), %rax
cmpq 0x20(%r14), %rax
je 0x14e89
leaq 0x10(%r14), %r15
cmpb $0xf, 0x60(%r14)
setne %al
shlb $0x5, %al
orb $0x5d, %al
leaq 0x10(%rsp), %rsi
movb %al, (%rsi)
movq %rbx, %rdi
callq 0xb500
movq %r15, %rdi
callq 0xbbb0
movq 0x40(%r14), %rax
cmpq 0x20(%r14), %rax
je 0x14de5
cmpq 0x48(%r14), %rax
jne 0x14d95
movq 0x58(%r14), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movb -0x1(%rax), %al
jmp 0x14de7
cmpb $0xb, %bpl
ja 0x14dcf
cmpb $0x0, 0x16(%r15)
jne 0x14df0
movq 0x8(%r15), %r14
jmp 0x14df4
leaq 0x10(%r14), %rdi
leaq 0xf(%rsp), %rbx
movq %rbx, %rsi
callq 0xbe50
movb (%rbx), %bpl
movb $0x1, 0x61(%r14)
movb %bpl, 0x60(%r14)
jmp 0x14e7c
xorl %edx, %edx
cmpb $0xd, %bpl
setne %al
cmpb $0x0, 0x16(%r15)
jne 0x14e36
movq 0x8(%r15), %rcx
jmp 0x14e3a
movb $0xb, %al
movb %al, 0x60(%r14)
jmp 0x14e7c
leaq 0x8(%r15), %r14
movl 0x10(%r15), %r15d
addq %r15, 0x50(%rbx)
cmpb $0x0, 0x80(%rbx)
je 0x14e56
cmpq %r15, 0x58(%rbx)
jae 0x14e13
movq %rbx, %rdi
callq 0xb460
cmpq %r15, 0x60(%rbx)
jae 0x14e24
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbc90
subq %r15, 0x58(%rbx)
movq 0x70(%rbx), %rax
leaq (%rax,%r15), %rcx
movq %rcx, 0x70(%rbx)
jmp 0x14e61
leaq 0x8(%r15), %rcx
movl 0x10(%r15), %edi
leaq 0x10(%rsp), %rsi
movq %rcx, (%rsi)
movq %rdi, 0x8(%rsi)
movb %al, %dl
movq %rbx, %rdi
callq 0x14f9f
jmp 0x14e7c
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb4f0
cmpl $0x1, %r15d
jne 0x14e6e
movb (%r14), %cl
movb %cl, (%rax)
jmp 0x14e7c
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xb790
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9900(%rip), %rdi      # 0x1e790
leaq 0x9914(%rip), %rsi      # 0x1e7ab
leaq 0x991f(%rip), %rcx      # 0x1e7bd
movl $0x84, %edx
callq 0xb540