// File: /workspace/github_c_makefile_star2_O3/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 0x3aa7
movq %rsi, %r13
testq %rsi, %rsi
je 0x3aa7
testq %r8, %r8
je 0x3aa7
movl %ecx, %ebx
cmpl $0x2, %ecx
jae 0x3aac
movq %rdx, %r14
cmpl $0x1, %ebx
setne %al
testq %rdx, %rdx
setne %cl
orb %al, %cl
je 0x3ab1
movq %rdi, %r15
movq %r8, (%rsp)
testl %ebx, %ebx
jne 0x39de
movq %r13, %rdi
callq 0x2120
movq %rax, %r14
movl $0x1, %edi
movl $0x20, %esi
callq 0x2220
testq %rax, %rax
je 0x3ab6
movq %rax, %r12
leaq 0x1(%r14), %rdi
callq 0x22c0
movq %rax, (%r12)
testq %rax, %rax
je 0x3abb
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
testl %ebx, %ebx
je 0x3a2c
movq %r14, %rdx
callq 0x2060
movb $0x0, (%rbp,%r14)
jmp 0x3a31
callq 0x2090
movl %r14d, 0x8(%r12)
movl %ebx, 0xc(%r12)
movq (%rsp), %rax
movq %rax, 0x10(%r12)
cmpq $0x0, (%r15)
je 0x3a54
movq 0x8(%r15), %rax
movq %r12, 0x18(%rax)
jmp 0x3a57
movq %r12, (%r15)
movq %r12, 0x8(%r15)
movl 0x10(%r15), %r9d
incl %r9d
movl %r9d, 0x10(%r15)
leaq 0x981b(%rip), %rax      # 0xd288
cmpl $0x2, 0x18(%rax)
jge 0x3a84
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x956d(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x4729(%rip), %rsi      # 0x81be
movq %rbp, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2260
jmp 0x3a73
callq 0x2539
callq 0x2514
callq 0x24ef
callq 0x24ca
callq 0x24a5