// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_7/exercise_7_05/calculator.c
// Function: main
int main(int argc, char *argv[])
{
  char c;
  double op2;
  char str[MAX_STR_LEN];

  while (scanf("%s", str) != EOF)
  {
    if (sscanf(str, "%lf", &op2) == 1)
    {
      push(op2);
    }
    else if (sscanf(str, "%c", &c) == 1)
    {
      switch (c)
      {
      case '+':
        push(pop() + pop());
        break;

      case '-':
        op2 = pop();
        push(pop() - op2);
        break;

      case '*':
        push(pop() * pop());
        break;

      case '/':
        op2 = pop();

        if (op2 != 0.0)
        {
          push(pop() / op2);
        }
        else
        {
          printf("Error: zero divisor.\n");
        }
        break;

      case '%':
        op2 = pop();

        if (op2 != 0.0)
        {
          push((int)pop() % (int)op2);
        }
        else
        {
          printf("Error: zero divisor.\n");
        }
        break;

      default:
        printf("Error: unknown command.\n");
        break;
      }
    }
  }

  printf("result: %.8g\n", pop());

  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x410(%rbp), %rsi
leaq 0xea9(%rip), %rdi       # 0x2030
movb $0x0, %al
callq 0x1050
cmpl $-0x1, %eax
je 0x1326
leaq -0x410(%rbp), %rdi
leaq 0xe8e(%rip), %rsi       # 0x2033
leaq -0x20(%rbp), %rdx
movb $0x0, %al
callq 0x1040
cmpl $0x1, %eax
jne 0x11c4
movsd -0x20(%rbp), %xmm0
callq 0x1350
jmp 0x1321
leaq -0x410(%rbp), %rdi
leaq 0xe65(%rip), %rsi       # 0x2037
leaq -0x11(%rbp), %rdx
movb $0x0, %al
callq 0x1040
cmpl $0x1, %eax
jne 0x131f
movsbl -0x11(%rbp), %eax
addl $-0x25, %eax
movl %eax, %ecx
movq %rcx, -0x418(%rbp)
subl $0xa, %eax
ja 0x130f
movq -0x418(%rbp), %rax
leaq 0xdf7(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x13b0
movsd %xmm0, -0x420(%rbp)
callq 0x13b0
movaps %xmm0, %xmm1
movsd -0x420(%rbp), %xmm0
addsd %xmm1, %xmm0
callq 0x1350
jmp 0x131d
callq 0x13b0
movsd %xmm0, -0x20(%rbp)
callq 0x13b0
subsd -0x20(%rbp), %xmm0
callq 0x1350
jmp 0x131d
callq 0x13b0
movsd %xmm0, -0x428(%rbp)
callq 0x13b0
movaps %xmm0, %xmm1
movsd -0x428(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x1350
jmp 0x131d
callq 0x13b0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x12a6
jp 0x12a6
jmp 0x12b7
callq 0x13b0
divsd -0x20(%rbp), %xmm0
callq 0x1350
jmp 0x12c5
leaq 0xd7c(%rip), %rdi       # 0x203a
movb $0x0, %al
callq 0x1030
jmp 0x131d
callq 0x13b0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x12e3
jp 0x12e3
jmp 0x12ff
callq 0x13b0
cvttsd2si %xmm0, %eax
cvttsd2si -0x20(%rbp), %ecx
cltd
idivl %ecx
cvtsi2sd %edx, %xmm0
callq 0x1350
jmp 0x130d
leaq 0xd34(%rip), %rdi       # 0x203a
movb $0x0, %al
callq 0x1030
jmp 0x131d
leaq 0xd3a(%rip), %rdi       # 0x2050
movb $0x0, %al
callq 0x1030
jmp 0x131f
jmp 0x1321
jmp 0x1179
callq 0x13b0
leaq 0xd37(%rip), %rdi       # 0x2069
movb $0x1, %al
callq 0x1030
xorl %eax, %eax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
nopw %cs:(%rax,%rax)