// File: /workspace/github_c_makefile_star2_O2/sachinites[P]CommandParser/clistd.c
// Function: show_history_callback
int
show_history_callback(param_t *param, ser_buff_t *b, op_mode enable_or_disable){
   
    unsigned int cmd_counter = 0;

    unsigned long cmd_offset[MAX_SAVED_CMDS];

    memset(&cmd_offset, 0, MAX_SAVED_CMDS * sizeof(unsigned long));
    FILE *f = fopen(CMD_HIST_RECORD_FILE, "r");
    
    if(!f){
        printf("Error : History file could not be read\n");
        return 0;
    }
   
   memset(file_cmsd_size, 0, FILE_CMD_SIZE_MAX);
  
   cmd_offset[cmd_counter++] = ftell(f);
   while(fgets(file_cmsd_size, FILE_CMD_SIZE_MAX, f) != NULL) {
       printf("%d. %s", cmd_counter - 1, file_cmsd_size);
       cmd_offset[cmd_counter++] = ftell(f);
       memset(file_cmsd_size, 0, FILE_CMD_SIZE_MAX);
   } 
 
    int cmd_choice;
    printf("Enter command no to trigger : ");
    scanf("%d", &cmd_choice);
    if(!(cmd_choice >= 0 && cmd_choice < cmd_counter)){
        printf("Invalid choice\n");
        fclose(f) ;
        return 0;
    }

    
   fseek(f, cmd_offset[cmd_choice], SEEK_SET);
   memset(file_cmsd_size, 0, FILE_CMD_SIZE_MAX);
   fgets(file_cmsd_size, FILE_CMD_SIZE_MAX, f);
   file_cmsd_size[FILE_CMD_SIZE_MAX -1] = '\0';

   printf("Command to be triggered : %s", file_cmsd_size); 
   parse_input_cmd(file_cmsd_size, strlen(file_cmsd_size), NULL);   

   fclose(f) ;
   return 0; 
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
leaq 0x10(%rsp), %rdi
movl $0xf0, %edx
xorl %esi, %esi
callq 0x1100
leaq 0x2b8a(%rip), %rdi      # 0x7ad8
leaq 0x2647(%rip), %rsi      # 0x759c
callq 0x1200
testq %rax, %rax
je 0x507a
movq %rax, %rbx
leaq 0xd073(%rip), %r14      # 0x11fe0
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x1100
movq %rbx, %rdi
callq 0x1170
movq %rax, 0x10(%rsp)
pushq $0x1
popq %r12
leaq 0x3159(%rip), %r15      # 0x80ed
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x1130
testq %rax, %rax
je 0x4fdf
leal -0x1(%r12), %esi
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10e0
movq %rbx, %rdi
callq 0x1170
movl %r12d, %ecx
incl %r12d
movq %rax, 0x10(%rsp,%rcx,8)
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x1100
jmp 0x4f94
leaq 0x310e(%rip), %rdi      # 0x80f4
xorl %eax, %eax
callq 0x10e0
leaq 0x2a6d(%rip), %rdi      # 0x7a61
leaq 0xc(%rsp), %r14
movq %r14, %rsi
xorl %eax, %eax
callq 0x1230
movl (%r14), %eax
testl %eax, %eax
setns %cl
cmpl %r12d, %eax
setb %dl
testb %dl, %cl
je 0x5088
movl %eax, %eax
movq 0x10(%rsp,%rax,8), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x11d0
leaq 0xcfb3(%rip), %r14      # 0x11fe0
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x1100
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x1130
movb $0x0, 0xd38c(%rip)      # 0x123df
leaq 0x30b9(%rip), %rdi      # 0x8113
movq %r14, %rsi
xorl %eax, %eax
callq 0x10e0
movq %r14, %rdi
callq 0x10c0
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x3348
jmp 0x5094
leaq 0x348b(%rip), %rdi      # 0x850c
callq 0x1080
jmp 0x509c
leaq 0x34a4(%rip), %rdi      # 0x8533
callq 0x1080
movq %rbx, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r14
popq %r15
retq