// File: /workspace/github_c_makefile_star2_O3/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 0x36d9(%rip), %rdi      # 0x8ab7
leaq 0x31b7(%rip), %rsi      # 0x859c
callq 0x11f0
testq %rax, %rax
je 0x5524
movq %rax, %rbx
leaq 0xdbe3(%rip), %r14      # 0x12fe0
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x1100
movq %rbx, %rdi
callq 0x1170
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x1130
movl $0x1, %r12d
testq %rax, %rax
je 0x548b
leaq 0x3c91(%rip), %r14      # 0x90cc
leaq 0xdb9e(%rip), %r15      # 0x12fe0
leal -0x1(%r12), %esi
movq %r14, %rdi
movq %r15, %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 %r15, %rdi
xorl %esi, %esi
callq 0x1100
movq %r15, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x1130
testq %rax, %rax
jne 0x5442
leaq 0x3c41(%rip), %rdi      # 0x90d3
xorl %eax, %eax
callq 0x10e0
leaq 0x35a0(%rip), %rdi      # 0x8a40
leaq 0xc(%rsp), %r14
movq %r14, %rsi
xorl %eax, %eax
callq 0x1220
movl (%r14), %eax
testl %eax, %eax
setns %cl
cmpl %r12d, %eax
setb %dl
testb %dl, %cl
je 0x5532
movq 0x10(%rsp,%rax,8), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x11c0
leaq 0xdb09(%rip), %r14      # 0x12fe0
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, 0xdee2(%rip)      # 0x133df
leaq 0x3bee(%rip), %rdi      # 0x90f2
movq %r14, %rsi
xorl %eax, %eax
callq 0x10e0
movq %r14, %rdi
callq 0x10c0
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x360d
jmp 0x553e
leaq 0x3fc0(%rip), %rdi      # 0x94eb
callq 0x1080
jmp 0x5546
leaq 0x3fd9(%rip), %rdi      # 0x9512
callq 0x1080
movq %rbx, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r14
popq %r15
retq