// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x7, -0x8(%rbp)
leaq 0x5abf(%rip), %rdi      # 0xab75
movb $0x0, %al
callq 0x10b0
movl $0x1, %edi
callq 0x3ed0
leaq 0xf562(%rip), %rdi      # 0x14630
xorl %esi, %esi
movl $0x64, %edx
callq 0x10d0
movl $0x0, 0xf54c(%rip)      # 0x14630
leaq 0xf545(%rip), %rdi      # 0x14630
addq $0x4, %rdi
leaq 0x5aa3(%rip), %rsi      # 0xab99
movl $0x20, %edx
callq 0x1050
movb $0x0, 0xf54c(%rip)      # 0x14653
leaq 0xed22(%rip), %rdi      # 0x13e30
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x10d0
movb $0x0, -0x1(%rbp)
movq 0x9ebb(%rip), %rax      # 0xefe0
movq (%rax), %rdx
leaq 0xed01(%rip), %rdi      # 0x13e30
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x10f0
cmpq $0x0, %rax
jne 0x5154
leaq 0x598a(%rip), %rdi      # 0xaad0
movb $0x0, %al
callq 0x10b0
xorl %edi, %edi
callq 0x1210
leaq 0xecd5(%rip), %rdi      # 0x13e30
callq 0x1090
cmpq $0x1, %rax
jne 0x5176
movb $0x0, 0xecc3(%rip)      # 0x13e30
xorl %edi, %edi
callq 0x3ed0
jmp 0x511a
leaq 0xecb3(%rip), %rdi      # 0x13e30
callq 0x1090
movq %rax, %rcx
subq $0x1, %rcx
leaq 0xeca0(%rip), %rax      # 0x13e30
movb $0x0, (%rax,%rcx)
leaq 0xec95(%rip), %rdi      # 0x13e30
callq 0x1090
movl %eax, %esi
leaq 0xec87(%rip), %rdi      # 0x13e30
leaq -0x1(%rbp), %rdx
callq 0x41f0
movl %eax, -0x8(%rbp)
testb $0x1, -0x1(%rbp)
je 0x51dd
leaq 0xec6e(%rip), %rdi      # 0x13e30
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x10d0
movl $0x1, %edi
callq 0x3ed0
jmp 0x511a
cmpl $0x0, -0x8(%rbp)
jne 0x520d
testb $0x1, 0x9f56(%rip)      # 0xf140
je 0x520d
leaq 0xec3d(%rip), %rdi      # 0x13e30
callq 0x1090
movl %eax, %edx
leaq 0x59a0(%rip), %rdi      # 0xaba1
leaq 0xec28(%rip), %rsi      # 0x13e30
callq 0x7360
movb $0x1, 0x9f2c(%rip)      # 0xf140
leaq 0xe3c5(%rip), %rdi      # 0x135e0
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x10d0
leaq 0xec02(%rip), %rdi      # 0x13e30
callq 0x1090
movq %rax, %rdx
leaq 0xe3a3(%rip), %rdi      # 0x135e0
leaq 0xebec(%rip), %rsi      # 0x13e30
callq 0x1150
leaq 0xe390(%rip), %rdi      # 0x135e0
callq 0x1090
movq %rax, %rcx
leaq 0xe381(%rip), %rax      # 0x135e0
movb $0x0, (%rax,%rcx)
leaq 0xebc6(%rip), %rdi      # 0x13e30
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x10d0
movl $0x1, %edi
callq 0x3ed0
jmp 0x511a
nopw %cs:(%rax,%rax)