// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
callq 0xe160
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0x2100
leaq 0x11234(%rip), %rdi     # 0x1f1d0
leaq 0x1e35(%rip), %rsi      # 0xfdd8
movl $0x3, %edx
xorl %ecx, %ecx
callq 0x20d0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xdfdf
movl -0x1c(%rbp), %esi
leaq 0x1e1e(%rip), %rdi      # 0xfde0
movb $0x0, %al
callq 0xd640
movl $0x2, 0x111f5(%rip)     # 0x1f1c8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe151
movq 0x111ea(%rip), %rdi     # 0x1f1d0
leaq 0x1e11(%rip), %rsi      # 0xfdfe
movl $0x3, %edx
movl $0x100000, %ecx         # imm = 0x100000
callq 0x2310
movl %eax, 0x7c76(%rip)      # 0x15c78
cmpl $0x0, 0x7c6f(%rip)      # 0x15c78
jge 0xe03a
callq 0xe160
movl 0x7c62(%rip), %esi      # 0x15c78
leaq 0x1de8(%rip), %rdi      # 0xfe05
movb $0x0, %al
callq 0xd640
movl $0x3, 0x1119a(%rip)     # 0x1f1c8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe151
movq 0x1118f(%rip), %rdi     # 0x1f1d0
leaq 0x1de9(%rip), %rsi      # 0xfe31
callq 0x2200
movq 0x1117c(%rip), %rdi     # 0x1f1d0
callq 0x21c0
movl %eax, 0x7c1d(%rip)      # 0x15c7c
cmpl $0x0, 0x7c16(%rip)      # 0x15c7c
jge 0xe097
callq 0xe160
movl 0x7c09(%rip), %esi      # 0x15c7c
leaq 0x1dce(%rip), %rdi      # 0xfe48
movb $0x0, %al
callq 0xd640
movl $0x4, 0x1113d(%rip)     # 0x1f1c8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe151
movq 0x11132(%rip), %rdi     # 0x1f1d0
movl 0x7bd4(%rip), %esi      # 0x15c78
movl $0x80, %edx
xorl %ecx, %ecx
callq 0x23c0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xe0e2
callq 0xe160
movl -0x1c(%rbp), %esi
leaq 0x1da5(%rip), %rdi      # 0xfe6d
movb $0x0, %al
callq 0xd640
movl $0x5, 0x110ef(%rip)     # 0x1f1c8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe151
movq -0x10(%rbp), %rax
leaq 0xf3(%rip), %rcx        # 0xe1e0
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
leaq 0x145(%rip), %rcx       # 0xe240
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
leaq 0x196(%rip), %rcx       # 0xe2a0
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
leaq 0x1e7(%rip), %rcx       # 0xe300
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
leaq 0x238(%rip), %rcx       # 0xe360
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
leaq 0x289(%rip), %rcx       # 0xe3c0
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
leaq 0x2da(%rip), %rcx       # 0xe420
movq %rcx, 0x30(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)