// File: /workspace/github_cpp_makefile_star2_O3/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 0xa5a1
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x306a(%rip), %rcx      # 0xd5b0
movl $0x39, %r8d
xorl %esi, %esi
callq 0x7710
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
callq 0x7130
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x7200
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xa954
movq -0x98(%rbp), %rsi
jmp 0xa94c
movq %rdx, %r14
movl %esi, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x30(%rax)
testl %eax, %eax
je 0xa72c
callq 0x7760
movq %rsp, %r12
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
callq 0x7760
movq %r12, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x71d0
movq 0x8(%rbx), %r13
movq (%r13), %rdi
movq %r12, %rsi
movl $0x42, %edx
movl %r15d, %ecx
callq 0x71a0
testl %eax, %eax
je 0xa793
movq %r12, %rdi
callq 0x7110
movb %al, -0x68(%rbp)
movq %r12, %rdi
callq 0x77c0
movb %al, -0x67(%rbp)
movq (%r13), %rdi
callq 0x79a0
movb %al, -0x280(%rbp)
movl 0xc(%r13), %eax
testl %eax, %eax
jns 0xa64f
movq (%r13), %rdi
movq (%r14), %rsi
movl $0x21, %edx
movl $0x100002, %ecx         # imm = 0x100002
callq 0x76e0
movl %eax, 0xc(%r13)
testl %eax, %eax
js 0xa8e8
movb %al, -0x27f(%rbp)
leaq 0x10(%r13), %r14
movq %r14, %rdi
callq 0x7390
movq 0x10(%r13), %rdi
testl %eax, %eax
js 0xa877
leaq -0x280(%rbp), %rsi
callq 0x72e0
movq 0x10(%r13), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7850
movq 0x10(%r13), %rdi
movl $0x1, %esi
callq 0x75a0
movq 0x10(%r13), %rdi
movl $0x1, %esi
callq 0x77e0
movq (%r13), %rdi
movq 0x10(%r13), %rsi
callq 0x7120
testl %eax, %eax
je 0xa8e2
movq (%r14), %rdi
callq 0x76c0
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x2ff7(%rip), %rcx      # 0xd6c5
movl $0x39, %r8d
xorl %esi, %esi
callq 0x7710
leaq -0xb8(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %r14
movq %r14, %rdi
callq 0x7130
movq %rbx, %rdi
movl $0x8, %esi
movq %r14, %rdx
callq 0x7200
movq -0xc8(%rbp), %rdi
cmpq %r15, %rdi
je 0xa954
movq -0xb8(%rbp), %rsi
jmp 0xa94c
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x2eaf(%rip), %rcx      # 0xd5ea
movl $0x34, %r8d
xorl %esi, %esi
callq 0x7710
leaq -0x78(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %r14
movq %r14, %rdi
callq 0x7130
movq %rbx, %rdi
movl $0x3, %esi
movq %r14, %rdx
callq 0x7200
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0xa954
movq -0x78(%rbp), %rsi
jmp 0xa94c
leaq -0x280(%rbp), %r14
movq %r14, %rdi
callq 0x7610
leaq 0x2e76(%rip), %rsi      # 0xd61f
movl $0x32, %edx
movq %r14, %rdi
callq 0x74a0
movl %r15d, %esi
leaq -0x280(%rbp), %rdi
callq 0x7230
leaq 0x2bb8(%rip), %rsi      # 0xd384
movl $0xd, %edx
movq %rax, %rdi
callq 0x74a0
leaq -0x278(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x7740
leaq 0x18(%rbx), %rdi
leaq -0x68(%rbp), %r14
movq %r14, %rsi
callq 0x7560
movq (%r14), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xa811
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x7420
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x7130
leaq -0x48(%rbp), %rdx
movq %rbx, %rdi
movl $0x6, %esi
callq 0x7200
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0xa853
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x7420
movq 0x675e(%rip), %rsi      # 0x10fb8
leaq -0x280(%rbp), %rdi
callq 0x71c0
leaq -0x210(%rbp), %rdi
callq 0x70c0
jmp 0xa954
callq 0x76c0
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x2dff(%rip), %rcx      # 0xd68a
movl $0x3a, %r8d
xorl %esi, %esi
callq 0x7710
leaq -0xd8(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %r14
movq %r14, %rdi
callq 0x7130
movq %rbx, %rdi
movl $0x8, %esi
movq %r14, %rdx
callq 0x7200
movq -0xe8(%rbp), %rdi
cmpq %r15, %rdi
je 0xa954
movq -0xd8(%rbp), %rsi
jmp 0xa94c
movb $0x1, 0x10(%rbx)
jmp 0xa954
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x2d5b(%rip), %rcx      # 0xd652
movl $0x37, %r8d
xorl %esi, %esi
callq 0x7710
leaq -0xf8(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %r14
movq %r14, %rdi
callq 0x7130
movq %rbx, %rdi
movl $0x8, %esi
movq %r14, %rdx
callq 0x7200
movq -0x108(%rbp), %rdi
cmpq %r15, %rdi
je 0xa954
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x7420
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x108(%rbp), %rdi
jmp 0xa985
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
jmp 0xa985
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
cmpq %r15, %rdi
je 0xaa02
movq (%r15), %rsi
jmp 0xa9fa
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0xa9c3
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x7420
jmp 0xa9c3
jmp 0xa9c0
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0xaa02
movq -0x78(%rbp), %rsi
jmp 0xa9fa
movq %rax, %rbx
movq 0x65ee(%rip), %rsi      # 0x10fb8
leaq -0x280(%rbp), %rdi
callq 0x71c0
leaq -0x210(%rbp), %rdi
callq 0x70c0
jmp 0xaa02
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xaa02
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x7420
movq %rbx, %rdi
callq 0x78b0