// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
leaq 0xeb8(%rip), %rdi       # 0x203c
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
cmpl $-0x1, %eax
je 0x14ba
leaq 0xe9f(%rip), %rbx       # 0x203f
leaq 0x20(%rsp), %r14
leaq 0x10(%rsp), %r15
leaq 0x2ebf(%rip), %rbp      # 0x4070
leaq 0xe84(%rip), %r13       # 0x203c
leaq 0xf(%rsp), %r12
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1050
cmpl $0x1, %eax
jne 0x11f6
movsd 0x10(%rsp), %xmm0
movslq 0x2e81(%rip), %rax      # 0x4060
cmpq $0x63, %rax
jg 0x124d
leal 0x1(%rax), %ecx
movl %ecx, 0x2e72(%rip)      # 0x4060
movsd %xmm0, (%rbp,%rax,8)
jmp 0x125b
movq %r14, %rdi
leaq 0xe43(%rip), %rsi       # 0x2043
movq %r12, %rdx
xorl %eax, %eax
callq 0x1050
cmpl $0x1, %eax
jne 0x125b
movzbl 0xf(%rsp), %eax
addl $-0x25, %eax
cmpl $0xa, %eax
ja 0x1276
leaq 0xded(%rip), %rcx       # 0x2010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2e2e(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x134e
decl %eax
movl %eax, 0x2e1e(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm0
jmp 0x135e
leaq 0xe00(%rip), %rdi       # 0x2054
movb $0x1, %al
callq 0x1040
movq %r13, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x1060
cmpl $-0x1, %eax
jne 0x11bd
jmp 0x14ba
leaq 0xe0f(%rip), %rdi       # 0x208c
jmp 0x1472
movl 0x2dd8(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x12ff
decl %eax
movl %eax, 0x2dcc(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm0
jmp 0x130f
movl 0x2dbe(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x1395
decl %eax
movl %eax, 0x2dae(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm0
jmp 0x13a5
movl 0x2d9d(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x13e4
decl %eax
movl %eax, 0x2d8d(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm0
jmp 0x13f4
movl 0x2d7c(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x142f
decl %eax
movl %eax, 0x2d6c(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm0
jmp 0x143f
leaq 0xd9e(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
movl 0x2d4b(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x1329
decl %eax
movl %eax, 0x2d3f(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm1
jmp 0x1345
leaq 0xd74(%rip), %rdi       # 0x20a4
movsd %xmm0, 0x18(%rsp)
callq 0x1030
movsd 0x18(%rsp), %xmm0
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
jmp 0x11d8
leaq 0xd4f(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
ucomisd 0xc9c(%rip), %xmm0      # 0x2008
jne 0x1374
jnp 0x146b
movl 0x2ce6(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x147c
decl %eax
movl %eax, 0x2cd6(%rip)      # 0x4060
cvttsd2si (%rbp,%rax,8), %eax
jmp 0x148a
leaq 0xd08(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
movl 0x2cb5(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x13bf
decl %eax
movl %eax, 0x2ca9(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm1
jmp 0x13db
leaq 0xcde(%rip), %rdi       # 0x20a4
movsd %xmm0, 0x18(%rsp)
callq 0x1030
movsd 0x18(%rsp), %xmm0
xorpd %xmm1, %xmm1
mulsd %xmm1, %xmm0
jmp 0x11d8
leaq 0xcb9(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x2c60(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x1414
decl %eax
movl %eax, 0x2c54(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm0
jmp 0x1424
leaq 0xc89(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
subsd 0x10(%rsp), %xmm0
jmp 0x11d8
leaq 0xc6e(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
ucomisd 0xbbb(%rip), %xmm0      # 0x2008
jne 0x1451
jnp 0x146b
movl 0x2c09(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x149f
decl %eax
movl %eax, 0x2bfd(%rip)      # 0x4060
movsd (%rbp,%rax,8), %xmm0
jmp 0x14af
leaq 0xc05(%rip), %rdi       # 0x2077
callq 0x1030
jmp 0x125b
leaq 0xc21(%rip), %rdi       # 0x20a4
callq 0x1030
xorl %eax, %eax
cvttsd2si 0x10(%rsp), %ecx
cltd
idivl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x11d8
leaq 0xbfe(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
divsd 0x10(%rsp), %xmm0
jmp 0x11d8
movl 0x2ba0(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x14da
decl %eax
movl %eax, 0x2b94(%rip)      # 0x4060
leaq 0x2b9d(%rip), %rcx      # 0x4070
movsd (%rcx,%rax,8), %xmm0
jmp 0x14ea
leaq 0xbc3(%rip), %rdi       # 0x20a4
callq 0x1030
xorpd %xmm0, %xmm0
leaq 0xb55(%rip), %rdi       # 0x2046
movb $0x1, %al
callq 0x1040
xorl %eax, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq