// File: /workspace/github_c_makefile_star2_O1/sachinites[P]CommandParser/parser.c
// Function: parse_input_cmd
CMD_PARSE_STATUS
parse_input_cmd(char *input, unsigned int len, bool *is_repeat_cmd){

    char** tokens = NULL;
    size_t token_cnt = 0;
    char file_name[128];
    CMD_PARSE_STATUS status = COMPLETE;
    
    tokens = tokenizer(input, ' ', &token_cnt);
    if(!token_cnt)
        return INCOMPLETE_COMMAND;

    if(token_cnt > 1 && 
            ((strncmp(tokens[0], DO, 2) == 0)) &&
            (get_cmd_tree_cursor() != libcli_get_root())) /*do commands are not allowed from root*/

    {
        if(IS_CURRENT_MODE_CONFIG()) /*Do commands are allowed only when user is operating in config mode*/
        {
            param_t *old_cursor_state = get_cmd_tree_cursor(), *new_cursor_state = NULL;
            set_cmd_tree_cursor(libcli_get_do_hook());/*It will also destroy the config mode serialize buffer*/

            /*There is a cross branch junp from config to Operational branch, hence reset the buffer*/
            reset_serialize_buffer(tlv_buff);
            status = build_tlv_buffer(&tokens[1], token_cnt-1);

            /*It might be possible that user may have switched the branch from within config branch*/
            new_cursor_state = get_cmd_tree_cursor();

            /*If new cursor is not same as do_hook, it means, 
             * user has entered into MODE in some operational branch*/

            if(new_cursor_state != libcli_get_do_hook()){
                if(IS_CURRENT_MODE_CONFIG()){
                    assert(0); /*Impossible case*/
                }
            }
            else{
                /*User is in the config mode only */
                set_cmd_tree_cursor(old_cursor_state);
                /*We need to rebuild the TLV buffer afresh*/
                build_cmd_tree_leaves_data(tlv_buff, libcli_get_root(), get_cmd_tree_cursor());
                mark_checkpoint_serialize_buffer(tlv_buff);
            }
        }
        else
            printf("Info : do is supported from within config mode only\n");
    }

    else if (strncmp (tokens[0], "repeat" , strlen(tokens[0])) == 0) {
        parser_process_repeat_cmd(token_cnt == 1 ? 0 : tokens[1]);
        if (is_repeat_cmd) *is_repeat_cmd = true;
    }   

    else if((strncmp(tokens[0], GOTO_ONE_LVL_UP_STRING, strlen(GOTO_ONE_LVL_UP_STRING)) == 0) && (token_cnt == 1))
        go_one_level_up_cmd_tree(get_cmd_tree_cursor());
    
    else if((strncmp(tokens[0], GOTO_TOP_STRING, strlen(GOTO_TOP_STRING)) == 0) && (token_cnt == 1))
        goto_top_of_cmd_tree(get_cmd_tree_cursor());

    
    else if((strncmp(tokens[0], CLEAR_SCR_STRING, strlen(CLEAR_SCR_STRING)) == 0) && (token_cnt == 1))
        clear_screen_handler(0, 0, MODE_UNKNOWN);

    else if (!strncmp(tokens[0], "run" , strlen("run"))  && 
	     !strncmp(tokens[1], "ut" , strlen("ut"))    &&
	     token_cnt == 4 ) {

        char *pend;
        long int tc_no = strtol(tokens[3], &pend, 10);
        strncpy(file_name, tokens[2], strlen(tokens[2]));
        file_name[strlen(tokens[2])] = '\0';
        run_test_case(file_name, tc_no);
    }
    
    else if ( !strncmp(tokens[0], "config" , strlen("config"))  &&
	      !strncmp(tokens[1], "load" , strlen("load"))      &&
	      token_cnt == 3 ) {

	    strncpy(file_name, tokens[2], strlen(tokens[2]));
	    file_name[strlen(tokens[2])] = '\0';
	    parse_file(file_name);
    }
    else 
        status = build_tlv_buffer(tokens, token_cnt); 

    re_init_tokens(MAX_CMD_TREE_DEPTH);

    if(is_user_in_cmd_mode())
        restore_checkpoint_serialize_buffer(tlv_buff);
    else
        reset_serialize_buffer(tlv_buff);

    return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rdx, %r12
movq %rsp, %r14
movq $0x0, (%r14)
movl $0x20, %esi
movq %r14, %rdx
callq 0x4bf1
movq %rax, %rbx
movq (%r14), %rax
testq %rax, %rax
je 0x3730
cmpq $0x1, %rax
je 0x36cd
movq (%rbx), %rdi
leaq 0x53d2(%rip), %rsi      # 0x8a8d
movl $0x2, %edx
callq 0x1070
testl %eax, %eax
je 0x37aa
movq (%rbx), %r15
movq %r15, %rdi
callq 0x10c0
leaq 0x4f4d(%rip), %rsi      # 0x862c
movq %r15, %rdi
movq %rax, %rdx
callq 0x1070
testl %eax, %eax
je 0x373b
leaq 0x4f57(%rip), %rsi      # 0x864c
movl $0x4, %edx
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
sete %al
movq (%rsp), %r14
cmpq $0x1, %r14
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x376b
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x1cb4
movq %rax, %rdi
callq 0x2ead
jmp 0x3a13
movl $0x5, %r14d
jmp 0x3a3e
callq 0x1b7c
movq 0x10(%rax), %rbx
callq 0x1b7c
xorl %r14d, %r14d
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq *%rbx
testq %r12, %r12
je 0x3a13
movb $0x1, (%r12)
jmp 0x3a13
cmpq $0x1, %r14
sete %bpl
leaq 0x4ee9(%rip), %rsi      # 0x8663
movl $0x2, %edx
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
sete %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x37f6
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x1cb4
movq %rax, %rdi
callq 0x2dea
jmp 0x3a13
xorl %eax, %eax
callq 0x1cb4
movq %rax, %r14
callq 0x1b3c
cmpq %rax, %r14
je 0x36cd
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x1cb4
movq %rax, %rdi
callq 0x2cd3
movq %rax, %r15
callq 0x1b64
cmpq %rax, %r15
je 0x3955
leaq 0x54ee(%rip), %rdi      # 0x8cda
callq 0x1080
jmp 0x3a13
cmpq $0x1, %r14
sete %bpl
leaq 0x4e36(%rip), %rsi      # 0x863b
movl $0x3, %edx
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
sete %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x3834
xorl %r14d, %r14d
xorl %edi, %edi
xorl %esi, %esi
movl $0x3, %edx
callq 0x572b
jmp 0x3a13
leaq 0x4d6e(%rip), %rsi      # 0x85a9
movl $0x3, %edx
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
jne 0x38c5
movq 0x8(%rbx), %rdi
leaq 0x4c6d(%rip), %rsi      # 0x84c4
movl $0x2, %edx
callq 0x1070
testl %eax, %eax
sete %al
cmpq $0x4, %r14
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x38c5
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x1180
movq %rax, %r14
movq 0x10(%rbx), %r15
movq %r15, %rdi
callq 0x10c0
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1060
movq 0x10(%rbx), %rdi
callq 0x10c0
movb $0x0, 0x10(%rsp,%rax)
movzwl %r14w, %esi
movq %r12, %rdi
callq 0x5ad9
jmp 0x393a
leaq 0x4c47(%rip), %rsi      # 0x8513
movl $0x6, %edx
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
jne 0x3942
movq 0x8(%rbx), %rdi
leaq 0x4c3e(%rip), %rsi      # 0x8526
movl $0x4, %edx
callq 0x1070
testl %eax, %eax
sete %al
cmpq $0x3, %r14
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3942
movq 0x10(%rbx), %r14
movq %r14, %rdi
callq 0x10c0
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1060
movq 0x10(%rbx), %rdi
callq 0x10c0
movb $0x0, 0x10(%rsp,%rax)
movq %r15, %rdi
callq 0x40a8
xorl %r14d, %r14d
jmp 0x3a13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3a51
movl %eax, %r14d
jmp 0x3a13
xorl %eax, %eax
callq 0x1cb4
movq %rax, %r15
callq 0x1b44
movq %rax, %rdi
callq 0x1c87
leaq 0xbaed(%rip), %r12      # 0xf460
movq (%r12), %rdi
callq 0x4b10
addq $0x8, %rbx
movq (%rsp), %rsi
decq %rsi
movq %rbx, %rdi
callq 0x3a51
movl %eax, %r14d
xorl %eax, %eax
callq 0x1cb4
movq %rax, %rbx
callq 0x1b44
cmpq %rax, %rbx
je 0x39e1
xorl %eax, %eax
callq 0x1cb4
movq %rax, %rdi
callq 0x2cd3
movq %rax, %rbx
callq 0x1b64
cmpq %rax, %rbx
jne 0x3a13
leaq 0x4938(%rip), %rdi      # 0x8301
leaq 0x5d53(%rip), %rsi      # 0x9723
leaq 0x50b9(%rip), %rcx      # 0x8a90
movl $0x14e, %edx            # imm = 0x14E
callq 0x10f0
movq %r15, %rdi
callq 0x1c87
movq (%r12), %rbx
callq 0x1b3c
movq %rax, %r15
xorl %eax, %eax
callq 0x1cb4
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x313e
movq (%r12), %rdi
callq 0x4557
movl $0x10, %edi
callq 0x4b51
xorl %eax, %eax
callq 0x1cbc
leaq 0xba35(%rip), %rcx      # 0xf460
movq (%rcx), %rdi
testl %eax, %eax
je 0x3a39
callq 0x452b
jmp 0x3a3e
callq 0x4b10
movl %r14d, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq