// File: /workspace/github_cpp_makefile_star2_O2/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 0x11620
movb $0x0, 0x61(%r14)
movb 0x60(%r14), %al
cmpb $0xb, %al
je 0x19c9e
cmpb $0xf, %al
sete %al
cmpb $0x10, %bpl
sete %cl
orb %al, %cl
jne 0x19c9e
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x19e63
leaq 0x10(%rsp), %rsi
movb $0x3a, (%rsi)
movq %rbx, %rdi
callq 0x11800
cmpb $0x0, 0x8(%r14)
jne 0x19c9e
leaq 0x10(%rsp), %rsi
movb $0x20, (%rsi)
movq %rbx, %rdi
callq 0x11800
movl %ebp, %eax
andb $-0x2, %al
cmpb $0xe, %al
jne 0x19cde
cmpb $0xf, %bpl
setne %al
shlb $0x5, %al
orb $0x5b, %al
leaq 0x10(%rsp), %rsi
movb %al, (%rsi)
movq %rbx, %rdi
callq 0x11800
leaq 0x10(%r14), %rdi
leaq 0xf(%rsp), %rbx
movq %rbx, %rsi
callq 0x11030
movb $0x1, 0x61(%r14)
movb (%rbx), %al
jmp 0x19d67
cmpb $0x10, %bpl
jne 0x19d3c
movq 0x40(%r14), %rax
cmpq 0x20(%r14), %rax
je 0x19daa
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 0x11800
movq %r15, %rdi
callq 0x123e0
movq 0x40(%r14), %rax
cmpq 0x20(%r14), %rax
je 0x19d65
cmpq 0x48(%r14), %rax
jne 0x19d37
movq 0x58(%r14), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movb -0x1(%rax), %al
jmp 0x19d67
cmpb $0xb, %bpl
ja 0x19d4f
cmpb $0x0, 0x16(%r15)
jne 0x19d78
movq 0x8(%r15), %rsi
jmp 0x19d7c
xorl %edx, %edx
cmpb $0xd, %bpl
setne %al
cmpb $0x0, 0x16(%r15)
jne 0x19d8a
movq 0x8(%r15), %rcx
jmp 0x19d8e
movb $0xb, %al
movb %al, 0x60(%r14)
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%r15), %rsi
movl 0x10(%r15), %edx
movq %rbx, %rdi
callq 0x120f0
jmp 0x19d6b
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 0x19e63
jmp 0x19d6b
leaq 0x79ff(%rip), %rdi      # 0x217b0
leaq 0x7a13(%rip), %rsi      # 0x217cb
leaq 0x7a1e(%rip), %rcx      # 0x217dd
movl $0x84, %edx
callq 0x11890
nop