// File: 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
subq $0xf0, %rsp
movq %rsi, -0xc0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jge 0x115b3
jmp 0x1144d
callq 0xe2f0
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
callq 0xe2f0
movq -0xc8(%rbp), %rdi
movq %rax, %rdx
xorl %esi, %esi
callq 0xd530
movq -0x20(%rbp), %rdi
movl $0x42, %esi
callq 0xe380
movq -0x20(%rbp), %rdi
movl $0x100002, %esi         # imm = 0x100002
callq 0xd580
movq -0x20(%rbp), %rdi
movl $0x10, %esi
callq 0xd430
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0xe160
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0xe260
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x48(%rax), %esi
callq 0xe630
movq -0xc0(%rbp), %rdi
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
callq 0xd3b0
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0xe780
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xd2f0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jge 0x115a1
movq -0xb8(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0xe0(%rbp)
leaq 0x7f3d(%rip), %rsi      # 0x19480
callq 0xdfb0
movq -0xe0(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0xd3d0
movq -0xb8(%rbp), %rdi
movq -0xd8(%rbp), %rdx
movl $0x8, %esi
callq 0xd5f0
jmp 0x11579
leaq -0x40(%rbp), %rdi
callq 0xd600
jmp 0x11753
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xd600
jmp 0x11758
movq -0x20(%rbp), %rdi
callq 0xe390
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0xb8(%rbp), %rax
movb 0x89(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11753
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0xe550
cmpl $0x0, %eax
jne 0x115f9
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd900
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x48(%rax), %esi
movl $0x1e, %edx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0xdbe0
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0xe5b0
leaq -0x88(%rbp), %rdi
callq 0xdda0
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0xdea0
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0xe040
movq -0xb8(%rbp), %rcx
movb $0x1, 0x89(%rcx)
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
addq $0x50, %rcx
leaq -0x88(%rbp), %rsi
leaq -0x9c4(%rip), %rdx      # 0x10cb0
callq 0xe650
movl %eax, -0x8c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xe3a0
cmpl $0x0, -0x8c(%rbp)
je 0x11751
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x116d0
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xe560
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xe1c0
movq -0x18(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0xb8(%rbp), %rdi
movb $0x0, 0x89(%rdi)
addq $0x18, %rdi
movq %rdi, -0xf0(%rbp)
leaq 0x7d58(%rip), %rsi      # 0x19448
callq 0xdfb0
movq -0xf0(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0xd3d0
movq -0xb8(%rbp), %rdi
movq -0xe8(%rbp), %rdx
movl $0xa, %esi
callq 0xd5f0
jmp 0x11729
leaq -0xb0(%rbp), %rdi
callq 0xd600
jmp 0x11753
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xd600
jmp 0x11758
jmp 0x11753
movq %rbp, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0xe590
nopw %cs:(%rax,%rax)