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

    if(!flag) {
        out.write_byte(0);

        assert(this->scope_stack.size() > 0);
        this->pop_scope();
        return;
    }

    this->write_head(flag, name, out);

    auto type = value.type();
    /* scope-starts carry no additional information */
    if(TpTools::is_scope(type)) {
        this->push_scope(type);

        return;
    }

    /* do nothing on null-type, flag already carries bool value */
    if(type == Type::Null || type == Type::Bool) {
        return;
    }

    if(type == Type::FP32) {
        out.write(value.pblock().fp32);

    } else if(type == Type::FP64) {
        out.write(value.pblock().fp64);

    } else if(TpTools::is_integral(type)) {

        uint64_t integer = TpTools::is_signed(type) && value.pblock().i64 < 0
            ? -value.pblock().i64
            : value.pblock().ui64;

        encode_integer(integer, out);

    } else {
        assert(type == Type::Binary || type == Type::String);

        encode_integer(value.size(), out);
        out.write(value.data(), value.size());
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movzbl 0x14(%rsi), %eax
leal -0x1(%rax), %esi
leal -0x9(%rax), %ecx
cmpb $0x7, %sil
ja 0x1a015
cmpb $0x2, %cl
setae %cl
testb $0x1, %al
sete %sil
movb $0x1, %al
testb %sil, %cl
jne 0x1a075
movq 0x8(%r14), %rax
shrq $0x3c, %rax
andb $0x8, %al
incb %al
jmp 0x1a075
cmpb $0x1, %cl
ja 0x1a027
cmpl $0x9, %eax
setne %al
shlb $0x4, %al
addb $0x11, %al
jmp 0x1a075
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0xe, %ecx
je 0x1a043
cmpl $0xc, %ecx
jne 0x1a052
cmpl $0xc, %eax
sete %al
shlb $0x4, %al
addb $0x10, %al
jmp 0x1a075
cmpl $0xf, %eax
movl $0x80, %ecx
movl $0x40, %eax
jmp 0x1a072
cmpl $0xb, %eax
je 0x1a1f0
testl %eax, %eax
jne 0x1a1f7
cmpq $0x0, 0x8(%r14)
movl $0x81, %ecx
movl $0x41, %eax
cmovel %ecx, %eax
testb %al, %al
je 0x1a0a1
movzbl %al, %esi
movq %r15, %rdi
movq %rbx, %rcx
callq 0xb8a0
movzbl 0x14(%r14), %esi
movl %esi, %eax
andb $-0x2, %al
cmpb $0xe, %al
jne 0x1a0e3
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xbed0
incq 0x50(%rbx)
cmpb $0x0, 0x80(%rbx)
je 0x1a111
cmpq $0x0, 0x58(%rbx)
jne 0x1a0bd
movq %rbx, %rdi
callq 0xb460
cmpq $0x0, 0x60(%rbx)
jne 0x1a0d1
movl $0x1, %esi
movq %rbx, %rdi
callq 0xbc90
decq 0x58(%rbx)
movq 0x70(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x70(%rbx)
jmp 0x1a11e
cmpl $0x9, %esi
jg 0x1a174
testl %esi, %esi
je 0x1a17e
cmpl $0x9, %esi
jne 0x1a184
addq $0x8, %r14
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xb7d0
movl $0x1, %esi
movq %rbx, %rdi
callq 0xb4f0
movb $0x0, (%rax)
movq 0xa8(%r15), %rax
movq 0xc0(%r15), %rcx
movq %rcx, %rdx
subq 0xa0(%r15), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rcx
adcq $-0x1, %rdx
subq 0xb0(%r15), %rax
addq 0x98(%r15), %rax
shlq $0x9, %rdx
addq %rdx, %rax
cmpq 0x88(%r15), %rax
je 0x1a27a
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xbf50
cmpl $0xa, %esi
je 0x1a1bb
cmpl $0xb, %esi
jne 0x1a184
popq %rbx
popq %r14
popq %r15
retq
cmpb $0x8, %sil
ja 0x1a1cf
leal -0x9(%rsi), %eax
cmpb $0x2, %al
setae %al
testb $0x1, %sil
sete %cl
testb %cl, %al
jne 0x1a1aa
movq 0x8(%r14), %rdi
testq %rdi, %rdi
js 0x1a272
movq 0x8(%r14), %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x19d0b
addq $0x8, %r14
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xbf40
cmpb $0xc, %al
jne 0x1a299
movl 0x10(%r14), %edi
movq %rbx, %rsi
callq 0x19d0b
cmpb $0x0, 0x16(%r14)
jne 0x1a1fe
movq 0x8(%r14), %r15
jmp 0x1a202
movb $0x8, %al
jmp 0x1a075
xorl %eax, %eax
jmp 0x1a075
leaq 0x8(%r14), %r15
movl 0x10(%r14), %r14d
addq %r14, 0x50(%rbx)
cmpb $0x0, 0x80(%rbx)
je 0x1a244
cmpq %r14, 0x58(%rbx)
jae 0x1a221
movq %rbx, %rdi
callq 0xb460
cmpq %r14, 0x60(%rbx)
jae 0x1a232
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbc90
subq %r14, 0x58(%rbx)
movq 0x70(%rbx), %rax
leaq (%rax,%r14), %rcx
movq %rcx, 0x70(%rbx)
jmp 0x1a24f
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb4f0
cmpl $0x1, %r14d
jne 0x1a25f
movb (%r15), %cl
movb %cl, (%rax)
jmp 0x1a17e
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0xb790
negq %rdi
jmp 0x1a1ae
leaq 0x575c(%rip), %rdi      # 0x1f9dd
leaq 0x590e(%rip), %rsi      # 0x1fb96
leaq 0x5918(%rip), %rcx      # 0x1fba7
movl $0xb5, %edx
callq 0xb540
leaq 0x594d(%rip), %rdi      # 0x1fbed
leaq 0x58ef(%rip), %rsi      # 0x1fb96
leaq 0x58f9(%rip), %rcx      # 0x1fba7
movl $0xd8, %edx
callq 0xb540