// File: night-shift[P]Srl/src/lib/Environment.cpp
// Function: Srl::Lib::Environment::write_conv(Srl::Value const&, Srl::String const&)
void Environment::write_conv(const Value& value, const String& val_name)
{
    MemBlock name_conv;

    if(val_name.encoding() == Encoding::UTF8) {
        name_conv = MemBlock(val_name.data(), val_name.size());

    } else {
        auto& buffer = this->str_buffer;
        auto size = Tools::conv_charset(Encoding::UTF8, val_name, buffer, true);
        name_conv = MemBlock(buffer.data(), size);
    }

    auto type = value.type();

    bool no_conversion_needed =
        /* scope types don't need conversion */
        TpTools::is_scope(type) || type == Type::Scope_End ||
        /* strings must be UTF8 in text formats */
        (type == Type::String && parser->get_format() != Format::Text &&
         value.encoding() == Encoding::UTF8) ||
        /* binary types must be converted to string in text formats */
        (type != Type::String && parser->get_format() == Format::Binary);

    if(no_conversion_needed) {
        parser->write(value, name_conv, this->out);

    } else {
        parser->write(this->conv_type(value), name_conv, this->out);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x374c0
movq -0x18(%rbp), %rdi
callq 0x342c0
cmpb $0x1, %al
jne 0x3dba3
movq -0x18(%rbp), %rdi
callq 0x33490
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
callq 0x37f50
movq -0x88(%rbp), %rsi
movq %rax, %rdx
leaq -0x38(%rbp), %rdi
callq 0x33280
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x3dbf7
movq -0x80(%rbp), %rax
addq $0x220, %rax            # imm = 0x220
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl $0x1, %ecx
xorl %eax, %eax
movl %eax, %r8d
movl %ecx, %edi
callq 0x37380
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x36f40
movq %rax, %rsi
movq -0x48(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x33280
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x35b80
movb %al, -0x59(%rbp)
movzbl -0x59(%rbp), %edi
callq 0x35db0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x89(%rbp)
jne 0x3dc90
movb $0x1, %al
cmpb $0x10, -0x59(%rbp)
movb %al, -0x89(%rbp)
je 0x3dc90
cmpb $0xc, -0x59(%rbp)
jne 0x3dc5b
movq -0x80(%rbp), %rax
movq 0x250(%rax), %rdi
movq (%rdi), %rax
callq *(%rax)
cmpb $0x1, %al
je 0x3dc5b
movq -0x10(%rbp), %rdi
callq 0x35830
movb %al, %cl
movb $0x1, %al
cmpb $0x1, %cl
movb %al, -0x89(%rbp)
je 0x3dc90
xorl %eax, %eax
cmpb $0xc, -0x59(%rbp)
movb %al, -0x8a(%rbp)
je 0x3dc84
movq -0x80(%rbp), %rax
movq 0x250(%rax), %rdi
movq (%rdi), %rax
callq *(%rax)
cmpb $0x0, %al
sete %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
andb $0x1, %al
movb %al, -0x5a(%rbp)
testb $0x1, -0x5a(%rbp)
je 0x3dcc3
movq -0x80(%rbp), %rcx
movq 0x250(%rcx), %rdi
movq -0x10(%rbp), %rsi
addq $0x2b0, %rcx            # imm = 0x2B0
movq (%rdi), %rax
leaq -0x28(%rbp), %rdx
callq *0x8(%rax)
jmp 0x3dd02
movq -0x80(%rbp), %rsi
movq 0x250(%rsi), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x33950
movq -0x80(%rbp), %rcx
movq -0x98(%rbp), %rdi
addq $0x2b0, %rcx            # imm = 0x2B0
movq (%rdi), %rax
leaq -0x78(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq *0x8(%rax)
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)