// File: /workspace/github_c_makefile_star2_O1/sachinites[P]CommandParser/parser.c
// Function: command_parser
void
command_parser(void){

    bool is_repeat_cmd;
    CMD_PARSE_STATUS status = UNKNOWN;

    printf("run - \'show help\' cmd to learn more");
    place_console(1);
    memset(&command_code_tlv, 0, sizeof(tlv_struct_t));

    command_code_tlv.leaf_type = INT;
    strncpy(command_code_tlv.leaf_id, "CMDCODE", LEAF_ID_SIZE);
    command_code_tlv.leaf_id[LEAF_ID_SIZE -1] = '\0';
    memset(cons_input_buffer, 0, CONS_INPUT_BUFFER_SIZE);

    while(1){

        is_repeat_cmd = false;

        if((fgets((char *)cons_input_buffer, sizeof(cons_input_buffer)-1, stdin) == NULL)){
            printf("error in reading from stdin\n");
            exit(EXIT_SUCCESS);
        }
    
        /*IF only enter is hit*/ 
        if(strlen(cons_input_buffer) == 1){
            cons_input_buffer[0]= '\0';
            place_console(0);
            continue; 
        }

        cons_input_buffer[strlen(cons_input_buffer) - 1] = '\0';
         
        status = parse_input_cmd(cons_input_buffer, strlen(cons_input_buffer), &is_repeat_cmd);

        if( is_repeat_cmd ) {
            memset(cons_input_buffer, 0, CONS_INPUT_BUFFER_SIZE);
            place_console(1);
            continue;
        }

        if(status == COMPLETE && cmd_recording_enabled) {
            record_command(CMD_HIST_RECORD_FILE,
						   cons_input_buffer,
						   strlen(cons_input_buffer));
		}

		cmd_recording_enabled = true;

        memset(last_command_input_buffer, 0, CONS_INPUT_BUFFER_SIZE);
        memcpy(last_command_input_buffer, cons_input_buffer, strlen(cons_input_buffer));
        last_command_input_buffer[strlen(last_command_input_buffer)] = '\0';

        memset(cons_input_buffer, 0, CONS_INPUT_BUFFER_SIZE);

        place_console(1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x48ab(%rip), %rdi      # 0x8ad0
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x10e0
movl $0xa, %edi
callq 0x1040
leaq 0x47b2(%rip), %rdi      # 0x89f1
leaq 0xcbba(%rip), %rsi      # 0x10e00
xorl %eax, %eax
callq 0x10e0
xorps %xmm0, %xmm0
movups %xmm0, 0xe409(%rip)     # 0x12660
movups %xmm0, 0xe412(%rip)     # 0x12670
movups %xmm0, 0xe3eb(%rip)     # 0x12650
movups %xmm0, 0xe414(%rip)     # 0x12680
movups %xmm0, 0xe41d(%rip)     # 0x12690
movups %xmm0, 0xe426(%rip)     # 0x126a0
movl $0x0, 0xe42c(%rip)      # 0x126b0
movups 0x4755(%rip), %xmm0     # 0x89e0
movups %xmm0, 0xe3d2(%rip)     # 0x12664
movups 0x4737(%rip), %xmm0     # 0x89d0
movups %xmm0, 0xe3b4(%rip)     # 0x12654
movb %bpl, 0xe3cc(%rip)      # 0x12673
leaq 0xdba2(%rip), %rbx      # 0x11e50
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
movb %bpl, 0x7(%rsp)
movq 0x8d17(%rip), %r13      # 0xcfe0
movq (%r13), %rdx
movq %rbx, %rdi
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x1130
testq %rax, %rax
je 0x440b
leaq 0x4707(%rip), %r14      # 0x89f1
leaq 0xcb0f(%rip), %r15      # 0x10e00
leaq 0x7(%rsp), %r12
movq %rbx, %rdi
callq 0x10c0
cmpq $0x1, %rax
jne 0x4310
movb $0x0, 0xdb45(%rip)      # 0x11e50
jmp 0x43df
movb $0x0, -0x1(%rax,%rbx)
movq %rbx, %rdi
movq %r12, %rdx
callq 0x3673
cmpb $0x1, 0x7(%rsp)
jne 0x4345
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
movl $0xa, %edi
callq 0x1040
jmp 0x43df
movq %r14, %r15
movq %r13, %r14
movq %r12, %r13
testl %eax, %eax
jne 0x4374
cmpb $0x0, 0xe35b(%rip)      # 0x126b4
jne 0x4374
movq %rbx, %rdi
callq 0x10c0
leaq 0x478a(%rip), %rdi      # 0x8af4
movq %rbx, %rsi
movl %eax, %edx
callq 0x569f
xorl %r12d, %r12d
movb %r12b, 0xe336(%rip)     # 0x126b4
movl $0x800, %edx            # imm = 0x800
leaq 0xd276(%rip), %rbp      # 0x11600
movq %rbp, %rdi
xorl %esi, %esi
callq 0x1100
movq %rbx, %rdi
callq 0x10c0
movq %rbp, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1190
movq %rbp, %rdi
callq 0x10c0
movb %r12b, (%rax,%rbp)
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
movl $0xa, %edi
callq 0x1040
movq %r13, %r12
movq %r14, %r13
movq %r15, %r14
leaq 0xca21(%rip), %r15      # 0x10e00
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x10e0
movb $0x0, 0x7(%rsp)
movq (%r13), %rdx
movq %rbx, %rdi
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x1130
testq %rax, %rax
jne 0x42f6
leaq 0x48fc(%rip), %rdi      # 0x8d0e
callq 0x1080
xorl %edi, %edi
callq 0x1250
nop