// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movq %rdi, %r14
movq 0x8(%rsi), %rax
movzbl 0x14(%rsi), %esi
leal -0x1(%rsi), %ecx
cmpb $0x9, %cl
ja 0x19c92
cmpb $0x8, %sil
ja 0x19caf
movb $0x1, %cl
testb $0x1, %sil
je 0x19ced
shrq $0x3c, %rax
andb $0x8, %al
incb %al
movl %eax, %ecx
jmp 0x19ced
movl %esi, %ecx
andl $-0x2, %ecx
cmpl $0xe, %ecx
je 0x19cbd
cmpl $0xc, %ecx
jne 0x19ccc
cmpl $0xc, %esi
sete %cl
shlb $0x4, %cl
addb $0x10, %cl
jmp 0x19ced
cmpl $0x9, %esi
setne %cl
shlb $0x4, %cl
addb $0x11, %cl
jmp 0x19ced
cmpl $0xf, %esi
movl $0x80, %eax
movl $0x40, %ecx
jmp 0x19cea
cmpl $0xb, %esi
je 0x19d7f
testl %esi, %esi
jne 0x19d86
testq %rax, %rax
movl $0x81, %eax
movl $0x41, %ecx
cmovel %eax, %ecx
movzbl %cl, %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0xb8a0
movzbl 0x14(%r15), %esi
movl %esi, %eax
andb $-0x2, %al
cmpb $0xe, %al
jne 0x19d15
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xbed0
leaq 0x8(%r15), %r14
cmpl $0x9, %esi
jg 0x19d37
testl %esi, %esi
je 0x19d41
cmpl $0x9, %esi
jne 0x19d47
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xb7d0
cmpl $0xa, %esi
je 0x19d6f
cmpl $0xb, %esi
jne 0x19d47
popq %rbx
popq %r14
popq %r15
retq
cmpb $0x8, %sil
ja 0x19dcc
movq (%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 0x19993
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xbf40
movb $0x8, %cl
jmp 0x19ced
incq 0x50(%rbx)
cmpb $0x0, 0x80(%rbx)
je 0x19e31
cmpq $0x0, 0x58(%rbx)
jne 0x19da6
movq %rbx, %rdi
callq 0xb460
cmpq $0x0, 0x60(%rbx)
jne 0x19dba
movl $0x1, %esi
movq %rbx, %rdi
callq 0xbc90
decq 0x58(%rbx)
movq 0x70(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x70(%rbx)
jmp 0x19e3e
cmpb $0xc, %al
jne 0x19edd
movl 0x10(%r15), %edi
movq %rbx, %rsi
callq 0x19993
cmpb $0x0, 0x16(%r15)
jne 0x19deb
movq 0x8(%r15), %r14
movl 0x10(%r15), %r15d
addq %r15, 0x50(%rbx)
cmpb $0x0, 0x80(%rbx)
je 0x19e90
cmpq %r15, 0x58(%rbx)
jae 0x19e0e
movq %rbx, %rdi
callq 0xb460
cmpq %r15, 0x60(%rbx)
jae 0x19e1f
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 0x19e9b
movl $0x1, %esi
movq %rbx, %rdi
callq 0xb4f0
movb $0x0, (%rax)
movq 0xa8(%r14), %rax
movq 0xc0(%r14), %rcx
movq %rcx, %rdx
subq 0xa0(%r14), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rcx
adcq $-0x1, %rdx
subq 0xb0(%r14), %rax
addq 0x98(%r14), %rax
shlq $0x9, %rdx
addq %rdx, %rax
cmpq 0x88(%r14), %rax
je 0x19ebe
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xbf50
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb4f0
cmpl $0x1, %r15d
jne 0x19eab
movb (%r14), %cl
movb %cl, (%rax)
jmp 0x19d41
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0xb790
leaq 0x4b18(%rip), %rdi      # 0x1e9dd
leaq 0x4cca(%rip), %rsi      # 0x1eb96
leaq 0x4cd4(%rip), %rcx      # 0x1eba7
movl $0xb5, %edx
callq 0xb540
leaq 0x4d09(%rip), %rdi      # 0x1ebed
leaq 0x4cab(%rip), %rsi      # 0x1eb96
leaq 0x4cb5(%rip), %rcx      # 0x1eba7
movl $0xd8, %edx
callq 0xb540