// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movzbl 0x14(%rsi), %esi
movb %sil, 0x7(%rsp)
movq %rcx, %rdx
callq 0xb3e0
movb $0x0, 0x61(%r14)
movb 0x60(%r14), %al
cmpb $0xb, %al
jne 0x14e66
movb 0x7(%rsp), %al
movl %eax, %ecx
andb $-0x2, %cl
cmpb $0xe, %cl
jne 0x14eaa
cmpb $0xf, %al
setne %al
shlb $0x5, %al
orb $0x5b, %al
leaq 0x8(%rsp), %rsi
movb %al, (%rsi)
movq %rbx, %rdi
callq 0xb500
movq 0x40(%r14), %rax
movq 0x50(%r14), %rcx
decq %rcx
cmpq %rcx, %rax
je 0x14f17
movb 0x7(%rsp), %cl
movb %cl, (%rax)
incq %rax
movq %rax, 0x40(%r14)
jmp 0x14f25
cmpb $0xf, %al
je 0x14e15
cmpb $0x10, 0x7(%rsp)
je 0x14e15
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x15103
leaq 0x8(%rsp), %rsi
movb $0x3a, (%rsi)
movq %rbx, %rdi
callq 0xb500
cmpb $0x0, 0x8(%r14)
jne 0x14e15
leaq 0x8(%rsp), %rsi
movb $0x20, (%rsi)
movq %rbx, %rdi
callq 0xb500
jmp 0x14e15
cmpb $0x10, %al
jne 0x14f06
movq 0x40(%r14), %rax
cmpq 0x20(%r14), %rax
je 0x14fed
leaq 0x10(%r14), %r15
cmpb $0xf, 0x60(%r14)
setne %al
shlb $0x5, %al
orb $0x5d, %al
leaq 0x8(%rsp), %rsi
movb %al, (%rsi)
movq %rbx, %rdi
callq 0xb500
movq %r15, %rdi
callq 0xbbb0
movq 0x40(%r14), %rax
cmpq 0x20(%r14), %rax
je 0x14f52
cmpq 0x48(%r14), %rax
jne 0x14f01
movq 0x58(%r14), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movb -0x1(%rax), %al
jmp 0x14f2e
cmpb $0xb, %al
ja 0x14f3e
cmpb $0x0, 0x16(%r15)
jne 0x14f56
movq 0x8(%r15), %r14
jmp 0x14f5a
leaq 0x10(%r14), %rdi
leaq 0x7(%rsp), %rsi
callq 0xbe50
movb $0x1, 0x61(%r14)
movb 0x7(%rsp), %al
movb %al, 0x60(%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
xorl %edx, %edx
cmpb $0xd, %al
setne %al
cmpb $0x0, 0x16(%r15)
jne 0x14f9c
movq 0x8(%r15), %rcx
jmp 0x14fa0
movb $0xb, %al
jmp 0x14f2e
leaq 0x8(%r15), %r14
movl 0x10(%r15), %r15d
addq %r15, 0x50(%rbx)
cmpb $0x0, 0x80(%rbx)
je 0x14fbf
cmpq %r15, 0x58(%rbx)
jae 0x14f79
movq %rbx, %rdi
callq 0xb460
cmpq %r15, 0x60(%rbx)
jae 0x14f8a
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 0x14fca
leaq 0x8(%r15), %rcx
movl 0x10(%r15), %edi
leaq 0x8(%rsp), %rsi
movq %rcx, (%rsi)
movq %rdi, 0x8(%rsi)
movb %al, %dl
movq %rbx, %rdi
callq 0x15103
jmp 0x14f32
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb4f0
cmpl $0x1, %r15d
jne 0x14fda
movb (%r14), %cl
movb %cl, (%rax)
jmp 0x14f32
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xb790
jmp 0x14f32
leaq 0xa79c(%rip), %rdi      # 0x1f790
leaq 0xa7b0(%rip), %rsi      # 0x1f7ab
leaq 0xa7bb(%rip), %rcx      # 0x1f7bd
movl $0x84, %edx
callq 0xb540