// File: /workspace/github_cpp_makefile_star2_O1/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 0x27c8
leaq 0x18(%rsp), %rdi
callq 0x2b38
leaq 0x8(%rsp), %rdi
callq 0x303c
cmpl $0x1, %ebp
je 0x26f1
xorl %r12d, %r12d
cmpl $0x2, %ebp
jl 0x25a4
movl $0x0, 0xc(%rsp)
leaq 0x4b55(%rip), %r14      # 0x7046
leaq 0x4b0c(%rip), %rax      # 0x7004
movq %rax, 0x10(%rsp)
movl $0x1, %r12d
movslq %r12d, %r13
movq (%r15,%r13,8), %rbx
movq %rbx, %rdi
leaq 0x4afc(%rip), %rsi      # 0x7010
callq 0x2250
testl %eax, %eax
je 0x2550
movq %rbx, %rdi
leaq 0x4aec(%rip), %rsi      # 0x7013
callq 0x2250
testl %eax, %eax
je 0x255a
movq %rbx, %rdi
leaq 0x4adf(%rip), %rsi      # 0x7019
callq 0x2250
testl %eax, %eax
je 0x2569
cmpb $0x2d, (%rbx)
movq %rbx, %r14
jne 0x2588
jmp 0x26e8
movl $0x1, 0xc(%rsp)
jmp 0x2588
incl %r12d
movq 0x8(%r15,%r13,8), %rax
movq %rax, 0x10(%rsp)
jmp 0x2588
movq 0x8(%r15,%r13,8), %rsi
leaq 0x18(%rsp), %rdi
movq %rsi, 0x10(%rsp)
callq 0x2b42
testl %eax, %eax
jne 0x2755
incl %r12d
incl %r12d
cmpl %ebp, %r12d
jl 0x2503
cmpl $0x1, 0xc(%rsp)
sete %r12b
movq 0x10(%rsp), %rbx
jmp 0x25b2
leaq 0x4a59(%rip), %rbx      # 0x7004
leaq 0x4a94(%rip), %r14      # 0x7046
cmpb $0x0, (%r14)
je 0x2740
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2250
testl %eax, %eax
je 0x2749
leaq 0x4ae0(%rip), %rdi      # 0x70b6
callq 0x22a0
leaq 0x4afb(%rip), %rdi      # 0x70dd
callq 0x22a0
movq 0x89e2(%rip), %rax      # 0xafd0
movq (%rax), %rdi
callq 0x21f0
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x2808
testl %eax, %eax
jne 0x275f
cmpq $0x0, 0x18(%rsp)
jne 0x2628
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x3046
testl %eax, %eax
jne 0x2772
leaq 0x4a0b(%rip), %rdi      # 0x703a
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
movl $0x130, %edi            # imm = 0x130
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x34f0
testb %r12b, %r12b
je 0x265d
movl $0x1, 0x128(%rbx)
leaq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x35ce
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x35d8
leaq 0x28(%rsp), %rdi
callq 0x286a
cmpq $0x0, 0x18(%rsp)
je 0x269a
leaq 0x18(%rsp), %rdi
callq 0x2b86
jmp 0x26a4
leaq 0x8(%rsp), %rdi
callq 0x30c4
movq %rbx, %rdi
callq 0x3596
movl $0x130, %esi            # imm = 0x130
movq %rbx, %rdi
callq 0x21b0
leaq 0x8(%rsp), %rdi
callq 0x3044
leaq 0x18(%rsp), %rdi
callq 0x2b40
leaq 0x28(%rsp), %rdi
callq 0x27ec
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49b8(%rip), %rdi      # 0x70a7
jmp 0x2750
leaq 0x49be(%rip), %rdi      # 0x70b6
callq 0x22a0
leaq 0x49d9(%rip), %rdi      # 0x70dd
callq 0x22a0
leaq 0x49ef(%rip), %rdi      # 0x70ff
callq 0x22a0
leaq 0x49fc(%rip), %rdi      # 0x7118
callq 0x22a0
leaq 0x4a23(%rip), %rdi      # 0x714b
callq 0x22a0
leaq 0x4a4f(%rip), %rdi      # 0x7183
callq 0x22a0
xorl %edi, %edi
callq 0x2220
leaq 0x493a(%rip), %rdi      # 0x7081
jmp 0x2750
leaq 0x48f7(%rip), %rdi      # 0x7047
callq 0x22a0
movl $0x1, %edi
callq 0x2220
leaq 0x48b6(%rip), %rdi      # 0x701c
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
jmp 0x2755
leaq 0x28(%rsp), %rdi
callq 0x286a
jmp 0x2755
movq %rax, %r14
movl $0x130, %esi            # imm = 0x130
movq %rbx, %rdi
callq 0x21b0
jmp 0x279f
movq %rax, %r14
jmp 0x27a9
movq %rax, %r14
jmp 0x27b3
jmp 0x279c
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x3044
leaq 0x18(%rsp), %rdi
callq 0x2b40
leaq 0x28(%rsp), %rdi
callq 0x27ec
movq %r14, %rdi
callq 0x2300
nopl (%rax)