// File: /workspace/github_c_makefile_star2_O2/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 0x3d06(%rip), %rdi      # 0x7ab4
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x10e0
pushq $0x1
popq %rdi
callq 0x30f0
xorps %xmm0, %xmm0
movups %xmm0, 0xd897(%rip)     # 0x11660
movups %xmm0, 0xd880(%rip)     # 0x11650
movups %xmm0, 0xd899(%rip)     # 0x11670
movups %xmm0, 0xd8c2(%rip)     # 0x116a0
movups %xmm0, 0xd8ab(%rip)     # 0x11690
movups %xmm0, 0xd894(%rip)     # 0x11680
andl $0x0, 0xd8bd(%rip)      # 0x116b0
movups 0x3ef0(%rip), %xmm0     # 0x7cea
movups %xmm0, 0xd853(%rip)     # 0x11654
movups 0x3ef1(%rip), %xmm0     # 0x7cf9
movups %xmm0, 0xd854(%rip)     # 0x11663
movb $0x0, 0xd85d(%rip)      # 0x11673
leaq 0xd033(%rip), %rbx      # 0x10e50
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
movq 0x81ad(%rip), %r13      # 0xbfe0
leaq 0x7(%rsp), %r14
leaq 0x3c99(%rip), %r15      # 0x7ad8
leaq 0xc7ba(%rip), %r12      # 0x10600
movb $0x0, 0x7(%rsp)
movq (%r13), %rdx
movq %rbx, %rdi
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x1130
testq %rax, %rax
je 0x3f10
movq %rbx, %rdi
callq 0x10c0
cmpq $0x1, %rax
jne 0x3e81
movb $0x0, 0xcfd6(%rip)      # 0x10e50
xorl %eax, %eax
jmp 0x3f03
movb $0x0, -0x1(%rax,%rbx)
movq %rbx, %rdi
movq %r14, %rdx
callq 0x3348
cmpb $0x1, 0x7(%rsp)
je 0x3ef2
testl %eax, %eax
jne 0x3eba
cmpb $0x0, 0xd811(%rip)      # 0x116b4
jne 0x3eba
movq %rbx, %rdi
callq 0x10c0
movq %r15, %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x50ad
movb %bpl, 0xd7f3(%rip)      # 0x116b4
movl $0x800, %edx            # imm = 0x800
movq %r12, %rdi
xorl %esi, %esi
callq 0x1100
movq %rbx, %rdi
callq 0x10c0
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1190
movq %r12, %rdi
callq 0x10c0
movb %bpl, (%rax,%r12)
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
movb $0x1, %al
movzbl %al, %edi
callq 0x30f0
jmp 0x3e46
leaq 0x3db7(%rip), %rdi      # 0x7cce
callq 0x1080
xorl %edi, %edi
callq 0x1260
nop