// File: /workspace/github_cpp_makefile_star2_O1/tobias93[P]piano/rtaudio/RtAudio.cpp
// Function: RtApiPulse::callbackEvent()
void RtApiPulse::callbackEvent( void )
{
  PulseAudioHandle *pah = static_cast<PulseAudioHandle *>( stream_.apiHandle );

  if ( stream_.state == STREAM_STOPPED ) {
    MUTEX_LOCK( &stream_.mutex );
    while ( !pah->runnable )
      pthread_cond_wait( &pah->runnable_cv, &stream_.mutex );

    if ( stream_.state != STREAM_RUNNING ) {
      MUTEX_UNLOCK( &stream_.mutex );
      return;
    }
    MUTEX_UNLOCK( &stream_.mutex );
  }

  if ( stream_.state == STREAM_CLOSED ) {
    errorText_ = "RtApiPulse::callbackEvent(): the stream is closed ... "
      "this shouldn't happen!";
    error( RtAudioError::WARNING );
    return;
  }

  RtAudioCallback callback = (RtAudioCallback) stream_.callbackInfo.callback;
  double streamTime = getStreamTime();
  RtAudioStreamStatus status = 0;
  int doStopStream = callback( stream_.userBuffer[OUTPUT], stream_.userBuffer[INPUT],
                               stream_.bufferSize, streamTime, status,
                               stream_.callbackInfo.userData );

  if ( doStopStream == 2 ) {
    abortStream();
    return;
  }

  MUTEX_LOCK( &stream_.mutex );
  void *pulse_in = stream_.doConvertBuffer[INPUT] ? stream_.deviceBuffer : stream_.userBuffer[INPUT];
  void *pulse_out = stream_.doConvertBuffer[OUTPUT] ? stream_.deviceBuffer : stream_.userBuffer[OUTPUT];

  if ( stream_.state != STREAM_RUNNING )
    goto unlock;

  int pa_error;
  size_t bytes;
  if (stream_.mode == OUTPUT || stream_.mode == DUPLEX ) {
    if ( stream_.doConvertBuffer[OUTPUT] ) {
        convertBuffer( stream_.deviceBuffer,
                       stream_.userBuffer[OUTPUT],
                       stream_.convertInfo[OUTPUT] );
        bytes = stream_.nDeviceChannels[OUTPUT] * stream_.bufferSize *
                formatBytes( stream_.deviceFormat[OUTPUT] );
    } else
        bytes = stream_.nUserChannels[OUTPUT] * stream_.bufferSize *
                formatBytes( stream_.userFormat );

    if ( pa_simple_write( pah->s_play, pulse_out, bytes, &pa_error ) < 0 ) {
      errorStream_ << "RtApiPulse::callbackEvent: audio write error, " <<
        pa_strerror( pa_error ) << ".";
      errorText_ = errorStream_.str();
      error( RtAudioError::WARNING );
    }
  }

  if ( stream_.mode == INPUT || stream_.mode == DUPLEX) {
    if ( stream_.doConvertBuffer[INPUT] )
      bytes = stream_.nDeviceChannels[INPUT] * stream_.bufferSize *
        formatBytes( stream_.deviceFormat[INPUT] );
    else
      bytes = stream_.nUserChannels[INPUT] * stream_.bufferSize *
        formatBytes( stream_.userFormat );
            
    if ( pa_simple_read( pah->s_rec, pulse_in, bytes, &pa_error ) < 0 ) {
      errorStream_ << "RtApiPulse::callbackEvent: audio read error, " <<
        pa_strerror( pa_error ) << ".";
      errorText_ = errorStream_.str();
      error( RtAudioError::WARNING );
    }
    if ( stream_.doConvertBuffer[INPUT] ) {
      convertBuffer( stream_.userBuffer[INPUT],
                     stream_.deviceBuffer,
                     stream_.convertInfo[INPUT] );
    }
  }

 unlock:
  MUTEX_UNLOCK( &stream_.mutex );
  RtApi::tickStreamTime();

  if ( doStopStream == 1 )
    stopStream();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0x1b0(%rdi), %rbp
cmpl $0x0, 0x1bc(%rdi)
jne 0x5ca4
leaq 0x230(%rbx), %r14
movq %r14, %rdi
callq 0x42b0
cmpb $0x0, 0x48(%rbp)
jne 0x5c8b
leaq 0x18(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x42f0
cmpb $0x1, 0x48(%rbp)
jne 0x5c7a
movl 0x1bc(%rbx), %r15d
movq %r14, %rdi
callq 0x4160
cmpl $0x2, %r15d
jne 0x6016
cmpl $-0x32, 0x1bc(%rbx)
jne 0x5ce7
leaq 0x180(%rbx), %rdi
movq 0x188(%rbx), %rdx
leaq 0x3b57(%rip), %rcx      # 0x9819
movl $0x4c, %r8d
xorl %esi, %esi
callq 0x4310
movq %rbx, %rdi
xorl %esi, %esi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5584
movq 0x268(%rbx), %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x58(%rax)
movq 0x1c0(%rbx), %rdi
movq 0x1c8(%rbx), %rsi
movl 0x1e4(%rbx), %edx
movq 0x270(%rbx), %r8
xorl %ecx, %ecx
callq *%r14
cmpl $0x2, %eax
jne 0x5d33
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x50(%rax)
movl %eax, %r15d
leaq 0x230(%rbx), %r14
movq %r14, %rdi
callq 0x42b0
movq 0x1d0(%rbx), %r12
cmpb $0x0, 0x1d9(%rbx)
movq %r12, %r13
jne 0x5d5f
movq 0x1c8(%rbx), %r13
movb 0x1d8(%rbx), %al
testb %al, %al
jne 0x5d70
movq 0x1c0(%rbx), %r12
cmpl $0x2, 0x1bc(%rbx)
jne 0x5fc4
testl $0xfffffffd, 0x1b8(%rbx) # imm = 0xFFFFFFFD
jne 0x5ebe
testb %al, %al
movq %r13, 0x10(%rsp)
je 0x5dbf
movq 0x1c0(%rbx), %rdx
movq 0x1d0(%rbx), %rsi
leaq 0x290(%rbx), %rcx
movq %rbx, %rdi
callq 0x6026
movl $0x220, %eax            # imm = 0x220
movl $0x1f4, %ecx            # imm = 0x1F4
jmp 0x5dc9
movl $0x218, %eax            # imm = 0x218
movl $0x1ec, %ecx            # imm = 0x1EC
movl 0x1e4(%rbx), %r13d
imull (%rbx,%rcx), %r13d
movq (%rbx,%rax), %rsi
movq %rbx, %rdi
callq 0x5800
imull %eax, %r13d
movq (%rbp), %rdi
leaq 0xc(%rsp), %rcx
movq %r12, %rsi
movq %r13, %rdx
callq 0x4330
testl %eax, %eax
movq 0x10(%rsp), %r13
jns 0x5ebe
leaq 0x8(%rbx), %r12
leaq 0x3a55(%rip), %rsi      # 0x9866
movl $0x2e, %edx
movq %r12, %rdi
callq 0x4200
movl 0xc(%rsp), %edi
callq 0x4050
testq %rax, %rax
je 0x5e47
movq %rax, %r13
movq %rax, %rdi
callq 0x40c0
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x4200
jmp 0x5e60
movq (%r12), %rax
movq -0x18(%rax), %rax
leaq (%r12,%rax), %rdi
movl 0x20(%r12,%rax), %esi
orl $0x1, %esi
callq 0x4390
leaq 0x3e28(%rip), %rsi      # 0x9c8f
movl $0x1, %edx
movq %r12, %rdi
callq 0x4200
leaq 0x10(%rbx), %rsi
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x4340
leaq 0x180(%rbx), %rdi
movq %r12, %rsi
callq 0x4260
movq (%r12), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
movq 0x10(%rsp), %r13
je 0x5eb4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x41f0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5584
movl 0x1b8(%rbx), %eax
decl %eax
cmpl $0x1, %eax
ja 0x5fc4
movzbl 0x1d9(%rbx), %eax
movl 0x1e4(%rbx), %r12d
imull 0x1f0(%rbx,%rax,8), %r12d
shll $0x4, %eax
movq 0x218(%rax,%rbx), %rsi
movq %rbx, %rdi
callq 0x5800
imull %eax, %r12d
movq 0x8(%rbp), %rdi
leaq 0xc(%rsp), %rcx
movq %r13, %rsi
movq %r12, %rdx
callq 0x42c0
testl %eax, %eax
jns 0x5f9e
leaq 0x8(%rbx), %r12
leaq 0x3971(%rip), %rsi      # 0x9895
movl $0x2d, %edx
movq %r12, %rdi
callq 0x4200
movl 0xc(%rsp), %edi
callq 0x4050
movq %r12, %rdi
movq %rax, %rsi
callq 0x41d0
leaq 0x3d43(%rip), %rsi      # 0x9c8f
movl $0x1, %edx
movq %rax, %rdi
callq 0x4200
leaq 0x10(%rbx), %rsi
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x4340
leaq 0x180(%rbx), %rdi
movq %r12, %rsi
callq 0x4260
movq (%r12), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x5f94
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x41f0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5584
cmpb $0x1, 0x1d9(%rbx)
jne 0x5fc4
movq 0x1c8(%rbx), %rsi
movq 0x1d0(%rbx), %rdx
leaq 0x2e0(%rbx), %rcx
movq %rbx, %rdi
callq 0x6026
movq %r14, %rdi
callq 0x4160
movl 0x1e4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl 0x1e0(%rbx), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
addsd 0x330(%rbx), %xmm0
movsd %xmm0, 0x330(%rbx)
leaq 0x338(%rbx), %rdi
xorl %esi, %esi
callq 0x4350
cmpl $0x1, %r15d
jne 0x6016
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop