// File: /workspace/github_c_makefile_star2_O0/sachinites[P]CommandParser/parser.c
// Function: find_matching_param
param_t*
find_matching_param(param_t **options, const char *cmd_name){
    
    int i = 0, leaf_index = -1,
        j = 0,
        choice = -1;

    bool ex_match = false;

    memset(array_of_possibilities, 0, POSSIBILITY_ARRAY_SIZE * sizeof(param_t *));

    for(; options[i] && i <= CHILDREN_END_INDEX; i++){

        if(IS_PARAM_LEAF(options[i])){
            leaf_index = i;
            continue;
        }

        if (is_cmd_string_match(options[i], cmd_name, &ex_match) == 0) {

            if (ex_match) {
                array_of_possibilities[ 0 ] = options[i];
                j = 1;
                break;
            }
            array_of_possibilities[ j++ ] = options[i];
            assert (j < POSSIBILITY_ARRAY_SIZE);
            continue;
        }
    }

    if(leaf_index >= 0 && j == 0)
        return options[leaf_index];

    if( j == 0)
        return NULL;

    if(j == 1)
        return array_of_possibilities[0];

    /* More than one param matched*/
    printf("%d possibilities :\n", j);
    for(i = 0; i < j; i++)
        printf("%-2d. %s\n", i, GET_CMD_NAME(array_of_possibilities[i]));

    printf("Choice [0-%d] : ? ", j-1);
    scanf("%d", &choice);

    /*  Read \n and discard */
    if((fgets((char *)cons_input_buffer, sizeof(cons_input_buffer)-1, stdin) == NULL)){
        printf("error in reading from stdin\n");
    }

    if(choice < 0 || choice > (j-1)){
        printf("\nInvalid Choice");
        return NULL;
    }

    return array_of_possibilities[choice];   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x24(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movb $0x0, -0x29(%rbp)
leaq 0xfe89(%rip), %rdi      # 0x13de0
xorl %esi, %esi
movl $0x50, %edx
callq 0x10d0
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
xorl %eax, %eax
cmpq $0x0, (%rcx,%rdx,8)
movb %al, -0x2a(%rbp)
je 0x3f81
cmpl $0xf, -0x1c(%rbp)
setle %al
movb %al, -0x2a(%rbp)
movb -0x2a(%rbp), %al
testb $0x1, %al
jne 0x3f8d
jmp 0x4047
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x1, (%rax)
jne 0x3fa9
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x4039
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x18(%rbp), %rsi
leaq -0x29(%rbp), %rdx
callq 0x4180
cmpl $0x0, %eax
jne 0x4037
testb $0x1, -0x29(%rbp)
je 0x3fe9
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0xfe00(%rip)      # 0x13de0
movl $0x1, -0x24(%rbp)
jmp 0x4047
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl -0x24(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x24(%rbp)
movslq %eax, %rcx
leaq 0xfdd6(%rip), %rax      # 0x13de0
movq %rdx, (%rax,%rcx,8)
cmpl $0xa, -0x24(%rbp)
jge 0x4016
jmp 0x4035
leaq 0x6a2d(%rip), %rdi      # 0xaa4a
leaq 0x7715(%rip), %rsi      # 0xb739
movl $0x57, %edx
leaq 0x6a35(%rip), %rcx      # 0xaa65
callq 0x10c0
jmp 0x4039
jmp 0x4039
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3f63
cmpl $0x0, -0x20(%rbp)
jl 0x4068
cmpl $0x0, -0x24(%rbp)
jne 0x4068
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x8(%rbp)
jmp 0x4173
cmpl $0x0, -0x24(%rbp)
jne 0x407b
movq $0x0, -0x8(%rbp)
jmp 0x4173
cmpl $0x1, -0x24(%rbp)
jne 0x4091
movq 0xfd58(%rip), %rax      # 0x13de0
movq %rax, -0x8(%rbp)
jmp 0x4173
movl -0x24(%rbp), %esi
leaq 0x6a01(%rip), %rdi      # 0xaa9c
movb $0x0, %al
callq 0x10b0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x40e0
movl -0x1c(%rbp), %esi
movslq -0x1c(%rbp), %rcx
leaq 0xfd21(%rip), %rax      # 0x13de0
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdx
leaq 0x69e2(%rip), %rdi      # 0xaab0
movb $0x0, %al
callq 0x10b0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x40a9
movl -0x24(%rbp), %esi
subl $0x1, %esi
leaq 0x69cd(%rip), %rdi      # 0xaaba
movb $0x0, %al
callq 0x10b0
leaq 0x69d2(%rip), %rdi      # 0xaacd
leaq -0x28(%rbp), %rsi
movb $0x0, %al
callq 0x11e0
movq 0xaed3(%rip), %rax      # 0xefe0
movq (%rax), %rdx
leaq 0xfd19(%rip), %rdi      # 0x13e30
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x10f0
cmpq $0x0, %rax
jne 0x4135
leaq 0x69a2(%rip), %rdi      # 0xaad0
movb $0x0, %al
callq 0x10b0
cmpl $0x0, -0x28(%rbp)
jl 0x4148
movl -0x28(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x4160
leaq 0x699e(%rip), %rdi      # 0xaaed
movb $0x0, %al
callq 0x10b0
movq $0x0, -0x8(%rbp)
jmp 0x4173
movslq -0x28(%rbp), %rcx
leaq 0xfc75(%rip), %rax      # 0x13de0
movq (%rax,%rcx,8), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)