// File: /workspace/github_c_makefile_star2_O3/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 0x39b7
movzbl (%rdx), %eax
cmpl $0x24, %eax
jg 0x38ba
cmpl $0x23, %eax
je 0x38d1
cmpl $0x24, %eax
jne 0x38e9
incq %rdx
decq %rcx
movl $0x10, %esi
jmp 0x38e9
cmpl $0x2f, %eax
je 0x38de
cmpl $0x25, %eax
jne 0x38e9
incq %rdx
decq %rcx
movl $0x2, %esi
jmp 0x38e9
incq %rdx
decq %rcx
movl $0xa, %esi
jmp 0x38e9
incq %rdx
decq %rcx
movl $0x8, %esi
testq %rcx, %rcx
sete %al
leaq -0x2(%rsi), %rdi
cmpq $0x23, %rdi
setae %dil
orb %al, %dil
jne 0x39b7
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movb (%rdx), %al
xorl %r9d, %r9d
cmpb $0x2d, %al
sete %r9b
cmpq %r9, %rcx
je 0x39bd
negq %r9
xorl %edi, %edi
cmpb $0x2d, %al
sete %dil
addq %rdi, %rdx
leaq -0xa(%rsi), %rdi
addq %r9, %rcx
negq %rcx
xorl %r10d, %r10d
xorl %r9d, %r9d
movzbl (%rdx,%r10), %r11d
leal -0x30(%r11), %ebx
cmpb $0x9, %bl
ja 0x3957
andl $0xf, %r11d
cmpq %r11, %rsi
ja 0x3997
jmp 0x39c3
leal -0x61(%r11), %ebx
cmpb $0x19, %bl
ja 0x396f
leal -0x61(%r11), %ebx
cmpq %rbx, %rdi
jbe 0x39c3
addl $-0x57, %r11d
jmp 0x3997
movl %r11d, %ebp
addb $-0x41, %bpl
xorl %r14d, %r14d
movl $0x0, %ebx
cmpb $0x19, %bpl
ja 0x39c8
leal -0x41(%r11), %r12d
movl $0x0, %r15d
cmpq %r12, %rdi
jbe 0x39cb
addl $-0x37, %r11d
imulq %rsi, %r9
addq %r11, %r9
incq %r10
movq %rcx, %r11
addq %r10, %r11
jne 0x393e
movq $-0x1, %r15
movb $0x1, %bl
movq %r9, %r14
jmp 0x39cb
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x39ef
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x39e7
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpb $0x2d, %al
sete %al
movq %r14, %rcx
negq %rcx
testb %bl, %al
cmoveq %r14, %rcx
movq $-0x1, %rax
cmoveq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
movq %rcx, (%r8)
retq