// File: tobias93[P]piano/rtaudio/RtAudio.cpp
// Function: RtApi::openStream(RtAudio::StreamParameters*, RtAudio::StreamParameters*, unsigned long, unsigned int, unsigned int*, int (*)(void*, void*, unsigned int, double, unsigned int, void*), void*, RtAudio::StreamOptions*, void (*)(RtAudioError::Type, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&))
void RtApi :: openStream( RtAudio::StreamParameters *oParams,
                          RtAudio::StreamParameters *iParams,
                          RtAudioFormat format, unsigned int sampleRate,
                          unsigned int *bufferFrames,
                          RtAudioCallback callback, void *userData,
                          RtAudio::StreamOptions *options,
                          RtAudioErrorCallback errorCallback )
{
  if ( stream_.state != STREAM_CLOSED ) {
    errorText_ = "RtApi::openStream: a stream is already open!";
    error( RtAudioError::INVALID_USE );
    return;
  }

  // Clear stream information potentially left from a previously open stream.
  clearStreamInfo();

  if ( oParams && oParams->nChannels < 1 ) {
    errorText_ = "RtApi::openStream: a non-NULL output StreamParameters structure cannot have an nChannels value less than one.";
    error( RtAudioError::INVALID_USE );
    return;
  }

  if ( iParams && iParams->nChannels < 1 ) {
    errorText_ = "RtApi::openStream: a non-NULL input StreamParameters structure cannot have an nChannels value less than one.";
    error( RtAudioError::INVALID_USE );
    return;
  }

  if ( oParams == NULL && iParams == NULL ) {
    errorText_ = "RtApi::openStream: input and output StreamParameters structures are both NULL!";
    error( RtAudioError::INVALID_USE );
    return;
  }

  if ( formatBytes(format) == 0 ) {
    errorText_ = "RtApi::openStream: 'format' parameter value is undefined.";
    error( RtAudioError::INVALID_USE );
    return;
  }

  unsigned int nDevices = getDeviceCount();
  unsigned int oChannels = 0;
  if ( oParams ) {
    oChannels = oParams->nChannels;
    if ( oParams->deviceId >= nDevices ) {
      errorText_ = "RtApi::openStream: output device parameter value is invalid.";
      error( RtAudioError::INVALID_USE );
      return;
    }
  }

  unsigned int iChannels = 0;
  if ( iParams ) {
    iChannels = iParams->nChannels;
    if ( iParams->deviceId >= nDevices ) {
      errorText_ = "RtApi::openStream: input device parameter value is invalid.";
      error( RtAudioError::INVALID_USE );
      return;
    }
  }

  bool result;

  if ( oChannels > 0 ) {

    result = probeDeviceOpen( oParams->deviceId, OUTPUT, oChannels, oParams->firstChannel,
                              sampleRate, format, bufferFrames, options );
    if ( result == false ) {
      error( RtAudioError::SYSTEM_ERROR );
      return;
    }
  }

  if ( iChannels > 0 ) {

    result = probeDeviceOpen( iParams->deviceId, INPUT, iChannels, iParams->firstChannel,
                              sampleRate, format, bufferFrames, options );
    if ( result == false ) {
      if ( oChannels > 0 ) closeStream();
      error( RtAudioError::SYSTEM_ERROR );
      return;
    }
  }

  stream_.callbackInfo.callback = (void *) callback;
  stream_.callbackInfo.userData = userData;
  stream_.callbackInfo.errorCallback = (void *) errorCallback;

  if ( options ) options->numberOfBuffers = stream_.nBuffers;
  stream_.state = STREAM_STOPPED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x68, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $-0x32, 0x1bc(%rax)
je 0x9b2c
movq -0x50(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x9a00(%rip), %rsi      # 0x13514
callq 0x8330
movq -0x50(%rbp), %rdi
movl $0x7, %esi
callq 0x9f60
jmp 0x9df5
movq -0x50(%rbp), %rdi
callq 0xa180
cmpq $0x0, -0x18(%rbp)
je 0x9b70
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jae 0x9b70
movq -0x50(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x99e9(%rip), %rsi      # 0x13541
callq 0x8330
movq -0x50(%rbp), %rdi
movl $0x7, %esi
callq 0x9f60
jmp 0x9df5
cmpq $0x0, -0x20(%rbp)
je 0x9bab
movq -0x20(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jae 0x9bab
movq -0x50(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x9a1c(%rip), %rsi      # 0x135af
callq 0x8330
movq -0x50(%rbp), %rdi
movl $0x7, %esi
callq 0x9f60
jmp 0x9df5
cmpq $0x0, -0x18(%rbp)
jne 0x9be3
cmpq $0x0, -0x20(%rbp)
jne 0x9be3
movq -0x50(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x9a51(%rip), %rsi      # 0x1361c
callq 0x8330
movq -0x50(%rbp), %rdi
movl $0x7, %esi
callq 0x9f60
jmp 0x9df5
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xa3d0
cmpl $0x0, %eax
jne 0x9c1f
movq -0x50(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x9a64(%rip), %rsi      # 0x1366b
callq 0x8330
movq -0x50(%rbp), %rdi
movl $0x7, %esi
callq 0x9f60
jmp 0x9df5
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x9c7b
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl -0x3c(%rbp), %eax
jb 0x9c79
movq -0x50(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x9a44(%rip), %rsi      # 0x136a5
callq 0x8330
movq -0x50(%rbp), %rdi
movl $0x7, %esi
callq 0x9f60
jmp 0x9df5
jmp 0x9c7b
movl $0x0, -0x44(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x9cca
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x3c(%rbp), %eax
jb 0x9cc8
movq -0x50(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x9a32(%rip), %rsi      # 0x136e2
callq 0x8330
movq -0x50(%rbp), %rdi
movl $0x7, %esi
callq 0x9f60
jmp 0x9df5
jmp 0x9cca
cmpl $0x0, -0x40(%rbp)
jbe 0x9d32
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movl -0x40(%rbp), %ecx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %r8d
movl -0x2c(%rbp), %r9d
movq -0x28(%rbp), %rbx
movq -0x38(%rbp), %r11
movq 0x20(%rbp), %r10
movq (%rdi), %rax
xorl %edx, %edx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *0x68(%rax)
andb $0x1, %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x9d30
movq -0x50(%rbp), %rdi
movl $0x9, %esi
callq 0x9f60
jmp 0x9df5
jmp 0x9d32
cmpl $0x0, -0x44(%rbp)
jbe 0x9daa
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %esi
movl -0x44(%rbp), %ecx
movq -0x20(%rbp), %rax
movl 0x8(%rax), %r8d
movl -0x2c(%rbp), %r9d
movq -0x28(%rbp), %rbx
movq -0x38(%rbp), %r11
movq 0x20(%rbp), %r10
movq (%rdi), %rax
movl $0x1, %edx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *0x68(%rax)
andb $0x1, %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x9da8
cmpl $0x0, -0x40(%rbp)
jbe 0x9d98
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq -0x50(%rbp), %rdi
movl $0x9, %esi
callq 0x9f60
jmp 0x9df5
jmp 0x9daa
movq -0x50(%rbp), %rax
movq 0x10(%rbp), %rcx
movq %rcx, 0x268(%rax)
movq 0x18(%rbp), %rcx
movq %rcx, 0x270(%rax)
movq 0x28(%rbp), %rcx
movq %rcx, 0x278(%rax)
cmpq $0x0, 0x20(%rbp)
je 0x9de7
movq -0x50(%rbp), %rax
movl 0x1e8(%rax), %ecx
movq 0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x50(%rbp), %rax
movl $0x0, 0x1bc(%rax)
addq $0x68, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax)