// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_complete.c
// Function: ce_complete_match
void ce_complete_match(CeComplete_t* complete, const char* match){
     if(complete->count == 0) return;
     if(strlen(match)){
          for(int64_t i = 0; i < complete->count; i++){
               const char* str = strstr(complete->elements[i].string, match);
               complete->elements[i].match = (str != NULL);

               // any options that are an identical match, override the current selection
               if(strcmp(match, complete->elements[i].string) == 0) complete->current = i;
          }
     }else{
          for(int64_t i = 0; i < complete->count; i++){
               complete->elements[i].match = true;
          }
     }

     // if our current no longer matches, find another that matches
     if(complete->current >= 0){
          if(!complete->elements[complete->current].match){
               bool found_match = false;

               for(int64_t i = complete->current + 1; i != complete->current; i++){
                    if(i >= complete->count) i = 0;
                    if(complete->elements[i].match){
                         complete->current = i;
                         found_match = true;
                         break;
                    }

                    if(i == 0 && complete->current == 0) break;
               }

               // if no matches, use invalid index
               if(!found_match) complete->current = -1;
          }
     }else{
          for(int64_t i = 0; i < complete->count; i++){
               if(complete->elements[i].match){
                    complete->current = i;
                    break;
               }
          }
     }

     if(complete->current >= 0){
          free(complete->current_match);
          complete->current_match = strdup(match);
     }
}

// Assembly:
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x18ff7
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r12
movq %rsi, (%rsp)
cmpb $0x0, (%rsi)
movq %rcx, 0x8(%rsp)
je 0x18f1e
pushq $0x10
popq %r13
xorl %ebp, %ebp
testq %rcx, %rcx
movl $0x0, %eax
cmovgq %rcx, %rax
movq %rax, 0x10(%rsp)
movq (%rsp), %rbx
cmpq %rbp, 0x10(%rsp)
je 0x18f3e
movq (%r12), %r14
movq -0x10(%r14,%r13), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0xd6f0
testq %rax, %rax
setne (%r14,%r13)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd390
testl %eax, %eax
jne 0x18f15
movq %rbp, 0x18(%r12)
incq %rbp
addq $0x18, %r13
jmp 0x18ede
xorl %eax, %eax
testq %rcx, %rcx
cmovgq %rcx, %rax
pushq $0x10
popq %rcx
subq $0x1, %rax
jb 0x18f3e
movq (%r12), %rdx
movb $0x1, (%rdx,%rcx)
addq $0x18, %rcx
jmp 0x18f2a
movq 0x18(%r12), %rax
testq %rax, %rax
js 0x18f98
movq (%r12), %rdx
imulq $0x18, %rax, %rcx
cmpb $0x0, 0x10(%rdx,%rcx)
movq (%rsp), %r14
movq 0x8(%rsp), %r9
jne 0x18fd2
xorl %esi, %esi
movq %rax, %rcx
movq %rcx, %rdi
incq %rdi
cmpq %rax, %rdi
je 0x18f90
cmpq %r9, %rdi
movq %rdi, %rcx
cmovgeq %rsi, %rcx
imulq $0x18, %rcx, %r8
cmpb $0x0, 0x10(%rdx,%r8)
jne 0x18fc5
testq %rax, %rax
jne 0x18f65
cmpq %r9, %rdi
jl 0x18f65
orq $-0x1, 0x18(%r12)
jmp 0x18fe9
xorl %ecx, %ecx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
cmovleq %rcx, %rdi
pushq $0x10
popq %rdx
movq (%rsp), %r14
cmpq %rcx, %rdi
je 0x18fcd
movq (%r12), %rsi
cmpb $0x0, (%rsi,%rdx)
jne 0x18fc5
incq %rcx
addq $0x18, %rdx
jmp 0x18fad
movq %rcx, 0x18(%r12)
movq %rcx, %rax
testq %rax, %rax
js 0x18fe9
movq 0x10(%r12), %rdi
callq 0xd090
movq %r14, %rdi
callq 0xd640
movq %rax, 0x10(%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq