// File: /workspace/github_c_makefile_star2_O1/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 0x15bf
cmpl $0x62, %eax
jg 0x11fa
leal -0x25(%rax), %ecx
cmpl $0xb, %ecx
ja 0x1231
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movl 0x2e91(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1362
decl %eax
movl %eax, 0x2e81(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x136e
cmpl $0x67, %eax
jg 0x1218
cmpl $0x63, %eax
je 0x130c
cmpl $0x64, %eax
jne 0x134c
callq 0x1860
jmp 0x11bb
cmpl $0x68, %eax
je 0x1339
cmpl $0x73, %eax
jne 0x134c
callq 0x18fb
jmp 0x11bb
cmpl $0xa, %eax
jne 0x1343
movl 0x2e30(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1500
decl %eax
movl %eax, 0x2e20(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x150c
movl 0x2e0f(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x139f
decl %eax
movl %eax, 0x2dff(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm1
jmp 0x13ab
movl 0x2dee(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x13f7
decl %eax
movl %eax, 0x2dde(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm1
jmp 0x1403
movl 0x2dcd(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1441
decl %eax
movl %eax, 0x2dbd(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm1
jmp 0x144d
movl 0x2dac(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1499
decl %eax
movl %eax, 0x2d9c(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm1
jmp 0x14a5
movslq 0x2d8a(%rip), %rbp      # 0x4070
cmpq $0x63, %rbp
jg 0x15a1
movq %rbx, %rdi
callq 0x1040
leal 0x1(%rbp), %eax
movl %eax, 0x2d6f(%rip)      # 0x4070
movsd %xmm0, (%r14,%rbp,8)
jmp 0x11bb
movslq 0x2d5d(%rip), %rdx      # 0x4070
testq %rdx, %rdx
jle 0x11bb
shlq $0x3, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1060
movl $0x0, 0x2d3c(%rip)      # 0x4070
jmp 0x11bb
callq 0x182d
jmp 0x11bb
cmpl $-0x1, %eax
je 0x15ae
leaq 0xcfb(%rip), %rdi       # 0x204e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1050
jmp 0x11bb
movq %r12, %rdi
callq 0x1030
xorpd %xmm0, %xmm0
ucomisd 0xc92(%rip), %xmm0      # 0x2008
jne 0x137e
jnp 0x1430
movl 0x2cec(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x151f
decl %eax
movl %eax, 0x2cdc(%rip)      # 0x4070
cvttsd2si (%r14,%rax,8), %eax
jmp 0x1535
movq %r12, %rdi
callq 0x1030
xorpd %xmm1, %xmm1
movl 0x2cbf(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x13c5
decl %eax
movl %eax, 0x2cb3(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x13dd
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movslq 0x2c8c(%rip), %rax      # 0x4070
cmpq $0x63, %rax
jg 0x15a1
addsd %xmm0, %xmm1
jmp 0x14ec
movq %r12, %rdi
callq 0x1030
xorpd %xmm1, %xmm1
ucomisd 0xbfd(%rip), %xmm1      # 0x2008
jne 0x140f
jnp 0x1430
movl 0x2c5b(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1564
decl %eax
movl %eax, 0x2c4b(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x157c
leaq 0xc43(%rip), %rdi       # 0x207a
callq 0x1030
jmp 0x11bb
movq %r12, %rdi
callq 0x1030
xorpd %xmm1, %xmm1
movl 0x2c1d(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x1467
decl %eax
movl %eax, 0x2c11(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x147f
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movslq 0x2bea(%rip), %rax      # 0x4070
cmpq $0x63, %rax
jg 0x15a1
subsd %xmm1, %xmm0
jmp 0x158d
movq %r12, %rdi
callq 0x1030
xorpd %xmm1, %xmm1
movl 0x2bc5(%rip), %eax      # 0x4070
testl %eax, %eax
jle 0x14bf
decl %eax
movl %eax, 0x2bb9(%rip)      # 0x4070
movsd (%r14,%rax,8), %xmm0
jmp 0x14d7
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movslq 0x2b92(%rip), %rax      # 0x4070
cmpq $0x63, %rax
jg 0x15a1
mulsd %xmm0, %xmm1
leal 0x1(%rax), %ecx
movl %ecx, 0x2b7b(%rip)      # 0x4070
movsd %xmm1, (%r14,%rax,8)
jmp 0x11bb
movq %r12, %rdi
callq 0x1030
xorpd %xmm0, %xmm0
leaq 0xb2d(%rip), %rdi       # 0x2040
movb $0x1, %al
callq 0x1050
jmp 0x11bb
movq %r12, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm0
xorl %eax, %eax
movslq 0x2b34(%rip), %rcx      # 0x4070
cmpq $0x63, %rcx
jg 0x15a1
cvttsd2si %xmm0, %esi
cltd
idivl %esi
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
leal 0x1(%rcx), %eax
movl %eax, 0x2b17(%rip)      # 0x4070
movsd %xmm0, (%r14,%rcx,8)
jmp 0x11bb
movq %r12, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0x1030
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
movslq 0x2aed(%rip), %rax      # 0x4070
cmpq $0x63, %rax
jg 0x15a1
divsd %xmm1, %xmm0
leal 0x1(%rax), %ecx
movl %ecx, 0x2ada(%rip)      # 0x4070
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