// File: /workspace/github_cpp_makefile_star2_O3/mikeakohn[P]drumsplusplus/build/../src/playdpp.cxx
// Function: main
int main(int argc, char *argv[])
{
  Tokens tokens;
  MidiFile midi_file;
  MidiPlayer midi_player;
  Song *song;
  const char *infile = "";
  const char *outfile = "/dev/midi00";
  int t;
  int interactive = 0;


  if (argc == 1)
  {
    printf(DLPLAYER_INFO);
    printf(COPYRIGHT);
    printf("Usage: playdpp <infile>\n\n");
    printf("       -midi <midi_device: default is /dev/midi00>\n");
    printf("       -o <.midi file to output to: disables /dev/midi>\n");
    printf("       -i [ will show patters as they are played ]\n\n");
    exit(0);
  }

  for (t = 1; t < argc; t++)
  {
    if (strcmp(argv[t], "-i") == 0)
    {
      interactive = 1;
    }
      else
    if (strcmp(argv[t],"-midi") == 0)
    {
      outfile = argv[++t];
    }
      else
    if (strcmp(argv[t],"-o") == 0)
    {
      outfile = argv[++t];

      if (midi_file.open(outfile) != 0)
      {
        exit(1);
      }
    }
      else
    if (argv[t][0] == '-')
    {
      printf("Unknown option\n");
      exit(1);
    }
      else
    {
      infile = argv[t];
    }
  }

  if (infile[0] == 0)
  {
    printf("\nError: No input filename specified.\n\n");
    exit(1);
  }

  if (strcmp(infile, outfile) == 0)
  {
    printf("\nError: The input / output filenames cannot be the same.\n\n");
    exit(1);
  }

  printf(DLPLAYER_INFO);
  printf(COPYRIGHT);
  fflush(stdout);

  if (tokens.open(infile) != 0)
  {
    printf("Error: Couldn't open file %s\n", infile);
    exit(1);
  }

  if (!midi_file.is_open())
  {
    if (midi_player.open(outfile) != 0)
    {
      tokens.close();
      exit(1);
    }
  }

  printf("Infile: %s\n\n", infile);

  song = new Song();

  if (interactive == 1) { song->set_interactive(); }

  song->set_midi(&midi_file, &midi_player);
  song->parse(&tokens);

#ifdef DEBUG
  song->print();
#endif

  tokens.close();

  if (midi_file.is_open())
  {
    midi_file.close();
  }
    else
  {
    midi_player.close();
  }

  delete song;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movl %edi, %ebp
leaq 0x28(%rsp), %rdi
callq 0x27cc
leaq 0x10(%rsp), %rdi
callq 0x2b38
leaq 0x8(%rsp), %rdi
callq 0x3050
cmpl $0x1, %ebp
je 0x2702
xorl %r12d, %r12d
cmpl $0x2, %ebp
jl 0x25a9
movl $0x0, 0xc(%rsp)
leaq 0x4b4f(%rip), %rax      # 0x7040
movq %rax, 0x20(%rsp)
leaq 0x4b07(%rip), %r14      # 0x7004
movl $0x1, %r13d
movslq %r13d, %r12
movq (%r15,%r12,8), %rbx
cmpb $0x2d, (%rbx)
jne 0x2561
cmpb $0x69, 0x1(%rbx)
jne 0x251b
cmpb $0x0, 0x2(%rbx)
je 0x2585
movq %rbx, %rdi
leaq 0x4aeb(%rip), %rsi      # 0x7010
callq 0x2250
testl %eax, %eax
je 0x257b
cmpb $0x6f, 0x1(%rbx)
jne 0x26ec
cmpb $0x0, 0x2(%rbx)
jne 0x26ec
movq 0x8(%r15,%r12,8), %r14
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x2b42
testl %eax, %eax
jne 0x26f8
incl %r13d
jmp 0x258d
movq %rbx, %rdi
leaq 0x4aa5(%rip), %rsi      # 0x7010
callq 0x2250
testl %eax, %eax
je 0x257b
movq %rbx, 0x20(%rsp)
jmp 0x258d
incl %r13d
movq 0x8(%r15,%r12,8), %r14
jmp 0x258d
movl $0x1, 0xc(%rsp)
incl %r13d
cmpl %ebp, %r13d
jl 0x2503
cmpl $0x1, 0xc(%rsp)
sete %r12b
movq 0x20(%rsp), %rbx
jmp 0x25b7
leaq 0x4a54(%rip), %r14      # 0x7004
leaq 0x4a89(%rip), %rbx      # 0x7040
cmpb $0x0, (%rbx)
je 0x2751
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2250
testl %eax, %eax
je 0x275a
leaq 0x4ad6(%rip), %rdi      # 0x70b0
callq 0x22a0
leaq 0x4af1(%rip), %rdi      # 0x70d7
callq 0x22a0
movq 0x89de(%rip), %rax      # 0xafd0
movq (%rax), %rdi
callq 0x21f0
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x280c
testl %eax, %eax
jne 0x2763
cmpq $0x0, 0x10(%rsp)
jne 0x262c
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x305a
testl %eax, %eax
jne 0x2776
leaq 0x4a01(%rip), %rdi      # 0x7034
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
movl $0x130, %edi            # imm = 0x130
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x34fc
testb %r12b, %r12b
je 0x2661
movl $0x1, 0x128(%rbx)
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x35da
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x35e4
leaq 0x28(%rsp), %rdi
callq 0x286e
cmpq $0x0, 0x10(%rsp)
je 0x269e
leaq 0x10(%rsp), %rdi
callq 0x2b86
jmp 0x26a8
leaq 0x8(%rsp), %rdi
callq 0x30ce
movq %rbx, %rdi
callq 0x35a2
movl $0x130, %esi            # imm = 0x130
movq %rbx, %rdi
callq 0x21b0
leaq 0x8(%rsp), %rdi
callq 0x3058
leaq 0x10(%rsp), %rdi
callq 0x2b40
leaq 0x28(%rsp), %rdi
callq 0x27f0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49ae(%rip), %rdi      # 0x70a1
callq 0x22a0
movl $0x1, %edi
callq 0x2220
leaq 0x49a7(%rip), %rdi      # 0x70b0
callq 0x22a0
leaq 0x49c2(%rip), %rdi      # 0x70d7
callq 0x22a0
leaq 0x49d8(%rip), %rdi      # 0x70f9
callq 0x22a0
leaq 0x49e5(%rip), %rdi      # 0x7112
callq 0x22a0
leaq 0x4a0c(%rip), %rdi      # 0x7145
callq 0x22a0
leaq 0x4a38(%rip), %rdi      # 0x717d
callq 0x22a0
xorl %edi, %edi
callq 0x2220
leaq 0x4923(%rip), %rdi      # 0x707b
jmp 0x26f3
leaq 0x48e0(%rip), %rdi      # 0x7041
jmp 0x26f3
leaq 0x48ac(%rip), %rdi      # 0x7016
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
jmp 0x26f8
leaq 0x28(%rsp), %rdi
callq 0x286e
jmp 0x26f8
movq %rax, %r14
movl $0x130, %esi            # imm = 0x130
movq %rbx, %rdi
callq 0x21b0
jmp 0x27a6
movq %rax, %r14
jmp 0x27b0
movq %rax, %r14
jmp 0x27ba
jmp 0x27a3
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x3058
leaq 0x10(%rsp), %rdi
callq 0x2b40
leaq 0x28(%rsp), %rdi
callq 0x27f0
movq %r14, %rdi
callq 0x2300