// File: /workspace/github_c_makefile_star2_O3/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 0x31ab(%rip), %rbx      # 0x6208
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rbx, %rbx
jle 0x3257
movq %rdi, %r14
xorl %r15d, %r15d
movq 0x3188(%rip), %r12      # 0x6200
xorl %r13d, %r13d
movq (%r12,%r15,8), %rsi
movq %r14, %rdi
callq 0x3266
cmpl $0x1, %eax
adcl $0x0, %r13d
incq %r15
cmpq %r15, %rbx
jne 0x307b
testl %r13d, %r13d
je 0x31e5
callq 0x3509
movq 0x3175(%rip), %r15      # 0x6220
testq %r15, %r15
je 0x30e3
movslq 0x3171(%rip), %rbx      # 0x6228
testq %rbx, %rbx
jle 0x30d0
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
callq 0x2050
incq %r12
cmpq %r12, %rbx
jne 0x30bf
movq %r15, %rdi
callq 0x2050
movq $0x0, 0x313d(%rip) # 0x6220
cmpb $0x0, (%r14)
je 0x31ec
movl $0x8, %edi
callq 0x21d0
movq %rax, 0x3122(%rip)      # 0x6220
testq %rax, %rax
je 0x31e5
movl $0x0, 0x3117(%rip)      # 0x6228
movslq 0x30f0(%rip), %r15      # 0x6208
testq %r15, %r15
jle 0x3207
movq %rax, -0x30(%rbp)
xorl %ebx, %ebx
movq 0x30d2(%rip), %rax      # 0x6200
movq %rax, -0x38(%rbp)
xorl %r13d, %r13d
movq %r15, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq (%rax,%rbx,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x3266
testl %eax, %eax
jne 0x31c7
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 0x31e5
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, 0x3086(%rip)     # 0x6228
leaq 0x10(,%r15,8), %rsi
movq -0x30(%rbp), %rdi
callq 0x21f0
movq %rax, 0x3066(%rip)      # 0x6220
movq %rax, -0x30(%rbp)
testq %rax, %rax
movq -0x40(%rbp), %r15
je 0x31e5
incq %rbx
cmpq %rbx, %r15
jne 0x3139
testl %r13d, %r13d
je 0x3203
movq -0x30(%rbp), %rax
movq %rax, 0x302d(%rip)      # 0x6210
jmp 0x322b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3257
movq 0x300d(%rip), %rax      # 0x6200
movq %rax, 0x3016(%rip)      # 0x6210
movl 0x3007(%rip), %r13d     # 0x6208
jmp 0x322b
movq -0x30(%rbp), %rax
movq %rax, %rdi
callq 0x2050
movq $0x0, 0x3006(%rip) # 0x6220
movq 0x2fdf(%rip), %rax      # 0x6200
movq %rax, 0x2fe8(%rip)      # 0x6210
movl %r15d, %r13d
movl %r13d, 0x2fe6(%rip)     # 0x6218
callq 0x3547
callq 0x3382
movl $0x0, 0x2f52(%rip)      # 0x6198
movq 0x2fc3(%rip), %rax      # 0x6210
movq (%rax), %rdi
callq 0x3401
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq