// File: tap3edit[P]tap3xml/global.cpp
// Function: dec2bcd(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
string dec2bcd(const string &str)
{
    ostringstream bcd, rbcd;
    unsigned long long intstr, msb;
    string bcd_str;


    /* Note: For the moment we will not support numbers bigger than 2**31 */

    intstr=atoll(str.c_str());

    do
    {

        bcd << (uchar)(intstr&0xFF);
        msb=intstr&0x80;
        intstr>>=8;
        
    } while (intstr>0);

    if (msb && ( atoll(str.c_str()) > 0))
        bcd << (uchar)0x00;

    if (!msb && ( atoll(str.c_str()) < 0))
        bcd << (uchar)0xFF;

    bcd_str=bcd.str();
    
    string::reverse_iterator rii=bcd_str.rbegin();
    while (rii!=bcd_str.rend())
    {
        rbcd << *rii++;
    }

    return rbcd.str();
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3a0, %rsp            # imm = 0x3A0
movq %rdi, -0x388(%rbp)
movq %rdi, %rax
movq %rax, -0x380(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4540
leaq -0x300(%rbp), %rdi
callq 0x4540
jmp 0x1474e
leaq -0x340(%rbp), %rdi
callq 0x4570
movq -0x10(%rbp), %rdi
callq 0x4160
movq %rax, %rdi
callq 0x4290
movq %rax, -0x318(%rbp)
movzbl -0x318(%rbp), %esi
leaq -0x188(%rbp), %rdi
callq 0x45f0
jmp 0x14787
movq -0x318(%rbp), %rax
andq $0x80, %rax
movq %rax, -0x320(%rbp)
movq -0x318(%rbp), %rax
shrq $0x8, %rax
movq %rax, -0x318(%rbp)
cmpq $0x0, -0x318(%rbp)
ja 0x14772
cmpq $0x0, -0x320(%rbp)
je 0x14830
movq -0x10(%rbp), %rdi
callq 0x4160
movq %rax, %rdi
callq 0x4290
cmpq $0x0, %rax
jle 0x14830
leaq -0x188(%rbp), %rdi
xorl %esi, %esi
callq 0x45f0
jmp 0x147e8
jmp 0x14830
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x308(%rbp)
movl %eax, -0x30c(%rbp)
jmp 0x14980
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x308(%rbp)
movl %eax, -0x30c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x41e0
leaq -0x300(%rbp), %rdi
callq 0x40c0
jmp 0x14980
cmpq $0x0, -0x320(%rbp)
jne 0x14866
movq -0x10(%rbp), %rdi
callq 0x4160
movq %rax, %rdi
callq 0x4290
cmpq $0x0, %rax
jge 0x14866
leaq -0x188(%rbp), %rdi
movl $0xff, %esi
callq 0x45f0
jmp 0x14864
jmp 0x14866
leaq -0x360(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x4380
jmp 0x1487b
leaq -0x340(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x4490
leaq -0x360(%rbp), %rdi
callq 0x41e0
leaq -0x368(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0x46c0
leaq -0x370(%rbp), %rdi
movq %rdi, -0x398(%rbp)
leaq -0x340(%rbp), %rsi
callq 0x4450
movq -0x398(%rbp), %rsi
leaq -0x368(%rbp), %rdi
callq 0x16aa0
movb %al, -0x389(%rbp)
jmp 0x148e2
movb -0x389(%rbp), %al
testb $0x1, %al
jne 0x148ee
jmp 0x14937
leaq -0x378(%rbp), %rdi
leaq -0x368(%rbp), %rsi
xorl %edx, %edx
callq 0x16ad0
jmp 0x14905
leaq -0x378(%rbp), %rdi
callq 0x16b10
movq %rax, -0x3a0(%rbp)
jmp 0x1491a
movq -0x3a0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x300(%rbp), %rdi
callq 0x4430
jmp 0x14932
jmp 0x148ad
movq -0x388(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x4380
jmp 0x1494c
leaq -0x340(%rbp), %rdi
callq 0x41e0
leaq -0x300(%rbp), %rdi
callq 0x40c0
leaq -0x188(%rbp), %rdi
callq 0x40c0
movq -0x380(%rbp), %rax
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbp
retq
leaq -0x188(%rbp), %rdi
callq 0x40c0
movq -0x308(%rbp), %rdi
callq 0x46d0
nopl (%rax,%rax)