// File: /workspace/github_c_makefile_star2_O1/zuocheng-liu[P]ae-memcached/src/command.c
// Function: command_service_register_handler
int32_t command_service_register_handler(
        command_service_ptr service, 
        char *cmd, 
        size_t cmd_len, 
        command_type cmd_type, 
        handler_t handler) {
    
    command_info_ptr command;
    if (NULL == service || NULL == cmd || NULL == handler) {
        LOG_FATAL("FATAL command_service_register_handler params illegal\n");
        return -1;
    }
    if (FULL_MATCH != cmd_type && FIXED_PREFIX != cmd_type) {
        LOG_FATAL("FATAL command_service_register_handler param cmd type illegal\n");
        return -1;
    }
    if (FIXED_PREFIX == cmd_type && cmd_len <= 0 ) {
        LOG_FATAL("FATAL command_service_register_handler param cmd len illegal\n");
        return -1;
    }
    if (FULL_MATCH == cmd_type) {
        cmd_len = strlen(cmd);
    }
    command = (command_info_ptr)calloc(1, sizeof(command_info));
    if (NULL == command) {
        LOG_FATAL("FATAL command_service_register_handler calloc fail \n");
        return -1;
    }
    
    command->cmd = (char *)malloc((cmd_len + 1) * sizeof(char));
    if (NULL == command->cmd) {
        LOG_FATAL("FATAL command_service_register_handler malloc fail. \n");
        return -1;
    }
    if (FULL_MATCH == cmd_type) {
        strcpy(command->cmd, cmd);
    } else { 
        /* FIXED_PREFIX == cmd_type */
        strncpy(command->cmd, cmd, cmd_len);
        command->cmd[cmd_len] = '\0';
    } 
    command->cmd_len = cmd_len;
    command->type = cmd_type;
    command->handler = handler;
    if (NULL == service->command_list) {
        service->command_list = command;
        service->end_command = command;
    } else {
        service->end_command->next = command;
        service->end_command = command;
    }
    ++ service->command_count;
    LOG_DEBUG_F4("Add command %s %d %d %d\n", command->cmd, command->cmd_len, command->type, service->command_count);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x3a8c
movq %rsi, %r13
testq %rsi, %rsi
je 0x3a8c
movq %r8, %r12
testq %r8, %r8
je 0x3a8c
movl %ecx, %ebx
cmpl $0x2, %ecx
jae 0x3a91
movq %rdx, %r14
cmpl $0x1, %ebx
setne %al
testq %rdx, %rdx
setne %cl
orb %al, %cl
je 0x3a96
movq %rdi, %r15
testl %ebx, %ebx
jne 0x39bd
movq %r13, %rdi
callq 0x2120
movq %rax, %r14
movq %r12, (%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x2220
testq %rax, %rax
je 0x3a9b
movq %rax, %rbp
leaq 0x1(%r14), %rdi
callq 0x22c0
movq %rax, (%rbp)
testq %rax, %rax
je 0x3aa0
movq %rax, %r12
testl %ebx, %ebx
je 0x3a0e
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2060
movb $0x0, (%r12,%r14)
jmp 0x3a19
movq %r12, %rdi
movq %r13, %rsi
callq 0x2090
movl %r14d, 0x8(%rbp)
movl %ebx, 0xc(%rbp)
movq (%rsp), %rax
movq %rax, 0x10(%rbp)
cmpq $0x0, (%r15)
je 0x3a38
movq 0x8(%r15), %rax
movq %rbp, 0x18(%rax)
jmp 0x3a3b
movq %rbp, (%r15)
movq %rbp, 0x8(%r15)
movl 0x10(%r15), %r9d
incl %r9d
movl %r9d, 0x10(%r15)
leaq 0x9837(%rip), %rax      # 0xd288
cmpl $0x2, 0x18(%rax)
jge 0x3a68
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9589(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movq (%rbp), %rdx
leaq 0x4741(%rip), %rsi      # 0x81be
movl %r14d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2260
jmp 0x3a57
callq 0x2539
callq 0x2514
callq 0x24ef
callq 0x24ca
callq 0x24a5