// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_4/exercise_4_10/calculator.c
// Function: getop
int getop(char s[])
{
  int i = 0, c;

  while ((s[0] = c = line[line_i++]) == ' ' || c == '\t')
    ;

  s[1] = '\0';

  if (isalpha(c))
  {
    var = c;
    return VARGET;
  }

  if (!isdigit(c) && c != '.' && c != '-')
  {
    return c;
  }

  if (c == '-')
  {
    int next = line[line_i++];
    if (next == '\n' || next == ' ' || next == '\t' || next == '\0')
    {
      --line_i;
      return '-';
    }
    else if (!isdigit(next) && next != '.') // not a number
    {
      return next;
    }
    else
    {
      s[++i] = c = next;
    }
  }
  else
  {
    c = line[line_i++];
  }

  if (isdigit(c))
  {
    while (isdigit(s[++i] = c = line[line_i++]))
      ;
  }

  if (c == '.')
  {
    while (isdigit(s[++i] = c = line[line_i++]))
      ;
  }

  --line_i;

  return NUMBER;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl 0x2b67(%rip), %eax      # 0x4080
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2b5c(%rip)      # 0x4080
movslq %eax, %rcx
leaq 0x2b62(%rip), %rax      # 0x4090
movsbl (%rax,%rcx), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movb %al, (%rcx)
movsbl %al, %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x1d(%rbp)
je 0x1552
cmpl $0x9, -0x18(%rbp)
sete %al
movb %al, -0x1d(%rbp)
movb -0x1d(%rbp), %al
testb $0x1, %al
jne 0x155b
jmp 0x155d
jmp 0x1513
movq -0x10(%rbp), %rax
movb $0x0, 0x1(%rax)
callq 0x1090
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x1594
movl -0x18(%rbp), %eax
movb %al, 0x2ad8(%rip)       # 0x4060
movl $0x61, -0x4(%rbp)
jmp 0x1774
callq 0x1090
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x15c5
cmpl $0x2e, -0x18(%rbp)
je 0x15c5
cmpl $0x2d, -0x18(%rbp)
je 0x15c5
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1774
cmpl $0x2d, -0x18(%rbp)
jne 0x166e
movl 0x2aab(%rip), %eax      # 0x4080
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2aa0(%rip)      # 0x4080
movslq %eax, %rcx
leaq 0x2aa6(%rip), %rax      # 0x4090
movsbl (%rax,%rcx), %eax
movl %eax, -0x1c(%rbp)
cmpl $0xa, -0x1c(%rbp)
je 0x1609
cmpl $0x20, -0x1c(%rbp)
je 0x1609
cmpl $0x9, -0x1c(%rbp)
je 0x1609
cmpl $0x0, -0x1c(%rbp)
jne 0x1624
movl 0x2a71(%rip), %eax      # 0x4080
addl $-0x1, %eax
movl %eax, 0x2a68(%rip)      # 0x4080
movl $0x2d, -0x4(%rbp)
jmp 0x1774
callq 0x1090
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x164f
cmpl $0x2e, -0x1c(%rbp)
je 0x164f
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1774
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x166c
jmp 0x1690
movl 0x2a0c(%rip), %eax      # 0x4080
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2a01(%rip)      # 0x4080
movslq %eax, %rcx
leaq 0x2a07(%rip), %rax      # 0x4090
movsbl (%rax,%rcx), %eax
movl %eax, -0x18(%rbp)
callq 0x1090
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x1701
jmp 0x16ac
callq 0x1090
movq (%rax), %rax
movl 0x29c6(%rip), %ecx      # 0x4080
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x29bb(%rip)      # 0x4080
movslq %ecx, %rdx
leaq 0x29c1(%rip), %rcx      # 0x4090
movsbl (%rcx,%rdx), %ecx
movl %ecx, -0x18(%rbp)
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %esi, %rsi
movb %cl, (%rdx,%rsi)
movsbl %cl, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x16ff
jmp 0x16ac
jmp 0x1701
cmpl $0x2e, -0x18(%rbp)
jne 0x175e
jmp 0x1709
callq 0x1090
movq (%rax), %rax
movl 0x2969(%rip), %ecx      # 0x4080
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x295e(%rip)      # 0x4080
movslq %ecx, %rdx
leaq 0x2964(%rip), %rcx      # 0x4090
movsbl (%rcx,%rdx), %ecx
movl %ecx, -0x18(%rbp)
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %esi, %rsi
movb %cl, (%rdx,%rsi)
movsbl %cl, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x175c
jmp 0x1709
jmp 0x175e
movl 0x291c(%rip), %eax      # 0x4080
addl $-0x1, %eax
movl %eax, 0x2913(%rip)      # 0x4080
movl $0x30, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)