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

    if(type == Type::Scope_End) {
        assert(this->scope_stack.size() > 0);

        uint32_t scope_elems = this->scope->elements;
        auto scope_elems_be = swap_bytes(scope_elems);

        out.write(this->scope->ticket, (const uint8_t*)&scope_elems_be, 0, 4);
        this->scope_stack.pop();
        this->scope = this->scope_stack.size() > 0 ? &this->scope_stack.top() : nullptr;

        return;
    }

    if(this->scope) {
        if(this->scope->type == Type::Object) {
            write_str(name, out);
        }
        this->scope_stack.top().elements++;
    }


    if(TpTools::is_scope(type)) {
        this->write_scope(type, out);
        return;
    }

    srl_to_msgp(value, out);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdi, %r14
movb 0x14(%rsi), %bpl
cmpb $0x10, %bpl
jne 0x1bd90
leaq 0x20(%r14), %r15
movq %r15, %rdi
callq 0x12740
testq %rax, %rax
je 0x1c20c
movq 0x70(%r14), %r12
movl 0x4(%r12), %edi
callq 0x1c24a
leaq 0x8(%rsp), %rdx
movl %eax, (%rdx)
addq $0x8, %r12
xorl %r13d, %r13d
pushq $0x4
popq %r8
movq %rbx, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x12790
movq %r15, %rdi
callq 0x114a0
movq %r15, %rdi
callq 0x12740
testq %rax, %rax
je 0x1bd7d
movq 0x50(%r14), %r13
cmpq 0x58(%r14), %r13
jne 0x1bd79
movq 0x68(%r14), %rax
movl $0x1e0, %r13d           # imm = 0x1E0
addq -0x8(%rax), %r13
addq $-0x28, %r13
movq %r13, 0x70(%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r15
movq 0x70(%r14), %rax
testq %rax, %rax
je 0x1bdc6
cmpb $0xe, (%rax)
jne 0x1bdac
movq %rdx, %rdi
movq %rbx, %rsi
callq 0x1c26d
movq 0x50(%r14), %rax
cmpq 0x58(%r14), %rax
jne 0x1bdc3
movq 0x68(%r14), %rcx
movl $0x1e0, %eax            # imm = 0x1E0
addq -0x8(%rcx), %rax
incl -0x24(%rax)
movl %ebp, %eax
andb $-0x2, %al
cmpb $0xe, %al
jne 0x1bdeb
movzbl %bpl, %esi
movq %r14, %rdi
movq %rbx, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x128d0
movzbl 0x14(%r15), %eax
cmpq $0xd, %rax
ja 0x1c22b
leaq 0x5b77(%rip), %rcx      # 0x21978
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpq $0x1, 0x8(%r15)
movl $0xc3, %esi
sbbl $0x0, %esi
movq %rbx, %rdi
jmp 0x1be24
movq %rbx, %rdi
movl $0xc0, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12160
movb $-0x33, 0x7(%rsp)
movzwl 0x8(%r15), %r14d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
rolw $0x8, %r14w
leaq 0x8(%rsp), %r15
movw %r14w, (%r15)
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r15, %rsi
callq 0x11770
jmp 0x1bd81
cmpb $0x0, 0x16(%r15)
jne 0x1c163
movq 0x8(%r15), %rax
jmp 0x1c167
movq %rbx, %rdi
movl $0xca, %esi
callq 0x12160
movss 0x8(%r15), %xmm0
callq 0x1ca80
leaq 0x8(%rsp), %rsi
movss %xmm0, (%rsi)
movq %rbx, %rdi
callq 0x11c40
jmp 0x1bd81
movb $-0x34, 0x8(%rsp)
movzbl 0x8(%r15), %r14d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
leaq 0x7(%rsp), %r15
movb %r14b, (%r15)
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r15, %rsi
callq 0x11e50
jmp 0x1bd81
movb $-0x2f, 0x7(%rsp)
movq 0x8(%r15), %r15
testw %r15w, %r15w
js 0x1bf2b
movl %r15d, %edi
andl $0x7fff, %edi           # imm = 0x7FFF
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
movswq %r15w, %rdi
movq %rbx, %rsi
callq 0x1c9f3
testb %al, %al
jne 0x1bd81
rolw $0x8, %r15w
leaq 0x8(%rsp), %r14
movw %r15w, (%r14)
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11940
jmp 0x1bd81
movb $-0x2d, 0x7(%rsp)
movq 0x8(%r15), %r14
testq %r14, %r14
js 0x1bf8b
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1c9f3
testb %al, %al
jne 0x1bd81
movq %r14, %rdi
callq 0x1ca36
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x12a70
jmp 0x1bd81
movb $-0x30, 0x8(%rsp)
movq 0x8(%r15), %r15
testb %r15b, %r15b
js 0x1bfef
movl %r15d, %edi
andl $0x7f, %edi
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
movsbq %r15b, %rdi
movq %rbx, %rsi
callq 0x1c9f3
testb %al, %al
jne 0x1bd81
leaq 0x7(%rsp), %r14
movb %r15b, (%r14)
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11130
jmp 0x1bd81
movb $-0x2e, 0x7(%rsp)
movq 0x8(%r15), %r14
testl %r14d, %r14d
js 0x1c04f
movl %r14d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
movslq %r14d, %rdi
movq %rbx, %rsi
callq 0x1c9f3
testb %al, %al
jne 0x1bd81
movl %r14d, %edi
callq 0x1ca13
leaq 0x8(%rsp), %r14
movl %eax, (%r14)
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x12c40
jmp 0x1bd81
cmpb $0x0, 0x16(%r15)
jne 0x1c184
movq 0x8(%r15), %r14
jmp 0x1c188
movb $-0x32, 0x7(%rsp)
movl 0x8(%r15), %r14d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
movl %r14d, %edi
callq 0x1c24a
leaq 0x8(%rsp), %r14
movl %eax, (%r14)
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x110f0
jmp 0x1bd81
movq %rbx, %rdi
movl $0xcb, %esi
callq 0x12160
movsd 0x8(%r15), %xmm0
callq 0x1caa7
leaq 0x8(%rsp), %rsi
movsd %xmm0, (%rsi)
movq %rbx, %rdi
callq 0x12ab0
jmp 0x1bd81
movb $-0x31, 0x7(%rsp)
movq 0x8(%r15), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1c9d0
testb %al, %al
jne 0x1bd81
movq %r14, %rdi
callq 0x1ca5b
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x11e50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11060
jmp 0x1bd81
leaq 0x8(%r15), %rax
movl 0x10(%r15), %ecx
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
movq %rcx, 0x8(%rdi)
movq %rbx, %rsi
callq 0x1c26d
jmp 0x1bd81
leaq 0x8(%r15), %r14
movl 0x10(%r15), %r15d
cmpq $0xff, %r15
ja 0x1c1b0
movq %rbx, %rdi
movl $0xc4, %esi
callq 0x12160
movzbl %r15b, %esi
movq %rbx, %rdi
callq 0x12160
jmp 0x1c1f9
leaq 0x8(%rsp), %r12
cmpl $0xfffe, %r15d          # imm = 0xFFFE
ja 0x1c1dd
movw %r15w, (%r12)
movq %rbx, %rdi
movl $0xc5, %esi
callq 0x12160
movq %rbx, %rdi
movq %r12, %rsi
callq 0x11770
jmp 0x1c1f9
movl %r15d, (%r12)
movq %rbx, %rdi
movl $0xc6, %esi
callq 0x12160
movq %rbx, %rdi
movq %r12, %rsi
callq 0x110f0
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x120f0
jmp 0x1bd81
leaq 0x57ea(%rip), %rdi      # 0x219fd
leaq 0x5800(%rip), %rsi      # 0x21a1a
leaq 0x580e(%rip), %rcx      # 0x21a2f
movl $0x178, %edx            # imm = 0x178
callq 0x11890
leaq 0x57e6(%rip), %rdi      # 0x21a18
leaq 0x57e1(%rip), %rsi      # 0x21a1a
leaq 0x58b6(%rip), %rcx      # 0x21af6
movl $0xc2, %edx
callq 0x11890