// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_4/exercise_4_04/stack.c
// Function: main
int main(void)
{
  int type;
  double op2;
  char s[MAXOP];

  while ((type = getop(s)) != EOF)
  {
    switch (type)
    {
    case NUMBER:
      push(atof(s));
      break;

    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;

    case 'h':
      view_head();
      break;

    case 'd':
      duplicate();
      break;

    case 's':
      swap();
      break;

    case 'c':
      clear();
      break;

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

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

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq 0x10(%rsp), %rbx
leaq 0x2eda(%rip), %r14      # 0x4080
leaq 0xef5(%rip), %r12       # 0x20a2
leaq 0xe5c(%rip), %r15       # 0x2010
leaq 0xed4(%rip), %r13       # 0x208f
movq %rbx, %rdi
callq 0x15aa
cmpl $0x62, %eax
jg 0x1234
leal -0x25(%rax), %ecx
cmpl $0xb, %ecx
ja 0x1271
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movl 0x2e8d(%rip), %ecx      # 0x4070
testl %ecx, %ecx
jle 0x13bb
leal -0x1(%rcx), %eax
movl %eax, 0x2e7c(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
ucomisd 0xe06(%rip), %xmm0      # 0x2008
jne 0x120a
jnp 0x13c3
cmpl $0x1, %ecx
jne 0x1525
movq %r12, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm0
xorl %eax, %eax
movl 0x2e41(%rip), %ecx      # 0x4070
jmp 0x1534
cmpl $0x67, %eax
jg 0x1255
cmpl $0x63, %eax
je 0x1384
cmpl $0x64, %eax
jne 0x13dd
callq 0x182c
jmp 0x11bb
cmpl $0x68, %eax
je 0x13b1
cmpl $0x73, %eax
jne 0x13dd
callq 0x18c8
jmp 0x11bb
cmpl $0xa, %eax
jne 0x13d4
movl 0x2df0(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1506
decl %eax
movl %eax, 0x2de0(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x1512
movl 0x2dcf(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x13f3
decl %eax
movl %eax, 0x2dbf(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm1
jmp 0x1405
movl 0x2dae(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x13bb
leal -0x1(%rax), %ecx
movl %ecx, 0x2d9d(%rip)      # 0x4070
movsd (%r14,%rcx,8), %xmm1
ucomisd 0xd27(%rip), %xmm1      # 0x2008
jne 0x12e9
jnp 0x13c3
cmpl $0x1, %eax
jne 0x155e
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movl 0x2d60(%rip), %eax      # 0x4070
jmp 0x156d
movl 0x2d55(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1449
decl %eax
movl %eax, 0x2d45(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm1
jmp 0x145b
movl 0x2d34(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x149f
decl %eax
movl %eax, 0x2d24(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm1
jmp 0x14b1
movslq 0x2d12(%rip), %rbp      # 0x4070
cmpq $0x63, %rbp
jg 0x158c
movq %rbx, %rdi
callq 0x1040
leal 0x1(%rbp), %eax
movl %eax, 0x2cf7(%rip)      # 0x4070
movsd %xmm0, (%r14,%rbp,8)
jmp 0x11bb
movslq 0x2ce5(%rip), %rdx      # 0x4070
testq %rdx, %rdx
jle 0x11bb
shlq $0x3, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1060
movl $0x0, 0x2cc4(%rip)      # 0x4070
jmp 0x11bb
callq 0x17f9
jmp 0x11bb
movq %r12, %rdi
callq 0x1030
leaq 0xcb0(%rip), %rdi       # 0x207a
callq 0x1030
jmp 0x11bb
cmpl $-0x1, %eax
je 0x1599
leaq 0xc6a(%rip), %rdi       # 0x204e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1050
jmp 0x11bb
movq %r12, %rdi
callq 0x1030
xorpd %xmm1, %xmm1
movl 0x2c6b(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1419
decl %eax
movl %eax, 0x2c5f(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x1437
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movl 0x2c39(%rip), %eax      # 0x4070
cmpl $0x63, %eax
jg 0x158c
addsd %xmm0, %xmm1
jmp 0x14f0
movq %r12, %rdi
callq 0x1030
xorpd %xmm1, %xmm1
movl 0x2c15(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x146f
decl %eax
movl %eax, 0x2c09(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x148d
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movl 0x2be3(%rip), %eax      # 0x4070
cmpl $0x63, %eax
jg 0x158c
subsd %xmm1, %xmm0
jmp 0x1576
movq %r12, %rdi
callq 0x1030
xorpd %xmm1, %xmm1
movl 0x2bbf(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x14c5
decl %eax
movl %eax, 0x2bb3(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x14e3
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movl 0x2b8d(%rip), %eax      # 0x4070
cmpl $0x63, %eax
jg 0x158c
mulsd %xmm0, %xmm1
leal 0x1(%rax), %ecx
movl %ecx, 0x2b77(%rip)      # 0x4070
cltq
movsd %xmm1, (%r14,%rax,8)
jmp 0x11bb
movq %r12, %rdi
callq 0x1030
xorpd %xmm0, %xmm0
leaq 0xb27(%rip), %rdi       # 0x2040
movb $0x1, %al
callq 0x1050
jmp 0x11bb
addl $-0x2, %ecx
movl %ecx, 0x2b42(%rip)      # 0x4070
cvttsd2si (%r14,%rcx,8), %eax
cmpl $0x63, %ecx
jg 0x158c
cvttsd2si %xmm0, %esi
cltd
idivl %esi
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
leal 0x1(%rcx), %eax
movl %eax, 0x2b20(%rip)      # 0x4070
movslq %ecx, %rax
movsd %xmm0, (%r14,%rax,8)
jmp 0x11bb
addl $-0x2, %eax
movl %eax, 0x2b09(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
cmpl $0x63, %eax
jg 0x158c
divsd %xmm1, %xmm0
leal 0x1(%rax), %ecx
movl %ecx, 0x2af1(%rip)      # 0x4070
cltq
movsd %xmm0, (%r14,%rax,8)
jmp 0x11bb
movq %r13, %rdi
callq 0x1030
jmp 0x11bb
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq