// File: /workspace/github_c_makefile_star2_O0/WojciechMula[P]pyahocorasick/src/trienode.c
// Function: trienode_unset_next_pointer
static TristateResult
trienode_unset_next_pointer(TrieNode* node, TrieNode* child) {

    unsigned i;
    unsigned index;
    Pair* next;

    ASSERT(node);
    for (i=0; i < node->n; i++) {
        if (node->next[i].child == child) {
            index = i;
            goto found;
        }
    }

    return FALSE;

found:
    if (node->n == 1) {
        // there is just one node
        node->n = 0;
        memory_free(node->next);
        node->next = NULL;
        return TRUE;
    }

    // there are more nodes, reallocation is needed

    next = (Pair*)memory_alloc((node->n - 1) * sizeof(Pair));
    if (UNLIKELY(next == NULL)) {
        return MEMORY_ERROR;
    }

    for (i=0; i < index; i++) {
        next[i] = node->next[i];
    }

    for (i=index + 1; i < node->n; i++) {
        next[i - 1] = node->next[i];
    }

    memory_free(node->next);
    node->next = next;
    node->n -= 1;
    return TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x9373
movq 0x8cca(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x2cd8(%rip), %rsi      # 0xc010
leaq 0x32ad(%rip), %rdx      # 0xc5ec
leaq 0x5436(%rip), %rcx      # 0xe77c
movl $0x43, %r8d
leaq 0x5a40(%rip), %r9       # 0xed93
movb $0x0, %al
callq 0x31b0
movq 0x8c97(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
callq 0x3230
movl $0x1, %edi
callq 0x3310
jmp 0x9375
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x93b9
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq 0x4(%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x93ac
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x93c5
jmp 0x93ae
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x937c
movl $0x2, -0x4(%rbp)
jmp 0x94fd
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x93ff
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x34b0
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x94fd
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
imulq $0xc, %rax, %rdi
callq 0x3450
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x9439
movl $0x0, -0x4(%rbp)
jmp 0x94fd
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x947f
movq -0x28(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x1c(%rbp), %edx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9440
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x94d0
movq -0x28(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x1c(%rbp), %edx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9488
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x34b0
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)