// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r12
movq %rsp, %r14
movq $0x0, (%r14)
movl $0x20, %esi
movq %r14, %rdx
callq 0x4a91
movq %rax, %rbx
movq (%r14), %rax
testq %rax, %rax
je 0x3703
cmpq $0x1, %rax
je 0x36a0
movq (%rbx), %rax
cmpb $0x64, (%rax)
jne 0x36a0
cmpb $0x6f, 0x1(%rax)
jne 0x36a0
xorl %eax, %eax
callq 0x1ca1
movq %rax, %r14
callq 0x1b3c
cmpq %rax, %r14
je 0x36a0
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x1ca1
movq %rax, %rdi
callq 0x2cb9
movq %rax, %r15
callq 0x1b64
cmpq %rax, %r15
je 0x3907
leaq 0x55e3(%rip), %rdi      # 0x8c79
callq 0x1080
jmp 0x38ca
movq (%rbx), %r15
movq %r15, %rdi
callq 0x10c0
leaq 0x4f7a(%rip), %rsi      # 0x862c
movq %r15, %rdi
movq %rax, %rdx
callq 0x1070
testl %eax, %eax
je 0x370e
leaq 0x4f84(%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 0x373e
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x1ca1
movq %rax, %rdi
callq 0x2e93
jmp 0x38ca
movl $0x5, %r14d
jmp 0x38f5
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 0x38ca
movb $0x1, (%r12)
jmp 0x38ca
movzbl (%r15), %eax
cmpl $0x72, %eax
je 0x3781
cmpl $0x63, %eax
jne 0x3843
cmpq $0x1, %r14
sete %al
cmpb $0x64, 0x1(%r15)
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3810
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x1ca1
movq %rax, %rdi
callq 0x2dd0
jmp 0x38ca
cmpb $0x75, 0x1(%r15)
jne 0x3843
cmpb $0x6e, 0x2(%r15)
jne 0x3843
movq 0x8(%rbx), %rax
cmpb $0x75, (%rax)
jne 0x3843
cmpb $0x74, 0x1(%rax)
sete %al
cmpq $0x4, %r14
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3843
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x1180
movq %rax, %r14
movq 0x10(%rbx), %rbx
movq %rbx, %rdi
callq 0x10c0
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1060
movq %rbx, %rdi
callq 0x10c0
movb $0x0, 0x10(%rsp,%rax)
movzwl %r14w, %esi
movq %r15, %rdi
callq 0x5989
jmp 0x38b7
cmpb $0x6c, 0x1(%r15)
jne 0x3843
cmpq $0x1, %r14
sete %al
cmpb $0x73, 0x2(%r15)
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3843
xorl %r14d, %r14d
xorl %edi, %edi
xorl %esi, %esi
movl $0x3, %edx
callq 0x55e3
jmp 0x38ca
leaq 0x4cc9(%rip), %rsi      # 0x8513
movl $0x6, %edx
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
jne 0x38bc
movq 0x8(%rbx), %rdi
leaq 0x4cc0(%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 0x38bc
movq 0x10(%rbx), %rbx
movq %rbx, %rdi
callq 0x10c0
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1060
movq %rbx, %rdi
callq 0x10c0
movb $0x0, 0x10(%rsp,%rax)
movq %r14, %rdi
callq 0x3f6b
xorl %r14d, %r14d
jmp 0x38ca
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39ce
movl %eax, %r14d
movl $0x10, %edi
callq 0x49f1
xorl %eax, %eax
callq 0x1ca9
leaq 0xbb7e(%rip), %rcx      # 0xf460
movq (%rcx), %rdi
testl %eax, %eax
je 0x38f0
callq 0x43de
jmp 0x38f5
callq 0x49b2
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
xorl %eax, %eax
callq 0x1ca1
movq %rax, %r15
callq 0x1b44
movq %rax, %rdi
callq 0x1c74
leaq 0xbb3b(%rip), %r12      # 0xf460
movq (%r12), %rdi
callq 0x49b2
addq $0x8, %rbx
movq (%rsp), %rsi
decq %rsi
movq %rbx, %rdi
callq 0x39ce
movl %eax, %r14d
xorl %eax, %eax
callq 0x1ca1
movq %rax, %rbx
callq 0x1b44
cmpq %rax, %rbx
je 0x3997
xorl %eax, %eax
callq 0x1ca1
movq %rax, %rdi
callq 0x2cb9
movq %rax, %rbx
callq 0x1b64
cmpq %rax, %rbx
jne 0x38ca
leaq 0x4982(%rip), %rdi      # 0x8301
leaq 0x5d5d(%rip), %rsi      # 0x96e3
leaq 0x50c6(%rip), %rcx      # 0x8a53
movl $0x14e, %edx            # imm = 0x14E
callq 0x10f0
movq %r15, %rdi
callq 0x1c74
movq (%r12), %rbx
callq 0x1b3c
movq %rax, %r15
xorl %eax, %eax
callq 0x1ca1
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3124
movq (%r12), %rdi
callq 0x440a
jmp 0x38ca