// File: marxn[P]pupp/src/parser/constval.cpp
// Function: ConstValueCast(ConstValue*, DataType)
ConstValue * ConstValueCast(ConstValue * value, DataType dst_type)
{
        switch(dst_type)
        {
                case String:
                        return new StringValue(value->toString());
                break;
                case Decimal:
                        return new DecimalValue(value->toString());
                break;
                case Integer:
                        {
                                string s = value->toString();
                                long value = 0;
                                if(sscanf(s.c_str(), "%ld", &value)==0)
                                {
                                        return NULL;
                                }
                        }

                        return new IntegerValue(value->toString());
                break;
                case Boolean:
                        if(value->GetType()!=Boolean)
                        {
                                string s = value->toString();
                                if(s=="0" || s=="")
                                {
                                        return new BooleanValue(false);
                                }

                                return new BooleanValue(true);
                        }

                        value->DupValue();
                break;
        }

        return NULL;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x128(%rsp)
movl %esi, 0x124(%rsp)
movl 0x124(%rsp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x48(%rsp)
subl $0x3, %eax
ja 0xaa9f
movq 0x48(%rsp), %rax
leaq 0x54a15(%rip), %rcx     # 0x5f070
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x30, %edi
callq 0x62f0
movq %rax, 0x40(%rsp)
movb $0x1, 0xf3(%rsp)
movq 0x128(%rsp), %rsi
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq 0x100(%rsp), %rdi
callq *%rax
jmp 0xa696
movq 0x40(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x7c00
jmp 0xa6aa
movq 0x40(%rsp), %rax
movb $0x0, 0xf3(%rsp)
movq %rax, 0x130(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x61e0
jmp 0xaaab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0xa708
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x61e0
testb $0x1, 0xf3(%rsp)
jne 0xa714
jmp 0xa723
movq 0x40(%rsp), %rdi
movl $0x30, %esi
callq 0x6300
jmp 0xaabb
movl $0x28, %edi
callq 0x62f0
movq %rax, 0x38(%rsp)
movb $0x1, 0xcf(%rsp)
movq 0x128(%rsp), %rsi
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq 0xd0(%rsp), %rdi
callq *%rax
jmp 0xa75a
movq 0x38(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x8220
jmp 0xa76e
movq 0x38(%rsp), %rax
movb $0x0, 0xcf(%rsp)
movq %rax, 0x130(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x61e0
jmp 0xaaab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0xa7cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x61e0
testb $0x1, 0xcf(%rsp)
jne 0xa7d8
jmp 0xa7e7
movq 0x38(%rsp), %rdi
movl $0x28, %esi
callq 0x6300
jmp 0xaabb
movq 0x128(%rsp), %rsi
movq (%rsi), %rax
leaq 0xa8(%rsp), %rdi
callq *0x18(%rax)
movq $0x0, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x6150
movq %rax, %rdi
leaq 0x5a372(%rip), %rsi     # 0x64b97
leaq 0xa0(%rsp), %rdx
movb $0x0, %al
callq 0x62c0
cmpl $0x0, %eax
jne 0xa852
movq $0x0, 0x130(%rsp)
movl $0x1, 0x9c(%rsp)
jmp 0xa85d
movl $0x0, 0x9c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x61e0
movl 0x9c(%rsp), %eax
testl %eax, %eax
je 0xa87c
jmp 0xa877
jmp 0xaaab
movl $0x18, %edi
callq 0x62f0
movq %rax, 0x30(%rsp)
movb $0x1, 0x77(%rsp)
movq 0x128(%rsp), %rsi
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq 0x78(%rsp), %rdi
callq *%rax
jmp 0xa8a8
movq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x7f00
jmp 0xa8b9
movq 0x30(%rsp), %rax
movb $0x0, 0x77(%rsp)
movq %rax, 0x130(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x61e0
jmp 0xaaab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0xa90e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x61e0
testb $0x1, 0x77(%rsp)
jne 0xa917
jmp 0xa926
movq 0x30(%rsp), %rdi
movl $0x18, %esi
callq 0x6300
jmp 0xaabb
movq 0x128(%rsp), %rdi
callq 0x7870
cmpl $0x3, %eax
je 0xaa91
movq 0x128(%rsp), %rsi
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq 0x50(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq *%rax
movq 0x20(%rsp), %rdi
leaq 0x5973b(%rip), %rsi     # 0x640a3
callq 0xab10
movb %al, 0x2f(%rsp)
jmp 0xa973
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0xa99e
jmp 0xa97d
leaq 0x5469a(%rip), %rsi     # 0x5f01e
leaq 0x50(%rsp), %rdi
callq 0xab10
movb %al, 0x1f(%rsp)
jmp 0xa994
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0xa99e
jmp 0xaa18
movl $0x10, %edi
callq 0x62f0
movq %rax, 0x10(%rsp)
jmp 0xa9af
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x8c00
jmp 0xa9bd
movq 0x10(%rsp), %rax
movq %rax, 0x130(%rsp)
movl $0x1, 0x9c(%rsp)
jmp 0xaa79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0xaa85
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
movl $0x10, %esi
callq 0x6300
jmp 0xaa85
movl $0x10, %edi
callq 0x62f0
movq %rax, 0x8(%rsp)
jmp 0xaa29
movq 0x8(%rsp), %rdi
movl $0x1, %esi
callq 0x8c00
jmp 0xaa3a
movq 0x8(%rsp), %rax
movq %rax, 0x130(%rsp)
movl $0x1, 0x9c(%rsp)
jmp 0xaa79
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
movl $0x10, %esi
callq 0x6300
jmp 0xaa85
leaq 0x50(%rsp), %rdi
callq 0x61e0
jmp 0xaaab
leaq 0x50(%rsp), %rdi
callq 0x61e0
jmp 0xaabb
movq 0x128(%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq $0x0, 0x130(%rsp)
movq 0x130(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xf8(%rsp), %rdi
callq 0x6550
nopl (%rax,%rax)