// File: /workspace/github_cpp_makefile_star2_O2/tobias93[P]piano/rtmidi_build/RtMidi.cpp
// Function: MidiOutAlsa::openPort(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void MidiOutAlsa :: openPort( unsigned int portNumber, const std::string portName )
{
  if ( connected_ ) {
    errorString_ = "MidiOutAlsa::openPort: a valid connection already exists!";
    error( RtMidiError::WARNING, errorString_ );
    return;
  }

  unsigned int nSrc = this->getPortCount();
  if (nSrc < 1) {
    errorString_ = "MidiOutAlsa::openPort: no MIDI output sources found!";
    error( RtMidiError::NO_DEVICES_FOUND, errorString_ );
    return;
  }

	snd_seq_port_info_t *pinfo;
	snd_seq_port_info_alloca( &pinfo );
  AlsaMidiData *data = static_cast<AlsaMidiData *> (apiData_);
  if ( portInfo( data->seq, pinfo, SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, (int) portNumber ) == 0 ) {
    std::ostringstream ost;
    ost << "MidiOutAlsa::openPort: the 'portNumber' argument (" << portNumber << ") is invalid.";
    errorString_ = ost.str();
    error( RtMidiError::INVALID_PARAMETER, errorString_ );
    return;
  }

  snd_seq_addr_t sender, receiver;
  receiver.client = snd_seq_port_info_get_client( pinfo );
  receiver.port = snd_seq_port_info_get_port( pinfo );
  sender.client = snd_seq_client_id( data->seq );

  if ( data->vport < 0 ) {
    data->vport = snd_seq_create_simple_port( data->seq, portName.c_str(),
                                              SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
                                              SND_SEQ_PORT_TYPE_MIDI_GENERIC|SND_SEQ_PORT_TYPE_APPLICATION );
    if ( data->vport < 0 ) {
      errorString_ = "MidiOutAlsa::openPort: ALSA error creating output port.";
      error( RtMidiError::DRIVER_ERROR, errorString_ );
      return;
    }
  }

  sender.port = data->vport;

  // Make subscription
  if (snd_seq_port_subscribe_malloc( &data->subscription ) < 0) {
    snd_seq_port_subscribe_free( data->subscription );
    errorString_ = "MidiOutAlsa::openPort: error allocating port subscription.";
    error( RtMidiError::DRIVER_ERROR, errorString_ );
    return;
  }
  snd_seq_port_subscribe_set_sender(data->subscription, &sender);
  snd_seq_port_subscribe_set_dest(data->subscription, &receiver);
  snd_seq_port_subscribe_set_time_update(data->subscription, 1);
  snd_seq_port_subscribe_set_time_real(data->subscription, 1);
  if ( snd_seq_subscribe_port(data->seq, data->subscription) ) {
    snd_seq_port_subscribe_free( data->subscription );
    errorString_ = "MidiOutAlsa::openPort: ALSA error making port connection.";
    error( RtMidiError::DRIVER_ERROR, errorString_ );
    return;
  }

  connected_ = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, %rbx
cmpb $0x1, 0x10(%rdi)
jne 0x9cc5
leaq 0x18(%rbx), %r14
leaq 0x292e(%rip), %rsi      # 0xc5c0
movq %r14, %rdi
callq 0x7af0
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7720
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x7240
leaq -0xa8(%rbp), %rdi
jmp 0x9f76
movq %rdx, %r14
movl %esi, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x30(%rax)
testl %eax, %eax
je 0x9e1e
callq 0x7890
movq %rsp, %r12
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
callq 0x7890
movq %r12, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x71f0
movq 0x8(%rbx), %r13
movq (%r13), %rdi
pushq $0x42
popq %rdx
movq %r12, %rsi
movl %r15d, %ecx
callq 0x71d0
testl %eax, %eax
je 0x9e5d
movq %r12, %rdi
callq 0x7130
movb %al, -0x48(%rbp)
movq %r12, %rdi
callq 0x7900
movb %al, -0x47(%rbp)
movq (%r13), %rdi
callq 0x7b30
movb %al, -0x280(%rbp)
movl 0xc(%r13), %eax
testl %eax, %eax
jns 0x9d6f
movq (%r13), %rdi
movq (%r14), %rsi
pushq $0x21
popq %rdx
movl $0x100002, %ecx         # imm = 0x100002
callq 0x7800
movl %eax, 0xc(%r13)
testl %eax, %eax
js 0x9f3c
movb %al, -0x27f(%rbp)
leaq 0x10(%r13), %r14
movq %r14, %rdi
callq 0x7400
movq 0x10(%r13), %rdi
testl %eax, %eax
js 0x9ef5
leaq -0x280(%rbp), %rsi
callq 0x7330
movq 0x10(%r13), %rdi
leaq -0x48(%rbp), %rsi
callq 0x79b0
movq 0x10(%r13), %rdi
pushq $0x1
popq %r15
movl %r15d, %esi
callq 0x7650
movq 0x10(%r13), %rdi
movl %r15d, %esi
callq 0x7930
movq (%r13), %rdi
movq 0x10(%r13), %rsi
callq 0x7140
testl %eax, %eax
je 0x9f36
movq (%r14), %rdi
callq 0x77e0
leaq 0x18(%rbx), %r15
leaq 0x28eb(%rip), %rsi      # 0xc6d5
movq %r15, %rdi
callq 0x7af0
leaq -0xc8(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x7720
pushq $0x8
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x7240
leaq -0xc8(%rbp), %rdi
jmp 0x9f76
leaq 0x18(%rbx), %r14
leaq 0x27d1(%rip), %rsi      # 0xc5fa
movq %r14, %rdi
callq 0x7af0
leaq -0x88(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7720
pushq $0x3
popq %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x7240
leaq -0x88(%rbp), %rdi
jmp 0x9f76
leaq -0x280(%rbp), %r14
movq %r14, %rdi
callq 0x76d0
leaq 0x27bc(%rip), %rsi      # 0xc62f
movq %r14, %rdi
callq 0x7470
movl %r15d, %esi
movq %rax, %rdi
callq 0x7290
leaq 0x2507(%rip), %rsi      # 0xc394
movq %rax, %rdi
callq 0x7470
leaq -0x278(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x7860
leaq 0x18(%rbx), %r14
leaq -0x48(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x7600
movq %r15, %rdi
callq 0x7180
leaq -0x68(%rbp), %rdi
movq %r14, %rsi
callq 0x7720
pushq $0x6
popq %rsi
leaq -0x68(%rbp), %rdx
movq %rbx, %rdi
callq 0x7240
leaq -0x68(%rbp), %rdi
callq 0x7180
leaq -0x280(%rbp), %rdi
callq 0x7090
jmp 0x9f7b
callq 0x77e0
leaq 0x18(%rbx), %r15
leaq 0x2795(%rip), %rsi      # 0xc69a
movq %r15, %rdi
callq 0x7af0
leaq -0xe8(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x7720
pushq $0x8
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x7240
leaq -0xe8(%rbp), %rdi
jmp 0x9f76
movb $0x1, 0x10(%rbx)
jmp 0x9f7b
leaq 0x18(%rbx), %r15
leaq 0x271b(%rip), %rsi      # 0xc662
movq %r15, %rdi
callq 0x7af0
leaq -0x108(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x7720
pushq $0x8
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x7240
leaq -0x108(%rbp), %rdi
callq 0x7180
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9f8e
jmp 0x9f8e
movq %rax, %rbx
movq %r14, %rdi
jmp 0x9fcd
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x7180
jmp 0x9fb5
jmp 0x9fb2
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
jmp 0x9fcd
movq %rax, %rbx
leaq -0x280(%rbp), %rdi
callq 0x7090
jmp 0x9fd2
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x7180
movq %rbx, %rdi
callq 0x7a10