// File: rofl0r[P]ascc/cs_parser.cpp
// Function: evaluate_expression(ccInternalList*, ccCompiledScript*, int, bool)
int evaluate_expression(ccInternalList*targ,ccCompiledScript*scrip,int countbrackets, bool insideBracketedDeclaration) {
  ccInternalList ours;
  int j,ourlen=0,brackdepth=0;
  int hadMetaOnly = 1;
  bool lastWasNew = false;

  for (j=targ->pos; j < targ->length; j++) {
    if (targ->script[j] == SCODE_META) {
      j+=2;
      continue;
    }

    if (sym.get_type(targ->script[j]) == SYM_OPENPARENTHESIS)
      brackdepth++;
    else if (sym.get_type(targ->script[j]) == SYM_CLOSEPARENTHESIS && (brackdepth > 0 || !insideBracketedDeclaration)) {
      brackdepth--;
      continue;
    }
    else if (sym.get_type(targ->script[j]) == SYM_NEW)
    {
      lastWasNew = true;
    }
    else if (lastWasNew)
    {
      lastWasNew = false;
    }
    else if (((!isPartOfExpression(targ, j)) && (brackdepth == 0))
          || ((brackdepth == 0) && (countbrackets!=0))
          || sym.get_type(targ->script[j]) == SYM_CLOSEPARENTHESIS) {
      ourlen = j - targ->pos;
      if ((ourlen < 1) || (hadMetaOnly == 1)) {
        cc_error("PE01: Parse error at '%s'",sym.get_friendly_name(targ->script[j]).c_str());
        return -1;
        }
      ours.script = (long*)malloc(ourlen * sizeof(long));
      memcpy(ours.script,&targ->script[targ->pos],ourlen*sizeof(long));
      int k,l;
      for (k=0;k<ourlen;k++) {
        if (ours.script[k] == SCODE_META) {
          ourlen-=3;
          for (l=k; l < ourlen; l++)
            ours.script[l] = ours.script[l+3];
          k--;
        }
      }
      ours.length = ourlen;
      ours.pos = 0;
      ours.allocated = ourlen;
      break;
    }

    // had a real token, not just metadata
    hadMetaOnly = 0;
  }

  if (j >= targ->length) {
    free(ours.script);
    ours.script=NULL;
    cc_error("end of input reached in middle of expression");
    return -1;
    }
  targ->pos = j;
  int retcode=0;
  // we now have the expression in 'ours'
  retcode=parse_sub_expr(&ours.script[0],ours.length,scrip);

  free(ours.script);
  ours.script = NULL;
  return retcode;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1e110
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x1, -0x50(%rbp)
movb $0x0, -0x51(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x8075
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
cmpq $-0x2, (%rax,%rcx,8)
jne 0x7d89
movl -0x44(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x44(%rbp)
jmp 0x8067
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,8), %esi
leaq 0x3aad1(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0x9c(%rbp)
jmp 0x7dac
movl -0x9c(%rbp), %eax
cmpl $0x5, %eax
jne 0x7dd6
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x8060
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x8125
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,8), %esi
leaq 0x3aa84(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0xa0(%rbp)
jmp 0x7df9
movl -0xa0(%rbp), %eax
cmpl $0x6, %eax
jne 0x7e1e
cmpl $0x0, -0x4c(%rbp)
jg 0x7e10
testb $0x1, -0x1d(%rbp)
jne 0x7e1e
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x8067
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,8), %esi
leaq 0x3aa3c(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0xa4(%rbp)
jmp 0x7e41
movl -0xa4(%rbp), %eax
cmpl $0x35, %eax
jne 0x7e55
movb $0x1, -0x51(%rbp)
jmp 0x805c
testb $0x1, -0x51(%rbp)
je 0x7e64
movb $0x0, -0x51(%rbp)
jmp 0x805a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0xa200
movl %eax, -0xa8(%rbp)
jmp 0x7e78
movl -0xa8(%rbp), %eax
cmpl $0x0, %eax
jne 0x7e89
cmpl $0x0, -0x4c(%rbp)
je 0x7ec7
cmpl $0x0, -0x4c(%rbp)
jne 0x7e95
cmpl $0x0, -0x1c(%rbp)
jne 0x7ec7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,8), %esi
leaq 0x3a9c5(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0xac(%rbp)
jmp 0x7eb8
movl -0xac(%rbp), %eax
cmpl $0x6, %eax
jne 0x8058
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x48(%rbp)
cmpl $0x1, -0x48(%rbp)
jl 0x7ee4
cmpl $0x1, -0x50(%rbp)
jne 0x7f66
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,8), %edx
leaq 0x3a976(%rip), %rsi     # 0x42870
leaq -0x88(%rbp), %rdi
callq 0x1f080
jmp 0x7f08
leaq -0x88(%rbp), %rdi
callq 0x41b0
movq %rax, %rsi
leaq 0x2a7a0(%rip), %rdi     # 0x326be
xorl %eax, %eax
callq 0x1bac0
jmp 0x7f27
leaq -0x88(%rbp), %rdi
callq 0x4270
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x8c(%rbp)
jmp 0x8110
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x4270
jmp 0x8125
movslq -0x48(%rbp), %rdi
shlq $0x3, %rdi
callq 0x44f0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
movslq -0x48(%rbp), %rdx
shlq $0x3, %rdx
callq 0x4300
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x8043
movq -0x38(%rbp), %rax
movslq -0x90(%rbp), %rcx
cmpq $-0x2, (%rax,%rcx,8)
jne 0x802d
movl -0x48(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x48(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x801e
movq -0x38(%rbp), %rax
movl -0x94(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x38(%rbp), %rax
movslq -0x94(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x7fdf
movl -0x90(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x802f
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x7fa9
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x8075
jmp 0x805a
jmp 0x805c
jmp 0x805e
jmp 0x8060
movl $0x0, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x7d59
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jl 0x80b4
movq -0x38(%rbp), %rdi
callq 0x4460
movq $0x0, -0x38(%rbp)
leaq 0x2a640(%rip), %rdi     # 0x326d8
xorl %eax, %eax
callq 0x1bac0
jmp 0x80a1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x8c(%rbp)
jmp 0x8110
movl -0x44(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x0, -0x98(%rbp)
movq -0x38(%rbp), %rdi
movl -0x40(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0xbc50
movl %eax, -0xb0(%rbp)
jmp 0x80e0
movl -0xb0(%rbp), %eax
movl %eax, -0x98(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4460
movq $0x0, -0x38(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x8c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1e0f0
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x1e0f0
movq -0x60(%rbp), %rdi
callq 0x4670
nopw (%rax,%rax)