// File: 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
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x252b
movq 0xbaf2(%rip), %rdi      # 0xdfd8
leaq 0x6bab(%rip), %rsi      # 0x9098
callq 0x2160
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x2160
movq %rax, %rdi
leaq 0x6b95(%rip), %rsi      # 0x90a0
callq 0x2160
movq %rax, %rdi
movq 0xbaae(%rip), %rsi      # 0xdfc8
callq 0x21b0
movl $0x1, -0x4(%rbp)
jmp 0x2820
leaq -0x58(%rbp), %rdi
callq 0x2840
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x22b0
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rdx
leaq -0x80(%rbp), %rdi
callq 0x28b0
jmp 0x256f
leaq -0x80(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2440
movq %rax, -0x1d8(%rbp)
jmp 0x2585
leaq -0x80(%rbp), %rdi
callq 0x20e0
leaq -0x81(%rbp), %rdi
callq 0x21d0
movq -0x1d8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x2960
movq -0x1e0(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
movl $0x190, %esi            # imm = 0x190
callq 0x2980
jmp 0x25e8
leaq -0xc1(%rbp), %rdi
callq 0x29f0
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x2a10
movq -0x1e8(%rbp), %rsi
leaq -0x1b8(%rbp), %rdi
movl $0x1f40, %edx           # imm = 0x1F40
movl $0x32, %ecx
movl $0xa, %r8d
movsd 0x69db(%rip), %xmm0     # 0x9008
callq 0x2a50
jmp 0x2634
movq 0xb99d(%rip), %rdi      # 0xdfd8
leaq 0x6a6d(%rip), %rsi      # 0x90af
callq 0x2160
movq %rax, -0x1f0(%rbp)
jmp 0x2650
movq -0x1f0(%rbp), %rdi
movq 0xb96a(%rip), %rsi      # 0xdfc8
callq 0x21b0
jmp 0x2665
jmp 0x2667
movq -0xa8(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x27b5
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x2d40
movq -0x208(%rbp), %rdi
movq %rax, -0x200(%rbp)
callq 0x2d60
movq -0x200(%rbp), %rdi
movq %rax, %rdx
movq -0x60(%rbp), %rcx
movl $0x2, %esi
callq 0x2240
movq %rax, -0x1f8(%rbp)
jmp 0x26bf
movq -0x1f8(%rbp), %rax
movl %eax, -0x1bc(%rbp)
cmpl $0x0, -0x1bc(%rbp)
jg 0x277b
jmp 0x27b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x270d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x20e0
leaq -0x81(%rbp), %rdi
callq 0x21d0
jmp 0x282c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x29f0
jmp 0x282c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2812
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x3370
jmp 0x2812
movslq -0x1bc(%rbp), %rcx
movq -0xa8(%rbp), %rax
leaq (%rax,%rcx,2), %rax
movq %rax, -0xa8(%rbp)
movslq -0x1bc(%rbp), %rdx
leaq -0x1b8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2d80
jmp 0x27b0
jmp 0x2667
movq -0x60(%rbp), %rdi
callq 0x2170
jmp 0x27c0
movq 0xb811(%rip), %rdi      # 0xdfd8
leaq 0x68f4(%rip), %rsi      # 0x90c2
callq 0x2160
movq %rax, -0x210(%rbp)
jmp 0x27dc
movq -0x210(%rbp), %rdi
movq 0xb7de(%rip), %rsi      # 0xdfc8
callq 0x21b0
jmp 0x27f1
movl $0x0, -0x4(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x3370
leaq -0xc0(%rbp), %rdi
callq 0x33d0
jmp 0x2820
leaq -0xc0(%rbp), %rdi
callq 0x33d0
jmp 0x282c
movl -0x4(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x22a0
nopl (%rax,%rax)