// File: /workspace/github_c_makefile_star2_O2/tabemann[P]attoforth/src/runtime/inner.c
// Function: af_parse_number
af_bool_t af_parse_number(af_global_t* global, af_cell_t base,  af_byte_t* text,
			  size_t length, af_sign_cell_t* result) {
  af_sign_cell_t value = 0;
  af_bool_t success = TRUE;
  af_bool_t negative = FALSE;
  if(length > 0) {
    if(*text == '%') {
      base = 2;
      text++;
      length--;
    } else if(*text == '/') {
      base = 8;
      text++;
      length--;
    } else if(*text == '#') {
      base = 10;
      text++;
      length--;
    } else if(*text == '$') {
      base = 16;
      text++;
      length--;
    }
    if(length > 0 && base >= 2 && base <= 36) {
      if(*text == '-') {
	negative = TRUE;
	text++;
	length--;
      }
      if(length > 0) {
	while(length--) {
	  value *= base;
	  if(*text >= '0' && *text <= '9') {
	    if(*text - '0' < base) {
	      value += *text++ - '0';
	    } else {
	      value = 0;
	      success = FALSE;
	      break;
	    }
	  } else if(*text >= 'a' && *text <= 'z') {
	    if(*text - 'a' < base - 10) {
	      value += (*text++ - 'a') + 10;
	    } else {
	      value = 0;
	      success = FALSE;
	      break;
	    }
	  } else if(*text >= 'A' && *text <= 'Z') {
	    if(*text - 'A' < base - 10) {
	      value += (*text++ - 'A') + 10;
	    } else {
	      value = 0;
	      success = FALSE;
	      break;
	    }
	  } else {
	    value = 0;
	    success = FALSE;
	    break;
	  }
	}
	if(success && negative) {
	  value = -value;
	}
      } else {
	value = 0;
	success = FALSE;
      }
    } else {
      value = 0;
      success = FALSE;
    }
  } else {
    value = 0;
    success = FALSE;
  }
  *result = value;
  return success;
}

// Assembly:
testq %rcx, %rcx
je 0x3848
movzbl (%rdx), %eax
cmpl $0x23, %eax
je 0x3770
cmpl $0x24, %eax
je 0x374c
cmpl $0x2f, %eax
je 0x375e
cmpl $0x25, %eax
jne 0x3780
incq %rdx
decq %rcx
movabsq $0x2, %rsi
jmp 0x3780
incq %rdx
decq %rcx
movabsq $0x10, %rsi
jmp 0x3780
incq %rdx
decq %rcx
movabsq $0x8, %rsi
jmp 0x3780
incq %rdx
decq %rcx
movabsq $0xa, %rsi
testq %rcx, %rcx
sete %al
leaq -0x2(%rsi), %rdi
cmpq $0x23, %rdi
setae %dil
orb %al, %dil
jne 0x3848
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movb (%rdx), %dil
xorl %eax, %eax
cmpb $0x2d, %dil
sete %al
cmpq %rax, %rcx
je 0x384e
negq %rax
xorl %r9d, %r9d
cmpb $0x2d, %dil
sete %r9b
addq %r9, %rdx
leaq -0xa(%rsi), %r11
addq %rax, %rcx
negq %rcx
xorl %r10d, %r10d
movabsq $-0x1, %r9
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %rcx, %r15
addq %r14, %r15
je 0x3854
movzbl (%rdx,%r14), %r12d
leal -0x30(%r12), %eax
cmpb $0x9, %al
ja 0x3807
andl $0xf, %r12d
cmpq %r12, %rsi
ja 0x383c
jmp 0x385c
leal -0x61(%r12), %eax
cmpb $0x19, %al
ja 0x3820
leal -0x61(%r12), %eax
cmpq %rax, %r11
jbe 0x385c
addl $-0x57, %r12d
jmp 0x383c
movl %r12d, %eax
addb $-0x41, %al
cmpb $0x19, %al
ja 0x385c
leal -0x41(%r12), %r13d
movl $0x0, %eax
cmpq %r13, %r11
jbe 0x385e
addl $-0x37, %r12d
imulq %rsi, %rbx
addq %r12, %rbx
incq %r14
jmp 0x37e6
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x3886
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x387d
movq %rbx, %r10
movq %r9, %rax
jmp 0x385e
xorl %eax, %eax
testq %r15, %r15
sete %dl
cmpb $0x2d, %dil
sete %sil
movq %r10, %rcx
negq %rcx
testb %dl, %sil
cmoveq %r10, %rcx
cmovneq %r9, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
movq %rcx, (%r8)
retq