// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x8(%rdi), %r12
testq %r12, %r12
je 0x1a262
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x0, (%rsi)
je 0x1a1b3
testq %r12, %r12
jle 0x1a1ce
movq (%rbx), %r13
addq $0x10, %r13
xorl %ebp, %ebp
movq -0x10(%r13), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xd6f0
testq %rax, %rax
setne (%r13)
movq %r14, %rdi
movq %r15, %rsi
callq 0xd390
testl %eax, %eax
jne 0x1a1a5
movq %rbp, 0x18(%rbx)
incq %rbp
addq $0x18, %r13
cmpq %rbp, %r12
jne 0x1a17b
jmp 0x1a1ce
testq %r12, %r12
jle 0x1a1ce
movq (%rbx), %rax
addq $0x10, %rax
movq %r12, %rcx
movb $0x1, (%rax)
addq $0x18, %rax
decq %rcx
jne 0x1a1c2
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
js 0x1a21e
movq (%rbx), %rdx
leaq (%rcx,%rcx,2), %rax
cmpb $0x0, 0x10(%rdx,%rax,8)
jne 0x1a246
xorl %esi, %esi
movq %rcx, %rdi
movq $-0x1, %rax
movq %rdi, %r8
incq %r8
cmpq %rcx, %r8
je 0x1a242
cmpq %r12, %r8
movq %r8, %rdi
cmovgeq %rsi, %rdi
leaq (%rdi,%rdi,2), %r9
cmpb $0x0, 0x10(%rdx,%r9,8)
jne 0x1a23f
testq %rcx, %rcx
jne 0x1a1f1
cmpq %r12, %r8
jl 0x1a1f1
jmp 0x1a242
testq %r12, %r12
jle 0x1a246
movq (%rbx), %rcx
addq $0x10, %rcx
xorl %eax, %eax
cmpb $0x0, (%rcx)
jne 0x1a242
incq %rax
addq $0x18, %rcx
cmpq %rax, %r12
jne 0x1a22c
jmp 0x1a246
movq %rdi, %rax
movq %rax, 0x18(%rbx)
cmpq $0x0, 0x18(%rbx)
js 0x1a262
movq 0x10(%rbx), %rdi
callq 0xd090
movq %r14, %rdi
callq 0xd640
movq %rax, 0x10(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq