// File: /workspace/github_cpp_makefile_star2_O3/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, %r12d
leal -0x7(%r12), %eax
cmpl $-0x5, %eax
jbe 0x499f
movq %rsi, %r15
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4bfa
movq (%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x49a4
movq 0x8(%r15), %rdi
callq 0x4360
movl %eax, %ebx
movq 0x10(%r15), %rdi
callq 0x4360
movl %eax, %ebp
xorl %r14d, %r14d
cmpl $0x4, %r12d
jb 0x4760
movq 0x18(%r15), %rdi
callq 0x42a0
movsd %xmm0, 0x38(%rsp)
cmpl $0x4, %r12d
je 0x476e
movq 0x20(%r15), %rdi
callq 0x4360
movl %eax, %r13d
cmpl $0x6, %r12d
jb 0x4771
movq 0x28(%r15), %rdi
callq 0x4360
movl %eax, %r14d
jmp 0x4771
movsd 0x48a0(%rip), %xmm0     # 0x9008
movsd %xmm0, 0x38(%rsp)
xorl %r13d, %r13d
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 0x47a4
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, %r13d
leaq 0x44(%rsp), %rdx
movl %r13d, (%rdx)
movl %ebx, 0x4(%rdx)
movl %r14d, 0x8(%rdx)
leaq 0x50(%rsp), %rax
movq $0x0, (%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq -0x170(%rip), %rax      # 0x4665
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x34(%rsp), %r9
movl $0x2, %ecx
xorl %esi, %esi
movl %ebp, %r8d
callq 0x4d8e
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 0x47eb(%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 0x4949
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x7760(%rip), %rdi      # 0xbfd0
leaq 0x4924(%rip), %rsi      # 0x919b
movl $0xf, %edx
callq 0x4230
movq 0x7748(%rip), %rdi      # 0xbfd0
movsd 0x38(%rsp), %xmm0
callq 0x4390
movq %rax, %r14
leaq 0x490e(%rip), %rsi      # 0x91ab
movl $0x38, %edx
movq %rax, %rdi
callq 0x4230
movl 0x34(%rsp), %esi
movq %r14, %rdi
callq 0x4150
movq %rax, %r14
leaq 0x4924(%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 0x490e
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42e0
jmp 0x48f4
leaq 0x48d2(%rip), %rdi      # 0x91e7
leaq 0x48d6(%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 0x4961
movq 0x7680(%rip), %rdi      # 0xbfd0
leaq 0x481d(%rip), %rsi      # 0x9174
movl $0x26, %edx
callq 0x4230
movq 0x28(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4975
movq (%rdi), %rax
callq *0x38(%rax)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4984
callq 0x4260
leaq 0x28(%rsp), %rdi
callq 0x4d7e
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x45fc
movq 0x7625(%rip), %rdi      # 0xbfd0
leaq 0x47a8(%rip), %rsi      # 0x915a
callq 0x41f0
movl $0x1, %edi
callq 0x4280
jmp 0x4ad4
jmp 0x4ad4
jmp 0x4ade
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x4ae1
movq %rbx, %rdi
callq 0x40a0
movq %rax, %rbx
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x75da(%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 0x4961
jmp 0x4ade
movq %rax, %rbx
callq 0x43d0
jmp 0x4ae1
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x4ae1
movq %rbx, %rdi
callq 0x40a0
movq %rax, %rbx
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x7556(%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 0x4961
jmp 0x4ade
movq %rax, %rbx
callq 0x43d0
jmp 0x4ae1
jmp 0x4ad4
movq %rax, %rdi
callq 0x4af3
jmp 0x4ade
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4d7e
movq %rbx, %rdi
callq 0x4400