// File: /workspace/github_cpp_makefile_star2_O3/rowdyroad[P]dtmfdecoder/example.cpp
// Function: main
int main (int argc, char *argv[])
{
  if (argc < 2) {
    std::cout << "Usage: " << argv[0] << " something.wav" << std::endl;
    return 1;
  }

  WAVHeader header;

  FILE * fp = loadWaveFile(argv[1], header);

  size_t timestamp = 0;
  size_t read_length = 0;

  std::vector<int16_t> frames(400);

  TextHandler handler;
  DTMFDecoder<> decoder(&handler);
  std::cout << "Detecting begin..." << std::endl;
  while (read_length < header.subchunk2Size) {
    int chunk_length = fread(frames.data(), sizeof(int16_t), frames.size(), fp);

    if (chunk_length <= 0) {
      break;
    }
    read_length += chunk_length * sizeof(int16_t);
    decoder.decode(frames, chunk_length);
  }

  fclose(fp);
  std::cout << "Detecting complete!" << std::endl;
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %r14
cmpl $0x1, %edi
jg 0x24de
movq 0x3b39(%rip), %rbx      # 0x5fd8
leaq 0x1bf2(%rip), %rsi      # 0x4098
movl $0x7, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%r14), %r14
testq %r14, %r14
je 0x2748
movq %r14, %rdi
callq 0x2090
movq 0x3b0a(%rip), %rdi      # 0x5fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x21b0
jmp 0x275f
movl $0x46464952, 0x28(%rsp) # imm = 0x46464952
movabsq $0x20746d6645564157, %rax # imm = 0x20746D6645564157
movq %rax, 0x38(%rsp)
movq $0x10, 0x40(%rsp)
movw $0x1, 0x48(%rsp)
movl $0x61746164, 0x64(%rsp) # imm = 0x61746164
movq $0x0, 0x68(%rsp)
movq 0x8(%r14), %rsi
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2810
leaq 0x70(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x241c
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x255c
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2190
movl $0x320, %edi            # imm = 0x320
callq 0x2180
movq %rax, %r14
movq %rax, 0x8(%rsp)
movq %rax, %r15
addq $0x320, %r15            # imm = 0x320
movq %r15, 0x18(%rsp)
movl $0x320, %edx            # imm = 0x320
movq %rax, %rdi
xorl %esi, %esi
callq 0x20d0
movq %r15, 0x10(%rsp)
leaq 0x37e0(%rip), %rax      # 0x5d78
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x70(%rsp), %rdi
movsd 0x1a5b(%rip), %xmm0     # 0x4008
movl $0x1f40, %edx           # imm = 0x1F40
movl $0x32, %ecx
movl $0xa, %r8d
callq 0x284e
movq 0x3a0f(%rip), %r14      # 0x5fd8
leaq 0x1adf(%rip), %rsi      # 0x40af
movl $0x12, %edx
movq %r14, %rdi
callq 0x21b0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x39dd(%rip), %rdi      # 0x5fd8
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq 0x68(%rsp), %r13
testq %r13, %r13
je 0x2662
xorl %ebp, %ebp
leaq 0x70(%rsp), %r14
leaq 0x8(%rsp), %r15
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
subq %rdi, %rdx
sarq %rdx
movl $0x2, %esi
movq %rbx, %rcx
callq 0x21f0
movq %rax, %r12
testl %r12d, %r12d
jle 0x2662
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2a38
leaq (%rbp,%r12,2), %rbp
cmpq %r13, %rbp
jb 0x261e
movq %rbx, %rdi
callq 0x2170
movq 0x3967(%rip), %rbx      # 0x5fd8
leaq 0x1a4a(%rip), %rsi      # 0x40c2
movl $0x13, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x3935(%rip), %rdi      # 0x5fd8
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x128(%rsp), %rbx
movq %rbx, %rdi
callq 0x2ec6
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x26d9
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0x26f6
movq 0x108(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x2713
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x272d
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2744
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %eax, %eax
jmp 0x279f
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2230
leaq 0x193a(%rip), %rsi      # 0x40a0
movl $0xe, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movl $0x1, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x27f7
jmp 0x27d9
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2807
movq 0x80(%rsp), %rsi
incq %rsi
jmp 0x2802
movq %rax, %rbx
jmp 0x2807
jmp 0x27e0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2cc6
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x2807
movq 0x18(%rsp), %rsi
subq %r14, %rsi
movq %r14, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2240
nop