// File: /workspace/github_c_makefile_star2_O3/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 0x49ab(%rip), %rdi      # 0x8a93
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x10e0
movl $0xa, %edi
callq 0x1040
leaq 0x48b5(%rip), %rdi      # 0x89b7
leaq 0xccf7(%rip), %rsi      # 0x10e00
xorl %eax, %eax
callq 0x10e0
xorps %xmm0, %xmm0
movups %xmm0, 0xe556(%rip)     # 0x12670
movups %xmm0, 0xe53f(%rip)     # 0x12660
movups %xmm0, 0xe528(%rip)     # 0x12650
movups %xmm0, 0xe551(%rip)     # 0x12680
movups %xmm0, 0xe55a(%rip)     # 0x12690
movups %xmm0, 0xe563(%rip)     # 0x126a0
movl $0x0, 0xe569(%rip)      # 0x126b0
movups 0x4b8a(%rip), %xmm0     # 0x8cd8
movups %xmm0, 0xe50e(%rip)     # 0x12663
movups 0x4b6d(%rip), %xmm0     # 0x8cc9
movups %xmm0, 0xe4f1(%rip)     # 0x12654
movb %bpl, 0xe509(%rip)      # 0x12673
leaq 0xdcdf(%rip), %rbx      # 0x11e50
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
movb %bpl, 0x7(%rsp)
movq 0x8e54(%rip), %r13      # 0xcfe0
movq (%r13), %rdx
movq %rbx, %rdi
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x1130
testq %rax, %rax
je 0x42ce
leaq 0x480a(%rip), %r14      # 0x89b7
leaq 0xcc4c(%rip), %r15      # 0x10e00
leaq 0x7(%rsp), %r12
movq %rbx, %rdi
callq 0x10c0
cmpq $0x1, %rax
jne 0x41d3
movb $0x0, 0xdc82(%rip)      # 0x11e50
jmp 0x42a2
movb $0x0, -0x1(%rax,%rbx)
movq %rbx, %rdi
movq %r12, %rdx
callq 0x360d
cmpb $0x1, 0x7(%rsp)
jne 0x4208
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
movl $0xa, %edi
callq 0x1040
jmp 0x42a2
movq %r14, %r15
movq %r13, %r14
movq %r12, %r13
testl %eax, %eax
jne 0x4237
cmpb $0x0, 0xe498(%rip)      # 0x126b4
jne 0x4237
movq %rbx, %rdi
callq 0x10c0
leaq 0x488a(%rip), %rdi      # 0x8ab7
movq %rbx, %rsi
movl %eax, %edx
callq 0x5557
xorl %r12d, %r12d
movb %r12b, 0xe473(%rip)     # 0x126b4
movl $0x800, %edx            # imm = 0x800
leaq 0xd3b3(%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 0xcb5e(%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 0x41b9
leaq 0x49d8(%rip), %rdi      # 0x8cad
callq 0x1080
xorl %edi, %edi
callq 0x1250
nopl (%rax)