// File: /workspace/github_c_makefile_star2_O2/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 0x325d
movq %rsi, %r13
testq %rsi, %rsi
je 0x325d
testq %r8, %r8
je 0x325d
movl %ecx, %ebx
cmpl $0x2, %ecx
jae 0x3272
movq %rdx, %r14
cmpl $0x1, %ebx
setne %al
testq %rdx, %rdx
setne %cl
orb %al, %cl
je 0x3287
movq %rdi, %r15
movq %r8, (%rsp)
testl %ebx, %ebx
jne 0x3198
movq %r13, %rdi
callq 0x2120
movq %rax, %r14
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x2220
testq %rax, %rax
je 0x329c
movq %rax, %r12
leaq 0x1(%r14), %rdi
callq 0x22c0
movq %rax, (%r12)
testq %rax, %rax
je 0x32b1
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
testl %ebx, %ebx
je 0x31e2
movq %r14, %rdx
callq 0x2060
movb $0x0, (%rbp,%r14)
jmp 0x31e7
callq 0x2090
movl %r14d, 0x8(%r12)
movl %ebx, 0xc(%r12)
movq (%rsp), %rax
movq %rax, 0x10(%r12)
cmpq $0x0, (%r15)
je 0x320a
movq 0x8(%r15), %rax
movq %r12, 0x18(%rax)
jmp 0x320d
movq %r12, (%r15)
movq %r12, 0x8(%r15)
movl 0x10(%r15), %r9d
incl %r9d
movl %r9d, 0x10(%r15)
leaq 0xa065(%rip), %rax      # 0xd288
cmpl $0x2, 0x18(%rax)
jge 0x323a
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9db7(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x4f27(%rip), %rsi      # 0x8172
movq %rbp, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2260
jmp 0x3229
movq 0x9d94(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4de5(%rip), %rdi      # 0x8053
pushq $0x36
jmp 0x32c4
movq 0x9d7f(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4e07(%rip), %rdi      # 0x808a
pushq $0x3e
jmp 0x32c4
movq 0x9d6a(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4e31(%rip), %rdi      # 0x80c9
pushq $0x3d
jmp 0x32c4
movq 0x9d55(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4e5a(%rip), %rdi      # 0x8107
pushq $0x34
jmp 0x32c4
movq 0x9d40(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4e7a(%rip), %rdi      # 0x813c
pushq $0x35
popq %rsi
pushq $0x1
popq %rdx
callq 0x2420
pushq $-0x1
popq %rdi
callq 0x2410