// File: /workspace/github_cpp_makefile_star2_O1/tobias93[P]piano/rtmidi_build/RtMidi.cpp
// Function: MidiInAlsa::openVirtualPort(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void MidiInAlsa :: openVirtualPort( std::string portName )
{
  AlsaMidiData *data = static_cast<AlsaMidiData *> (apiData_);
  if ( data->vport < 0 ) {
    snd_seq_port_info_t *pinfo;
    snd_seq_port_info_alloca( &pinfo );
    snd_seq_port_info_set_capability( pinfo,
				      SND_SEQ_PORT_CAP_WRITE |
				      SND_SEQ_PORT_CAP_SUBS_WRITE );
    snd_seq_port_info_set_type( pinfo,
				SND_SEQ_PORT_TYPE_MIDI_GENERIC |
				SND_SEQ_PORT_TYPE_APPLICATION );
    snd_seq_port_info_set_midi_channels(pinfo, 16);
#ifndef AVOID_TIMESTAMPING
    snd_seq_port_info_set_timestamping(pinfo, 1);
    snd_seq_port_info_set_timestamp_real(pinfo, 1);    
    snd_seq_port_info_set_timestamp_queue(pinfo, data->queue_id);
#endif
    snd_seq_port_info_set_name(pinfo, portName.c_str());
    data->vport = snd_seq_create_port(data->seq, pinfo);

    if ( data->vport < 0 ) {
      errorString_ = "MidiInAlsa::openVirtualPort: ALSA error creating virtual port.";
      error( RtMidiError::DRIVER_ERROR, errorString_ );
      return;
    }
    data->vport = snd_seq_port_info_get_port(pinfo);
  }

  if ( inputData_.doInput == false ) {
    // Wait for old thread to stop, if still running
    if ( !pthread_equal(data->thread, data->dummy_thread_id) )
      pthread_join( data->thread, NULL );

    // Start the input queue
#ifndef AVOID_TIMESTAMPING
    snd_seq_start_queue( data->seq, data->queue_id, NULL );
    snd_seq_drain_output( data->seq );
#endif
    // Start our MIDI input thread.
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_attr_setschedpolicy(&attr, SCHED_OTHER);

    inputData_.doInput = true;
    int err = pthread_create(&data->thread, &attr, alsaMidiHandler, &inputData_);
    pthread_attr_destroy(&attr);
    if ( err ) {
      if ( data->subscription ) {
        snd_seq_unsubscribe_port( data->seq, data->subscription );
        snd_seq_port_subscribe_free( data->subscription );
        data->subscription = 0;
      }
      inputData_.doInput = false;
      errorString_ = "MidiInAlsa::openPort: error starting MIDI input thread!";
      error( RtMidiError::THREAD_ERROR, errorString_ );
      return;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %r13
cmpl $0x0, 0xc(%r13)
jns 0x9d6f
movq %rsi, %r14
callq 0x7760
movq %rsp, %r15
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
callq 0x7760
movq %r15, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x71d0
movq %r15, %rdi
movl $0x42, %esi
callq 0x77b0
movq %r15, %rdi
movl $0x100002, %esi         # imm = 0x100002
callq 0x71f0
movq %r15, %rdi
movl $0x10, %esi
callq 0x7170
movq %r15, %rdi
movl $0x1, %esi
callq 0x76a0
movq %r15, %rdi
movl $0x1, %esi
callq 0x7720
movl 0x48(%r13), %esi
movq %r15, %rdi
callq 0x78f0
movq (%r14), %rsi
movq %r15, %rdi
callq 0x7980
movq (%r13), %rdi
movq %r15, %rsi
callq 0x70b0
movl %eax, %r14d
movl %eax, 0xc(%r13)
testl %eax, %eax
js 0x9d09
movq %r15, %rdi
callq 0x77c0
movl %eax, 0xc(%r13)
jmp 0x9d6a
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x3760(%rip), %rcx      # 0xd478
movl $0x3e, %r8d
xorl %esi, %esi
callq 0x7710
leaq -0x58(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r15
movq %r15, %rdi
callq 0x7130
movq %rbx, %rdi
movl $0x8, %esi
movq %r15, %rdx
callq 0x7200
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x9d6a
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x7420
testl %r14d, %r14d
js 0x9d78
cmpb $0x0, 0x89(%rbx)
je 0x9d87
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50(%rbx), %r14
leaq 0x30(%r13), %r15
movq 0x30(%r13), %r12
movq 0x38(%r13), %rsi
movq %r12, %rdi
callq 0x7870
testl %eax, %eax
jne 0x9dad
movq %r12, %rdi
xorl %esi, %esi
callq 0x7380
movq (%r13), %rdi
movl 0x48(%r13), %esi
movl $0x1e, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x7470
movq (%r13), %rdi
callq 0x78c0
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
callq 0x7540
movq %r12, %rdi
xorl %esi, %esi
callq 0x7590
movq %r12, %rdi
xorl %esi, %esi
callq 0x7650
movb $0x1, 0x89(%rbx)
leaq -0x648(%rip), %rdx      # 0x97b6
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x7900
movl %eax, %r14d
movq %r12, %rdi
callq 0x77d0
testl %r14d, %r14d
je 0x9d78
movq 0x10(%r13), %rsi
testq %rsi, %rsi
je 0x9e43
movq (%r13), %rdi
callq 0x7880
movq 0x10(%r13), %rdi
callq 0x76c0
movq $0x0, 0x10(%r13)
movb $0x0, 0x89(%rbx)
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x35e7(%rip), %rcx      # 0xd440
movl $0x37, %r8d
xorl %esi, %esi
callq 0x7710
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x7130
movq %rbx, %rdi
movl $0xa, %esi
movq %r14, %rdx
callq 0x7200
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x9d78
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x7420
jmp 0x9d78
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x9edd
movq -0x58(%rbp), %rsi
jmp 0x9ed5
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x9edd
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x7420
movq %rbx, %rdi
callq 0x78b0
nop