// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movl %ecx, 0x14(%rsp)
movq %r8, 0x8(%rsp)
xorl %eax, %eax
cmpq 0x28(%rsp), %rax
je 0x4227
xorl %eax, %eax
cmpq 0x20(%rsp), %rax
je 0x4227
xorl %eax, %eax
cmpq 0x8(%rsp), %rax
jne 0x424b
jmp 0x4229
movq 0xcdc8(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7e19(%rip), %rsi      # 0xc053
movb $0x0, %al
callq 0x2280
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2430
xorl %eax, %eax
cmpl 0x14(%rsp), %eax
je 0x4282
movl $0x1, %eax
cmpl 0x14(%rsp), %eax
je 0x4282
jmp 0x4260
movq 0xcd91(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7e19(%rip), %rsi      # 0xc08a
movb $0x0, %al
callq 0x2280
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2430
movl $0x1, %eax
cmpl 0x14(%rsp), %eax
jne 0x42b9
cmpq $0x0, 0x18(%rsp)
ja 0x42b9
jmp 0x4297
movq 0xcd5a(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7e21(%rip), %rsi      # 0xc0c9
movb $0x0, %al
callq 0x2280
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2430
xorl %eax, %eax
cmpl 0x14(%rsp), %eax
jne 0x42d0
movq 0x20(%rsp), %rdi
callq 0x2110
movq %rax, 0x18(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x2240
movq %rax, (%rsp)
xorl %eax, %eax
cmpq (%rsp), %rax
jne 0x430f
jmp 0x42ed
movq 0xcd04(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7e09(%rip), %rsi      # 0xc107
movb $0x0, %al
callq 0x2280
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2430
movq 0x18(%rsp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x22e0
movq %rax, %rcx
movq (%rsp), %rax
movq %rcx, (%rax)
movq (%rsp), %rcx
xorl %eax, %eax
cmpq (%rcx), %rax
jne 0x435a
jmp 0x4338
movq 0xccb9(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7df3(%rip), %rsi      # 0xc13c
movb $0x0, %al
callq 0x2280
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2430
xorl %eax, %eax
cmpl 0x14(%rsp), %eax
jne 0x4375
movq (%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x2090
jmp 0x439b
movq (%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x2060
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x18(%rsp), %rax
movl %eax, %ecx
movq (%rsp), %rax
movl %ecx, 0x8(%rax)
movl 0x14(%rsp), %ecx
movq (%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x8(%rsp), %rcx
movq (%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
xorl %eax, %eax
cmpq (%rcx), %rax
jne 0x43e8
movq (%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq (%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x4406
movq (%rsp), %rcx
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x18(%rax)
movq (%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
leaq 0xce7d(%rip), %rax      # 0x11298
cmpl $0x1, 0x18(%rax)
jle 0x4458
movq 0xcbd0(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq (%rsp), %rax
movq (%rax), %rdx
movq (%rsp), %rax
movl 0x8(%rax), %ecx
movq (%rsp), %rax
movl 0xc(%rax), %r8d
movq 0x28(%rsp), %rax
movl 0x10(%rax), %r9d
leaq 0x7d21(%rip), %rsi      # 0xc172
movb $0x0, %al
callq 0x2280
jmp 0x445a
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopl (%rax,%rax)