// File: /workspace/github_cpp_makefile_star2_O2/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, 0xc(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x27a8
leaq 0x10(%rsp), %rdi
callq 0x2af4
leaq 0x4(%rsp), %rdi
callq 0x2fc4
cmpl $0x1, 0xc(%rsp)
je 0x26dc
movl $0x0, 0x8(%rsp)
pushq $0x1
popq %r13
leaq 0x4b17(%rip), %r14      # 0x7004
leaq 0x4b4c(%rip), %rax      # 0x7040
movq %rax, 0x20(%rsp)
cmpl 0xc(%rsp), %r13d
jge 0x258c
movslq %r13d, %r12
movq (%r15,%r12,8), %rbx
movb (%rbx), %bpl
cmpb $0x2d, %bpl
jne 0x2520
cmpb $0x69, 0x1(%rbx)
jne 0x2520
cmpb $0x0, 0x2(%rbx)
je 0x257d
movq %rbx, %rdi
leaq 0x4ae6(%rip), %rsi      # 0x7010
callq 0x2290
testl %eax, %eax
je 0x256c
cmpb $0x2d, %bpl
jne 0x2576
cmpb $0x6f, 0x1(%rbx)
jne 0x26c8
cmpb $0x0, 0x2(%rbx)
jne 0x26c8
movq 0x8(%r15,%r12,8), %r14
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x2afe
testl %eax, %eax
jne 0x26d4
incl %r13d
jmp 0x2584
incl %r13d
movq 0x8(%r15,%r12,8), %r14
jmp 0x2584
movq %rbx, 0x20(%rsp)
jmp 0x2584
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
incl %r13d
jmp 0x24f9
movq 0x20(%rsp), %rbx
cmpb $0x0, (%rbx)
je 0x272b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2290
testl %eax, %eax
je 0x2734
leaq 0x4afc(%rip), %rdi      # 0x70b0
callq 0x22e0
leaq 0x4b17(%rip), %rdi      # 0x70d7
callq 0x22e0
movq 0x8a04(%rip), %rax      # 0xafd0
movq (%rax), %rdi
callq 0x2210
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x27d6
testl %eax, %eax
jne 0x273d
cmpq $0x0, 0x10(%rsp)
jne 0x2606
leaq 0x4(%rsp), %rdi
movq %r14, %rsi
callq 0x2fca
testl %eax, %eax
jne 0x2750
leaq 0x4a27(%rip), %rdi      # 0x7034
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
movl $0x130, %edi            # imm = 0x130
callq 0x21b0
movq %rax, %rbx
movq %rax, %rdi
callq 0x34b0
cmpl $0x1, 0x8(%rsp)
jne 0x263d
movl $0x1, 0x128(%rbx)
leaq 0x10(%rsp), %rsi
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x3598
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x35a2
leaq 0x28(%rsp), %rdi
callq 0x2816
cmpq $0x0, 0x10(%rsp)
je 0x267a
leaq 0x10(%rsp), %rdi
callq 0x2b40
jmp 0x2684
leaq 0x4(%rsp), %rdi
callq 0x303e
movq %rbx, %rdi
callq 0x3560
movl $0x130, %esi            # imm = 0x130
movq %rbx, %rdi
callq 0x21c0
leaq 0x4(%rsp), %rdi
callq 0x2fc8
leaq 0x10(%rsp), %rdi
callq 0x2afc
leaq 0x28(%rsp), %rdi
callq 0x27cc
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49d2(%rip), %rdi      # 0x70a1
callq 0x22e0
pushq $0x1
popq %rdi
callq 0x2240
leaq 0x49cd(%rip), %rdi      # 0x70b0
callq 0x22e0
leaq 0x49e8(%rip), %rdi      # 0x70d7
callq 0x22e0
leaq 0x49fe(%rip), %rdi      # 0x70f9
callq 0x22e0
leaq 0x4a0b(%rip), %rdi      # 0x7112
callq 0x22e0
leaq 0x4a32(%rip), %rdi      # 0x7145
callq 0x22e0
leaq 0x4a5e(%rip), %rdi      # 0x717d
callq 0x22e0
xorl %edi, %edi
callq 0x2240
leaq 0x4949(%rip), %rdi      # 0x707b
jmp 0x26cf
leaq 0x4906(%rip), %rdi      # 0x7041
jmp 0x26cf
leaq 0x48d2(%rip), %rdi      # 0x7016
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
jmp 0x26d4
leaq 0x28(%rsp), %rdi
callq 0x2816
jmp 0x26d4
movq %rax, %r14
movl $0x130, %esi            # imm = 0x130
movq %rbx, %rdi
callq 0x21c0
jmp 0x2780
movq %rax, %r14
jmp 0x278a
movq %rax, %r14
jmp 0x2794
jmp 0x277d
movq %rax, %r14
leaq 0x4(%rsp), %rdi
callq 0x2fc8
leaq 0x10(%rsp), %rdi
callq 0x2afc
leaq 0x28(%rsp), %rdi
callq 0x27cc
movq %r14, %rdi
callq 0x2330
nop