// File: /workspace/github_c_makefile_star2_O3/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
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movaps %xmm0, 0xe9f7(%rip)     # 0x11e00
movaps %xmm0, 0xea00(%rip)     # 0x11e10
movaps %xmm0, 0xea09(%rip)     # 0x11e20
movaps %xmm0, 0xea12(%rip)     # 0x11e30
movaps %xmm0, 0xea1b(%rip)     # 0x11e40
movq (%rdi), %r12
movq $0x0, 0x8(%rsp)
testq %r12, %r12
je 0x34f7
movq %rsi, %r15
movq %rdi, %r14
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
xorl %ebx, %ebx
cmpl $0x1, (%r12)
jne 0x3457
movl %ebx, 0x10(%rsp)
jmp 0x34b0
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 0x34b0
movq %rbp, %rdi
callq 0x10c0
cmpl %eax, %r13d
je 0x350c
movq 0x8(%rsp), %rdx
movslq %edx, %rax
leaq 0xe967(%rip), %rcx      # 0x11e00
movq %r12, (%rcx,%rax,8)
movq %rdx, %rax
cmpl $0x9, %eax
jge 0x35ee
incl %eax
movq %rax, 0x8(%rsp)
cmpq $0xe, %rbx
ja 0x34c3
movq 0x8(%r14,%rbx,8), %r12
incq %rbx
testq %r12, %r12
jne 0x344a
movl 0x10(%rsp), %edx
testl %edx, %edx
setns %al
movq 0x8(%rsp), %rbx
testl %ebx, %ebx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x34e5
movl %edx, %eax
movq (%r14,%rax,8), %r12
jmp 0x34fa
testl %ebx, %ebx
je 0x34f7
cmpl $0x1, %ebx
jne 0x3515
movq 0xe90b(%rip), %r12      # 0x11e00
jmp 0x34fa
xorl %r12d, %r12d
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, 0xe8ed(%rip)      # 0x11e00
jmp 0x34fa
leaq 0x54f3(%rip), %rdi      # 0x8a0f
movl %ebx, %esi
xorl %eax, %eax
callq 0x10e0
testl %ebx, %ebx
jle 0x355f
movl 0x8(%rsp), %ebx
leaq 0x54ef(%rip), %r14      # 0x8a23
leaq 0xe8c5(%rip), %r12      # 0x11e00
xorl %r15d, %r15d
movq (%r12), %rax
movq 0x8(%rax), %rdx
movq %r14, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x10e0
incq %r15
addq $0x8, %r12
cmpq %r15, %rbx
jne 0x353e
movq 0x8(%rsp), %rbx
leal -0x1(%rbx), %esi
leaq 0x54bf(%rip), %rdi      # 0x8a2d
xorl %eax, %eax
callq 0x10e0
leaq 0x54c4(%rip), %rdi      # 0x8a40
leaq 0x14(%rsp), %rsi
xorl %eax, %eax
callq 0x1220
movq 0x9a51(%rip), %rax      # 0xcfe0
movq (%rax), %rdx
leaq 0xe8b7(%rip), %rdi      # 0x11e50
movl $0x7ff, %esi            # imm = 0x7FF
callq 0x1130
testq %rax, %rax
jne 0x35b4
leaq 0x56fe(%rip), %rdi      # 0x8cad
callq 0x1080
movl 0x14(%rsp), %eax
testl %eax, %eax
setns %cl
cmpl %ebx, %eax
setl %dl
testb %dl, %cl
je 0x35d8
movl %eax, %eax
leaq 0xe831(%rip), %rcx      # 0x11e00
movq (%rcx,%rax,8), %r12
jmp 0x34fa
leaq 0x5464(%rip), %rdi      # 0x8a43
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x10e0
jmp 0x34fa
leaq 0x53c8(%rip), %rdi      # 0x89bd
leaq 0x60e7(%rip), %rsi      # 0x96e3
leaq 0x53d5(%rip), %rcx      # 0x89d8
movl $0x57, %edx
callq 0x10f0