// File: rofl0r[P]ascc/cs_parser.cpp
// Function: accept_literal_or_constant_value(int, int&, bool, char const*)
int accept_literal_or_constant_value(int fromSym, int &theValue, bool isNegative, const char *errorMsg) {
  if (sym.get_type(fromSym) == SYM_LITERALVALUE) {

    // Prepend '-' so we can parse -2147483648
    std::string literalStrValue = std::string(sym.get_name(fromSym));
    if (isNegative) {
        literalStrValue = '-' + literalStrValue;
    }

    errno = 0;
    char *endptr = 0;
    const long longValue = strtol(literalStrValue.c_str(), &endptr, 10);

    if ((longValue == LONG_MIN || longValue == LONG_MAX) && errno == ERANGE) {
        cc_error("Could not parse integer symbol '%s' because of overflow.", friendly_int_symbol(fromSym, isNegative).c_str());
        return -1;
    }
    if (endptr[0] != 0) {
        cc_error("Could not parse integer symbol '%s' because the whole buffer wasn't converted.", friendly_int_symbol(fromSym, isNegative).c_str());
        return -1;
    }
    if (longValue > INT_MAX || longValue < INT_MIN) {
        cc_error("Could not parse integer symbol '%s' because of overflow.", friendly_int_symbol(fromSym, isNegative).c_str());
        return -1;
    }

    theValue = static_cast<int>(longValue);
  }
  else if (sym.get_type(fromSym) == SYM_CONSTANT) {
    theValue = sym.entries[fromSym].soffs;
    if (isNegative) {
        theValue = -theValue;
    }
  }
  else {
    cc_error((char*)errorMsg);
    return -1;
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movb %dl, %al
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movl -0x8(%rbp), %esi
leaq 0x3a169(%rip), %rdi     # 0x42870
callq 0x1e1e0
cmpl $0x13, %eax
jne 0x89e1
movl -0x8(%rbp), %esi
leaq 0x3a151(%rip), %rdi     # 0x42870
callq 0x1f730
movq %rax, -0x100(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x4680
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x18000
jmp 0x8754
leaq -0x41(%rbp), %rdi
callq 0x43e0
testb $0x1, -0x11(%rbp)
je 0x87ba
leaq -0x78(%rbp), %rdi
movl $0x2d, %esi
leaq -0x40(%rbp), %rdx
callq 0x180b0
jmp 0x8777
leaq -0x40(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x4490
leaq -0x78(%rbp), %rdi
callq 0x4270
jmp 0x87ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x43e0
jmp 0x8a51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x89d6
callq 0x4080
movl $0x0, (%rax)
movq $0x0, -0x80(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x41b0
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
movl $0xa, %edx
callq 0x4520
movq %rax, -0x88(%rbp)
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
cmpq %rax, -0x88(%rbp)
je 0x8818
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rax, -0x88(%rbp)
jne 0x8898
callq 0x4080
cmpl $0x22, (%rax)
jne 0x8898
movl -0x8(%rbp), %esi
movzbl -0x11(%rbp), %edx
andl $0x1, %edx
leaq -0xa8(%rbp), %rdi
callq 0x8640
jmp 0x883a
leaq -0xa8(%rbp), %rdi
callq 0x41b0
movq %rax, %rsi
leaq 0x2922d(%rip), %rdi     # 0x31a7d
xorl %eax, %eax
callq 0x1bac0
jmp 0x8859
leaq -0xa8(%rbp), %rdi
callq 0x4270
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xac(%rbp)
jmp 0x89bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x4270
jmp 0x89d6
movq -0x80(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x891a
movl -0x8(%rbp), %esi
movzbl -0x11(%rbp), %edx
andl $0x1, %edx
leaq -0xd0(%rbp), %rdi
callq 0x8640
jmp 0x88bc
leaq -0xd0(%rbp), %rdi
callq 0x41b0
movq %rax, %rsi
leaq 0x291e4(%rip), %rdi     # 0x31ab6
xorl %eax, %eax
callq 0x1bac0
jmp 0x88db
leaq -0xd0(%rbp), %rdi
callq 0x4270
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xac(%rbp)
jmp 0x89bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x4270
jmp 0x89d6
cmpq $0x7fffffff, -0x88(%rbp) # imm = 0x7FFFFFFF
jg 0x8934
cmpq $-0x80000000, -0x88(%rbp) # imm = 0x80000000
jge 0x89a4
movl -0x8(%rbp), %esi
movzbl -0x11(%rbp), %edx
andl $0x1, %edx
leaq -0xf0(%rbp), %rdi
callq 0x8640
jmp 0x894c
leaq -0xf0(%rbp), %rdi
callq 0x41b0
movq %rax, %rsi
leaq 0x2911b(%rip), %rdi     # 0x31a7d
xorl %eax, %eax
callq 0x1bac0
jmp 0x896b
leaq -0xf0(%rbp), %rdi
callq 0x4270
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xac(%rbp)
jmp 0x89bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x4270
jmp 0x89d6
movq -0x88(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0xac(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4270
movl -0xac(%rbp), %eax
testl %eax, %eax
je 0x89d4
jmp 0x89d2
jmp 0x8a45
jmp 0x8a3e
leaq -0x40(%rbp), %rdi
callq 0x4270
jmp 0x8a51
movl -0x8(%rbp), %esi
leaq 0x39e85(%rip), %rdi     # 0x42870
callq 0x1e1e0
cmpl $0x14, %eax
jne 0x8a28
movslq -0x8(%rbp), %rsi
leaq 0x39e70(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movl 0x34(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
testb $0x1, -0x11(%rbp)
je 0x8a26
movq -0x10(%rbp), %rax
xorl %ecx, %ecx
subl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x8a3c
movq -0x20(%rbp), %rdi
movb $0x0, %al
callq 0x1bac0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8a45
jmp 0x8a3e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x4670
nopw (%rax,%rax)