// File: /workspace/github_cpp_makefile_star2_O2/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), %ecx
leal -0x1(%rcx), %eax
cmpb $0x9, %al
ja 0x1d677
cmpb $0x8, %cl
ja 0x1d693
movb $0x1, %al
testb $0x1, %cl
je 0x1d6cd
movq 0x8(%r14), %rax
shrq $0x3c, %rax
andb $0x8, %al
incb %al
jmp 0x1d6cd
movl %ecx, %eax
andl $-0x2, %eax
cmpl $0xe, %eax
je 0x1d6a0
cmpl $0xc, %eax
jne 0x1d6ac
cmpl $0xc, %ecx
sete %al
shlb $0x4, %al
addb $0x10, %al
jmp 0x1d6cd
cmpl $0x9, %ecx
setne %al
shlb $0x4, %al
addb $0x11, %al
jmp 0x1d6cd
cmpl $0xf, %ecx
movl $0x80, %ecx
pushq $0x40
jmp 0x1d6c9
cmpl $0xb, %ecx
je 0x1d75f
testl %ecx, %ecx
jne 0x1d766
cmpq $0x0, 0x8(%r14)
movl $0x81, %ecx
pushq $0x41
popq %rax
cmovel %ecx, %eax
movzbl %al, %esi
movq %r15, %rdi
movq %rbx, %rcx
callq 0x11dd0
movzbl 0x14(%r14), %esi
movl %esi, %eax
andb $-0x2, %al
cmpb $0xe, %al
jne 0x1d6f5
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x129e0
testl %esi, %esi
je 0x1d71c
cmpl $0xb, %esi
je 0x1d71c
cmpl $0xa, %esi
je 0x1d722
cmpl $0x9, %esi
jne 0x1d736
addq $0x8, %r14
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x11c40
popq %rbx
popq %r14
popq %r15
retq
addq $0x8, %r14
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x12ab0
cmpb $0x8, %sil
ja 0x1d78b
movq 0x8(%r14), %rax
movq %rax, %rdi
negq %rdi
cmovsq %rax, %rdi
testb $0x1, %sil
cmoveq %rax, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x1d492
movb $0x8, %al
jmp 0x1d6cd
movq %rbx, %rdi
xorl %esi, %esi
callq 0x12160
leaq 0x78(%r15), %rdi
callq 0x12300
testq %rax, %rax
je 0x1d7bd
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x12ac0
cmpb $0xc, %al
jne 0x1d7dc
movl 0x10(%r14), %edi
movq %rbx, %rsi
callq 0x1d492
cmpb $0x0, 0x16(%r14)
jne 0x1d7a8
movq 0x8(%r14), %rsi
jmp 0x1d7ac
leaq 0x8(%r14), %rsi
movl 0x10(%r14), %edx
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x120f0
leaq 0x4239(%rip), %rdi      # 0x219fd
leaq 0x43eb(%rip), %rsi      # 0x21bb6
leaq 0x43f5(%rip), %rcx      # 0x21bc7
movl $0xb5, %edx
callq 0x11890
leaq 0x442a(%rip), %rdi      # 0x21c0d
leaq 0x43cc(%rip), %rsi      # 0x21bb6
leaq 0x43d6(%rip), %rcx      # 0x21bc7
movl $0xd8, %edx
callq 0x11890
nop