// File: /workspace/github_c_makefile_star2_O1/kobolt[P]curses-collection/playlist/list.c
// Function: list_filter_apply
int list_filter_apply(char *filter)
{
  int i;

  /* Just ignore everything if an invalid filter is given. */
  if (list_filter_produces_size(filter) == 0)
    return -1;

  play_block(); /* Entering critical section. */

  /* Free old filtered list first, if it exists. */
  if (list_filtered != NULL) {
    for (i = 0; i < list_filtered_size; i++) {
      free(list_filtered[i]);
    }
    free(list_filtered);
    list_filtered = NULL;
  }

  /* Use the empty string to disable the filter. */
  if (strlen(filter) == 0) {
    list = list_original;
    list_size = list_original_size;
    goto list_filter_apply_done;
  }

  list_filtered = (char **)malloc(sizeof(char *));
  if (list_filtered == NULL)
    return -1;

  list_filtered_size = 0;
  for (i = 0; i < list_original_size; i++) {
    if (list_cmp(filter, list_original[i]) == 0) {
      list_filtered[list_filtered_size] = (char *)malloc(sizeof(char) * 
        (strlen(list_original[i]) + 1));
      if (list_filtered[list_filtered_size] == NULL)
        return -1;
      strncpy(list_filtered[list_filtered_size], 
        list_original[i], strlen(list_original[i]) + 1);

      list_filtered_size++;
      list_filtered = (char **)realloc(list_filtered, sizeof(char *) *
        (list_filtered_size + 1));
      if (list_filtered == NULL)
        return -1;
    }
  }

  /* This should not happen, as size is checked earlier, but just in case... */
  if (list_filtered_size == 0) {
    free(list_filtered);
    list_filtered = NULL;

    list = list_original;
    list_size = list_original_size;
    goto list_filter_apply_done;
  }

  list = list_filtered;
  list_size = list_filtered_size;

list_filter_apply_done:
  play_unblock(); /* Leaving critical section. */
  play_cancel();
  list_current = 0;
  play_execute(list[list_current]);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movslq 0x31b8(%rip), %rbx      # 0x6208
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rbx, %rbx
jle 0x3254
movq %rdi, %r14
xorl %r15d, %r15d
movq 0x3195(%rip), %r12      # 0x6200
xorl %r13d, %r13d
movq (%r12,%r15,8), %rsi
movq %r14, %rdi
callq 0x3263
cmpl $0x1, %eax
adcl $0x0, %r13d
incq %r15
cmpq %r15, %rbx
jne 0x306e
testl %r13d, %r13d
je 0x31eb
callq 0x3505
movq 0x3182(%rip), %r15      # 0x6220
testq %r15, %r15
je 0x30d6
movslq 0x317e(%rip), %rbx      # 0x6228
testq %rbx, %rbx
jle 0x30c3
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
callq 0x2050
incq %r12
cmpq %r12, %rbx
jne 0x30b2
movq %r15, %rdi
callq 0x2050
movq $0x0, 0x314a(%rip) # 0x6220
cmpb $0x0, (%r14)
je 0x31f2
movl $0x8, %edi
callq 0x21d0
movq %rax, 0x312f(%rip)      # 0x6220
testq %rax, %rax
je 0x31eb
movl $0x0, 0x3124(%rip)      # 0x6228
movslq 0x30fd(%rip), %r15      # 0x6208
testq %r15, %r15
jle 0x31d1
movl 0x310d(%rip), %r13d     # 0x6228
movq 0x30fe(%rip), %rax      # 0x6220
movq %rax, -0x30(%rbp)
movq 0x30d3(%rip), %rax      # 0x6200
movq %rax, -0x38(%rbp)
xorl %ebx, %ebx
movq %r15, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq (%rax,%rbx,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x3263
testl %eax, %eax
jne 0x31c5
movq %r12, %rdi
callq 0x20e0
leaq 0x1(%rax), %rdi
callq 0x21d0
movq %rax, %r12
movslq %r13d, %r15
movq -0x30(%rbp), %rax
movq %r12, (%rax,%r15,8)
testq %r12, %r12
je 0x31eb
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq (%rax,%rbx,8), %r13
movq %r13, %rdi
callq 0x20e0
leaq 0x1(%rax), %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2080
leal 0x1(%r15), %r13d
movl %r13d, 0x3088(%rip)     # 0x6228
leaq 0x10(,%r15,8), %rsi
movq -0x30(%rbp), %rdi
callq 0x21f0
movq %rax, 0x3068(%rip)      # 0x6220
movq %rax, -0x30(%rbp)
testq %rax, %rax
movq -0x40(%rbp), %r15
je 0x31eb
incq %rbx
cmpq %rbx, %r15
jne 0x3137
movl 0x3051(%rip), %eax      # 0x6228
movq 0x3042(%rip), %rdi      # 0x6220
testl %eax, %eax
je 0x3208
movq %rdi, 0x3027(%rip)      # 0x6210
jmp 0x3229
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3254
movq 0x3007(%rip), %rax      # 0x6200
movq %rax, 0x3010(%rip)      # 0x6210
movl 0x3002(%rip), %eax      # 0x6208
jmp 0x3229
callq 0x2050
movq $0x0, 0x3008(%rip) # 0x6220
movq 0x2fe1(%rip), %rax      # 0x6200
movq %rax, 0x2fea(%rip)      # 0x6210
movl %r15d, %eax
movl %eax, 0x2fe9(%rip)      # 0x6218
callq 0x3543
callq 0x337e
movl $0x0, 0x2f55(%rip)      # 0x6198
movq 0x2fc6(%rip), %rax      # 0x6210
movq (%rax), %rdi
callq 0x33fd
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq