// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rdi, %rbx
movl 0x326d(%rip), %r14d     # 0x6208
movq 0x325e(%rip), %r15      # 0x6200
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
xorl %r13d, %r13d
cmpq %r12, %r14
je 0x2fcc
movq (%r15,%r12,8), %rsi
movq %rbx, %rdi
callq 0x3199
cmpl $0x1, %eax
adcl $0x0, %r13d
incq %r12
jmp 0x2faf
pushq $-0x1
popq %rax
testl %r13d, %r13d
je 0x318a
callq 0x3418
movq 0x323c(%rip), %r15      # 0x6220
testq %r15, %r15
je 0x301d
movl 0x3238(%rip), %r14d     # 0x6228
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
cmpq %r12, %r14
je 0x300d
movq (%r15,%r12,8), %rdi
callq 0x2050
incq %r12
jmp 0x2ffa
movq %r15, %rdi
callq 0x2050
andq $0x0, 0x3203(%rip)      # 0x6220
cmpb $0x0, (%rbx)
je 0x3119
pushq $0x8
popq %rdi
callq 0x21d0
movq %rax, 0x31eb(%rip)      # 0x6220
testq %rax, %rax
je 0x3114
movq %rax, %r15
andl $0x0, 0x31e0(%rip)      # 0x6228
movl 0x31ba(%rip), %eax      # 0x6208
movq 0x31ab(%rip), %rcx      # 0x6200
movq %rcx, -0x38(%rbp)
xorl %r14d, %r14d
testl %eax, %eax
movl $0x0, %r13d
movl %eax, -0x3c(%rbp)
cmovgl %eax, %r13d
movl $0x0, -0x30(%rbp)
movq %r13, -0x48(%rbp)
cmpq %r14, %r13
je 0x3130
movq -0x38(%rbp), %rax
movq (%rax,%r14,8), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3199
testl %eax, %eax
jne 0x310c
movq %r12, %rdi
callq 0x20e0
leaq 0x1(%rax), %rdi
callq 0x21d0
movq %r15, %r13
movslq -0x30(%rbp), %r15
movq %rax, (%r13,%r15,8)
testq %rax, %rax
je 0x3114
movq %rax, %r12
movq -0x38(%rbp), %rax
movq (%rax,%r14,8), %rdi
movq %rdi, -0x30(%rbp)
callq 0x20e0
leaq 0x1(%rax), %rdx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x2080
leal 0x1(%r15), %eax
movl %eax, -0x30(%rbp)
movl %eax, 0x313f(%rip)      # 0x6228
leaq 0x10(,%r15,8), %rsi
movq %r13, %rdi
callq 0x21f0
movq %rax, %r15
movq %rax, 0x311d(%rip)      # 0x6220
testq %rax, %rax
movq -0x48(%rbp), %r13
je 0x3114
incq %r14
jmp 0x3076
pushq $-0x1
popq %rax
jmp 0x318a
movq 0x30e0(%rip), %rax      # 0x6200
movq %rax, 0x30e9(%rip)      # 0x6210
movl 0x30da(%rip), %r13d     # 0x6208
jmp 0x3161
movl -0x30(%rbp), %r13d
testl %r13d, %r13d
je 0x3142
movq %r15, 0x30d0(%rip)      # 0x6210
jmp 0x3161
movq %r15, %rdi
callq 0x2050
andq $0x0, 0x30ce(%rip)      # 0x6220
movq -0x38(%rbp), %rax
movq %rax, 0x30b3(%rip)      # 0x6210
movl -0x3c(%rbp), %r13d
movl %r13d, 0x30b0(%rip)     # 0x6218
callq 0x3454
callq 0x32a6
andl $0x0, 0x301f(%rip)      # 0x6198
movq 0x3090(%rip), %rax      # 0x6210
movq (%rax), %rdi
callq 0x331a
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq