// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
orl $-0x1, 0x4(%rsp)
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0xdcbe(%rip)     # 0x10e00
movaps %xmm0, 0xdcc7(%rip)     # 0x10e10
movaps %xmm0, 0xdcd0(%rip)     # 0x10e20
movaps %xmm0, 0xdcd9(%rip)     # 0x10e30
movaps %xmm0, 0xdce2(%rip)     # 0x10e40
xorl %ebx, %ebx
pushq $-0x1
popq %rax
movl %eax, (%rsp)
leaq 0xdc93(%rip), %rax      # 0x10e00
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
cmpq $0xf, %rbx
ja 0x31f0
movq (%r14,%rbx,8), %r12
testq %r12, %r12
je 0x31f0
cmpl $0x1, (%r12)
jne 0x3196
movl %ebx, (%rsp)
jmp 0x31eb
movq %r15, %rdi
callq 0x10c0
movq %rax, %r13
movq 0x8(%r12), %rbp
movslq %r13d, %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1070
testl %eax, %eax
jne 0x31eb
movq %rbp, %rdi
callq 0x10c0
cmpl %eax, %r13d
je 0x3234
movq 0x8(%rsp), %rcx
movslq %ecx, %rax
leaq 0xdc2c(%rip), %rdx      # 0x10e00
movq %r12, (%rdx,%rax,8)
movq %rcx, %rax
cmpl $0x9, %eax
jge 0x332b
incl %eax
movq %rax, 0x8(%rsp)
incq %rbx
jmp 0x317b
movl (%rsp), %edx
testl %edx, %edx
setns %al
movq 0x8(%rsp), %r12
testl %r12d, %r12d
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3215
movl %edx, %eax
movq (%r14,%rax,8), %r12
jmp 0x3319
testl %r12d, %r12d
je 0x322c
cmpl $0x1, %r12d
jne 0x3240
movq 0xdbd9(%rip), %r12      # 0x10e00
jmp 0x3319
xorl %r12d, %r12d
jmp 0x3319
movq %r12, 0xdbc5(%rip)      # 0x10e00
jmp 0x3319
leaq 0x47e9(%rip), %rdi      # 0x7a30
movl %r12d, %esi
xorl %eax, %eax
callq 0x10e0
testl %r12d, %r12d
movl $0x0, %ebx
cmovgl %r12d, %ebx
leaq 0x47e0(%rip), %r14      # 0x7a44
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x3294
movq 0x10(%rsp), %r13
movq (%r13), %rax
movq 0x8(%rax), %rdx
movq %r14, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x10e0
incq %r15
addq $0x8, %r13
movq %r13, 0x10(%rsp)
jmp 0x3267
leal -0x1(%r12), %esi
leaq 0x47ae(%rip), %rdi      # 0x7a4e
xorl %eax, %eax
callq 0x10e0
leaq 0x47b3(%rip), %rdi      # 0x7a61
leaq 0x4(%rsp), %rsi
xorl %eax, %eax
callq 0x1230
movq 0x8d1f(%rip), %rax      # 0xbfe0
movq (%rax), %rdx
leaq 0xdb85(%rip), %rdi      # 0x10e50
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x1130
testq %rax, %rax
jne 0x32e6
leaq 0x49ed(%rip), %rdi      # 0x7cce
callq 0x1080
movl 0x4(%rsp), %eax
testl %eax, %eax
setns %cl
cmpl %r12d, %eax
setl %dl
testb %dl, %cl
je 0x3308
movl %eax, %eax
leaq 0xdafe(%rip), %rcx      # 0x10e00
movq (%rcx,%rax,8), %r12
jmp 0x3319
leaq 0x4755(%rip), %rdi      # 0x7a64
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x10e0
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x46ac(%rip), %rdi      # 0x79de
leaq 0x53aa(%rip), %rsi      # 0x86e3
leaq 0x46b9(%rip), %rcx      # 0x79f9
pushq $0x57
popq %rdx
callq 0x10f0