// File: /workspace/github_cpp_makefile_star2_O3/tobias93[P]piano/rtaudio/tests/playraw.cpp
// Function: main
int main( int argc, char *argv[] )
{
  unsigned int channels, fs, bufferFrames, device = 0, offset = 0;
  char *file;

  // minimal command-line checking
  if ( argc < 4 || argc > 6 ) usage();

  RtAudio dac;
  if ( dac.getDeviceCount() < 1 ) {
    std::cout << "\nNo audio devices found!\n";
    exit( 0 );
  }

  channels = (unsigned int) atoi( argv[1]) ;
  fs = (unsigned int) atoi( argv[2] );
  file = argv[3];
  if ( argc > 4 )
    device = (unsigned int) atoi( argv[4] );
  if ( argc > 5 )
    offset = (unsigned int) atoi( argv[5] );

  OutputData data;
  data.fd = fopen( file, "rb" );
  if ( !data.fd ) {
    std::cout << "Unable to find or open file!\n";
    exit( 1 );
  }

  // Set our stream parameters for output only.
  bufferFrames = 512;
  RtAudio::StreamParameters oParams;
  oParams.deviceId = device;
  oParams.nChannels = channels;
  oParams.firstChannel = offset;

  if ( device == 0 )
    oParams.deviceId = dac.getDefaultOutputDevice();

  data.channels = channels;
  try {
    dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &output, (void *)&data );
    dac.startStream();
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    goto cleanup;
  }

  std::cout << "\nPlaying raw file " << file << " (buffer frames = " << bufferFrames << ")." << std::endl;
  while ( 1 ) {
    SLEEP( 100 ); // wake every 100 ms to check if we're done
    if ( dac.isStreamRunning() == false ) break;
  }

 cleanup:
  fclose( data.fd );
  dac.closeStream();

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edi, %r12d
leal -0x7(%r12), %eax
cmpl $-0x4, %eax
jbe 0x48a1
movq %rsi, %r15
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4a8e
movq (%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x48a6
movq 0x8(%r15), %rdi
callq 0x4350
movl %eax, %r14d
movq 0x10(%r15), %rdi
callq 0x4350
movl %eax, 0x38(%rsp)
movq 0x18(%r15), %rbx
xorl %r13d, %r13d
cmpl $0x5, %r12d
jb 0x470b
movq 0x20(%r15), %rdi
callq 0x4350
movl %eax, %ebp
cmpl $0x5, %r12d
je 0x470d
movq 0x28(%r15), %rdi
callq 0x4350
movl %eax, %r13d
jmp 0x470d
xorl %ebp, %ebp
leaq 0x4a26(%rip), %rsi      # 0x913a
movq %rbx, %rdi
callq 0x4250
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x48c0
movl $0x200, 0x34(%rsp)      # imm = 0x200
movl %ebp, 0x3c(%rsp)
movl %r14d, 0x40(%rsp)
movl %r13d, 0x44(%rsp)
testl %ebp, %ebp
jne 0x4753
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rax
movl %r14d, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq -0x13b(%rip), %rax      # 0x4635
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
leaq 0x34(%rsp), %r9
movl $0x2, %ecx
xorl %edx, %edx
movl 0x38(%rsp), %r8d
callq 0x4c22
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x782a(%rip), %r14      # 0xbfd0
leaq 0x49ae(%rip), %rsi      # 0x915b
movl $0x12, %edx
movq %r14, %rdi
callq 0x4230
testq %rbx, %rbx
je 0x47db
movq %rbx, %rdi
callq 0x40c0
movq 0x7802(%rip), %rdi      # 0xbfd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4230
jmp 0x47f3
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x43c0
movq 0x77d6(%rip), %rdi      # 0xbfd0
leaq 0x496d(%rip), %rsi      # 0x916e
movl $0x12, %edx
callq 0x4230
movl 0x34(%rsp), %esi
movq 0x77ba(%rip), %rdi      # 0xbfd0
callq 0x4150
movq %rax, %rbx
leaq 0x495c(%rip), %rsi      # 0x9181
movl $0x2, %edx
movq %rax, %rdi
callq 0x4230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x41e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4160
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42c0
movq 0x28(%rsp), %rax
cmpl $0x2, 0x1bc(%rax)
je 0x4859
movq 0x48(%rsp), %rdi
callq 0x4200
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
leaq 0x28(%rsp), %rdi
callq 0x4c12
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x45cc
movq 0x7723(%rip), %rdi      # 0xbfd0
leaq 0x486c(%rip), %rsi      # 0x9120
callq 0x41f0
xorl %edi, %edi
callq 0x4280
movq 0x7709(%rip), %rdi      # 0xbfd0
leaq 0x486f(%rip), %rsi      # 0x913d
callq 0x41f0
movl $0x1, %edi
callq 0x4280
jmp 0x48eb
jmp 0x4974
jmp 0x4974
jmp 0x48eb
movq %rax, %rdi
callq 0x4989
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x4977
movq %rbx, %rdi
callq 0x40a0
movq %rax, %rbx
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x76bb(%rip), %rdi      # 0xbfd0
movl $0x1, %edx
callq 0x4230
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r14, %rdi
callq 0x4230
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4230
movq %rax, %rdi
callq 0x40d0
callq 0x43b0
jmp 0x4871
jmp 0x4974
movq %rax, %rbx
callq 0x43b0
jmp 0x4977
jmp 0x48eb
jmp 0x4974
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4c12
movq %rbx, %rdi
callq 0x43e0