// File: /workspace/github_cpp_makefile_star2_O1/tobias93[P]piano/rtaudio/tests/record.cpp
// Function: main
int main( int argc, char *argv[] )
{
  unsigned int channels, fs, bufferFrames, device = 0, offset = 0;
  double time = 2.0;
  FILE *fd;

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

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

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

  // Let RtAudio print messages to stderr.
  adc.showWarnings( true );

  // Set our stream parameters for input only.
  bufferFrames = 512;
  RtAudio::StreamParameters iParams;
  if ( device == 0 )
    iParams.deviceId = adc.getDefaultInputDevice();
  else
    iParams.deviceId = device;
  iParams.nChannels = channels;
  iParams.firstChannel = offset;

  InputData data;
  data.buffer = 0;
  try {
    adc.openStream( NULL, &iParams, FORMAT, fs, &bufferFrames, &input, (void *)&data );
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    goto cleanup;
  }

  data.bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
  data.totalFrames = (unsigned long) (fs * time);
  data.frameCounter = 0;
  data.channels = channels;
  unsigned long totalBytes;
  totalBytes = data.totalFrames * channels * sizeof( MY_TYPE );

  // Allocate the entire data buffer before starting stream.
  data.buffer = (MY_TYPE*) malloc( totalBytes );
  if ( data.buffer == 0 ) {
    std::cout << "Memory allocation error ... quitting!\n";
    goto cleanup;
  }

  try {
    adc.startStream();
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    goto cleanup;
  }

  std::cout << "\nRecording for " << time << " seconds ... writing file 'record.raw' (buffer frames = " << bufferFrames << ")." << std::endl;
  while ( adc.isStreamRunning() ) {
    SLEEP( 100 ); // wake every 100 ms to check if we're done
  }

  // Now write the entire data to the file.
  fd = fopen( "record.raw", "wb" );
  fwrite( data.buffer, sizeof( MY_TYPE ), data.totalFrames * channels, fd );
  fclose( fd );

 cleanup:
  if ( adc.isStreamOpen() ) adc.closeStream();
  if ( data.buffer ) free( data.buffer );

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edi, %r15d
leal -0x7(%r15), %eax
cmpl $-0x5, %eax
jbe 0x4993
movq %rsi, %r14
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4bec
movq (%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x4998
movq 0x8(%r14), %rdi
callq 0x4360
movl %eax, %ebx
movq 0x10(%r14), %rdi
callq 0x4360
movl %eax, %ebp
cmpl $0x4, %r15d
jl 0x472a
movq 0x18(%r14), %rdi
callq 0x42a0
jmp 0x4732
movsd 0x48d6(%rip), %xmm0     # 0x9008
movsd %xmm0, 0x38(%rsp)
xorl %r12d, %r12d
movl $0x0, %r13d
cmpl $0x5, %r15d
jl 0x4753
movq 0x20(%r14), %rdi
callq 0x4360
movl %eax, %r13d
cmpl $0x6, %r15d
jl 0x4765
movq 0x28(%r14), %rdi
callq 0x4360
movl %eax, %r12d
movq 0x28(%rsp), %rdi
movb $0x1, 0x1a0(%rdi)
movl $0x200, 0x34(%rsp)      # imm = 0x200
movq $0x0, 0x44(%rsp)
movl $0x0, 0x4c(%rsp)
testl %r13d, %r13d
jne 0x4798
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, %r13d
leaq 0x44(%rsp), %rdx
movl %r13d, (%rdx)
movl %ebx, 0x4(%rdx)
movl %r12d, 0x8(%rdx)
leaq 0x50(%rsp), %rax
movq $0x0, (%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq -0x164(%rip), %rax      # 0x4665
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x34(%rsp), %r9
movl $0x2, %ecx
xorl %esi, %esi
movl %ebp, %r8d
callq 0x4d80
movl 0x34(%rsp), %eax
imull %ebx, %eax
addq %rax, %rax
movq %rax, 0x58(%rsp)
movl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x38(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x47f7(%rip), %xmm0     # 0x9010
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
movq %rdi, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movl %ebx, 0x70(%rsp)
movl %ebx, %ebx
imulq %rbx, %rdi
addq %rdi, %rdi
callq 0x42b0
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x493d
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x776c(%rip), %rdi      # 0xbfd0
leaq 0x4930(%rip), %rsi      # 0x919b
movl $0xf, %edx
callq 0x4230
movq 0x7754(%rip), %rdi      # 0xbfd0
movsd 0x38(%rsp), %xmm0
callq 0x4390
movq %rax, %r14
leaq 0x491a(%rip), %rsi      # 0x91ab
movl $0x38, %edx
movq %rax, %rdi
callq 0x4230
movl 0x34(%rsp), %esi
movq %r14, %rdi
callq 0x4150
movq %rax, %r14
leaq 0x4930(%rip), %rsi      # 0x91e4
movl $0x2, %edx
movq %rax, %rdi
callq 0x4230
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x41e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4160
movq 0x28(%rsp), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x4902
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42e0
jmp 0x48e8
leaq 0x48de(%rip), %rdi      # 0x91e7
leaq 0x48e2(%rip), %rsi      # 0x91f2
callq 0x4250
movq %rax, %r14
movq 0x50(%rsp), %rdi
imulq 0x60(%rsp), %rbx
movl $0x2, %esi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x4460
movq %r14, %rdi
callq 0x4200
jmp 0x4955
movq 0x768c(%rip), %rdi      # 0xbfd0
leaq 0x4829(%rip), %rsi      # 0x9174
movl $0x26, %edx
callq 0x4230
movq 0x28(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4969
movq (%rdi), %rax
callq *0x38(%rax)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4978
callq 0x4260
leaq 0x28(%rsp), %rdi
callq 0x4d70
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x45fc
movq 0x7631(%rip), %rdi      # 0xbfd0
leaq 0x47b4(%rip), %rsi      # 0x915a
callq 0x41f0
movl $0x1, %edi
callq 0x4280
jmp 0x4ac8
jmp 0x4ac8
jmp 0x4ad2
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x4ad5
movq %rbx, %rdi
callq 0x40a0
movq %rax, %rbx
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x75e6(%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 0x43d0
jmp 0x4955
jmp 0x4ad2
movq %rax, %rbx
callq 0x43d0
jmp 0x4ad5
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x4ad5
movq %rbx, %rdi
callq 0x40a0
movq %rax, %rbx
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x7562(%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 0x43d0
jmp 0x4955
jmp 0x4ad2
movq %rax, %rbx
callq 0x43d0
jmp 0x4ad5
jmp 0x4ac8
movq %rax, %rdi
callq 0x4ae7
jmp 0x4ad2
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4d70
movq %rbx, %rdi
callq 0x4400