// File: /workspace/github_c_makefile_star2_O1/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 0x35ce(%rip), %rdi      # 0x8af4
leaq 0x306f(%rip), %rsi      # 0x859c
callq 0x11f0
testq %rax, %rax
je 0x566c
movq %rax, %rbx
leaq 0xda9b(%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 0x55d3
leaq 0x3b89(%rip), %r14      # 0x910c
leaq 0xda56(%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 0x558a
leaq 0x3b39(%rip), %rdi      # 0x9113
xorl %eax, %eax
callq 0x10e0
leaq 0x3492(%rip), %rdi      # 0x8a7a
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 0x567a
movq 0x10(%rsp,%rax,8), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x11c0
leaq 0xd9c1(%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, 0xdd9a(%rip)      # 0x133df
leaq 0x3ae6(%rip), %rdi      # 0x9132
movq %r14, %rsi
xorl %eax, %eax
callq 0x10e0
movq %r14, %rdi
callq 0x10c0
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x3673
jmp 0x5686
leaq 0x3eb5(%rip), %rdi      # 0x9528
callq 0x1080
jmp 0x568e
leaq 0x3ece(%rip), %rdi      # 0x954f
callq 0x1080
movq %rbx, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r14
popq %r15
retq