// File: /workspace/github_c_makefile_star2_O3/jonof[P]jfaudiolib/src/driver_alsa.c
// Function: ALSADrv_MIDI_Init
int ALSADrv_MIDI_Init(midifuncs *funcs, const char *params)
{
    int result;

    (void)params;
    
    ALSADrv_MIDI_Shutdown();
    memset(funcs, 0, sizeof(midifuncs));

    result = snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0);
    if (result < 0) {
        ASS_Message("ALSADrv: snd_seq_open err %d\n", result);
        ErrorCode = ALSAErr_SeqOpen;
        return ALSAErr_Error;
    }
    
    seq_port = snd_seq_create_simple_port(seq, "output",
                  SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE,
                  SND_SEQ_PORT_TYPE_APPLICATION);
    if (seq_port < 0) {
        ALSADrv_MIDI_Shutdown();
        ASS_Message("ALSADrv: snd_seq_create_simple_port err %d\n", seq_port);
        ErrorCode = ALSAErr_CreateSimplePort;
        return ALSAErr_Error;
    }
    
    snd_seq_set_client_name(seq, "JFAudioLib application");

    seq_queue = snd_seq_alloc_queue(seq);
    if (seq_queue < 0) {
        ALSADrv_MIDI_Shutdown();
        ASS_Message("ALSADrv: snd_seq_alloc_queue err %d\n", seq_queue);
        ErrorCode = ALSAErr_AllocQueue;
        return ALSAErr_Error;
    }
    
    result = snd_seq_connect_to(seq, seq_port, 128, 0);
    if (result < 0) {
        ALSADrv_MIDI_Shutdown();
        ASS_Message("ALSADrv: snd_seq_connect_to err %d\n", result);
        ErrorCode = ALSAErr_ConnectTo;
        return ALSAErr_Error;
    }
    
    funcs->NoteOff = Func_NoteOff;
    funcs->NoteOn  = Func_NoteOn;
    funcs->PolyAftertouch = Func_PolyAftertouch;
    funcs->ControlChange = Func_ControlChange;
    funcs->ProgramChange = Func_ProgramChange;
    funcs->ChannelAftertouch = Func_ChannelAftertouch;
    funcs->PitchBend = Func_PitchBend;
    
    return ALSAErr_Ok;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x926d
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
leaq 0x1069f(%rip), %rdi     # 0x19790
leaq 0x20a8(%rip), %rsi      # 0xb1a0
movl $0x3, %edx
xorl %ecx, %ecx
callq 0x20d0
testl %eax, %eax
js 0x91d8
movq 0x1067d(%rip), %rdi     # 0x19790
leaq 0x20ac(%rip), %rsi      # 0xb1c6
movl $0x3, %edx
movl $0x100000, %ecx         # imm = 0x100000
callq 0x2320
movl %eax, 0x7189(%rip)      # 0x102b8
testl %eax, %eax
js 0x91f4
movq 0x10652(%rip), %rdi     # 0x19790
leaq 0x20b4(%rip), %rsi      # 0xb1f9
callq 0x2200
movq 0x1063f(%rip), %rdi     # 0x19790
callq 0x21c0
movl %eax, 0x7160(%rip)      # 0x102bc
testl %eax, %eax
js 0x9219
movq 0x10625(%rip), %rdi     # 0x19790
movl 0x7147(%rip), %esi      # 0x102b8
xorl %ebp, %ebp
movl $0x80, %edx
xorl %ecx, %ecx
callq 0x23d0
testl %eax, %eax
js 0x923e
leaq 0x140(%rip), %rax       # 0x92ce
movq %rax, (%rbx)
leaq 0x1d0(%rip), %rax       # 0x9368
movq %rax, 0x8(%rbx)
leaq 0x25f(%rip), %rax       # 0x9402
movq %rax, 0x10(%rbx)
leaq 0x2ee(%rip), %rax       # 0x949c
movq %rax, 0x18(%rbx)
leaq 0x37f(%rip), %rax       # 0x9538
movq %rax, 0x20(%rbx)
leaq 0x40e(%rip), %rax       # 0x95d2
movq %rax, 0x28(%rbx)
leaq 0x49d(%rip), %rax       # 0x966c
movq %rax, 0x30(%rbx)
jmp 0x9266
leaq 0x1fc9(%rip), %rdi      # 0xb1a8
movl %eax, %esi
xorl %eax, %eax
callq 0x8b10
movl $0x2, 0x10596(%rip)     # 0x19788
jmp 0x9261
callq 0x926d
movl 0x70b9(%rip), %esi      # 0x102b8
leaq 0x1fc7(%rip), %rdi      # 0xb1cd
xorl %eax, %eax
callq 0x8b10
movl $0x3, 0x10571(%rip)     # 0x19788
jmp 0x9261
callq 0x926d
movl 0x7098(%rip), %esi      # 0x102bc
leaq 0x1fe5(%rip), %rdi      # 0xb210
xorl %eax, %eax
callq 0x8b10
movl $0x4, 0x1054c(%rip)     # 0x19788
jmp 0x9261
movl %eax, %r14d
callq 0x926d
leaq 0x1fe8(%rip), %rdi      # 0xb235
movl %r14d, %esi
xorl %eax, %eax
callq 0x8b10
movl $0x5, 0x10527(%rip)     # 0x19788
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq