// File: rofl0r[P]ascc/cs_parser.cpp
// Function: find_lowest_bonding_operator(long*, int)
int find_lowest_bonding_operator(long*slist,int listlen) {
  int k,blevel=0,plevel=0;
  int lowestis = 0,lowestat = -1;
  for (k=0;k<listlen;k++) {
    int thisType = sym.get_type(slist[k]);
    if (thisType == SYM_OPENBRACKET)
      blevel++;
    else if (thisType == SYM_CLOSEBRACKET)
      blevel--;
    else if (thisType == SYM_OPENPARENTHESIS)
      plevel++;
    else if (thisType == SYM_CLOSEPARENTHESIS)
      plevel--;

    if (((thisType == SYM_OPERATOR) || (thisType == SYM_NEW)) &&
        (plevel == 0) && (blevel == 0)) {
      // .ssize stores the precedence
      int thisIsTheOperator = 0;
      if (ccGetOption(SCOPT_LEFTTORIGHT)) {
        // left-to-right; find the right-most operator, then
        // they will be recursively processed left
        if (sym.entries[slist[k]].ssize >= lowestis)
          thisIsTheOperator = 1;
      }
      else {
        // right-to-left; find the left-most operator, then
        // they will be recursively processed right
        if (sym.entries[slist[k]].ssize > lowestis)
          thisIsTheOperator = 1;
      }
      if (thisIsTheOperator) {
        lowestis = sym.entries[slist[k]].ssize;
        lowestat = k;
      }
    }
  }
  return lowestat;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xa462
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0x3853d(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0x24(%rbp)
cmpl $0x7, -0x24(%rbp)
jne 0xa34c
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xa383
cmpl $0x8, -0x24(%rbp)
jne 0xa35d
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xa381
cmpl $0x5, -0x24(%rbp)
jne 0xa36e
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xa37f
cmpl $0x6, -0x24(%rbp)
jne 0xa37d
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xa37f
jmp 0xa381
jmp 0xa383
cmpl $0x3, -0x24(%rbp)
je 0xa393
cmpl $0x35, -0x24(%rbp)
jne 0xa452
cmpl $0x0, -0x18(%rbp)
jne 0xa452
cmpl $0x0, -0x14(%rbp)
jne 0xa452
movl $0x0, -0x28(%rbp)
movl $0x40, %edi
callq 0x265a0
cmpl $0x0, %eax
je 0xa3ef
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x384a0(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jl 0xa3ed
movl $0x1, -0x28(%rbp)
jmp 0xa421
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x3846e(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jle 0xa41f
movl $0x1, -0x28(%rbp)
jmp 0xa421
cmpl $0x0, -0x28(%rbp)
je 0xa450
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x38436(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x38(%rax), %rax
movl %eax, -0x1c(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0xa452
jmp 0xa454
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xa312
movl -0x20(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)