// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/sds.c
// Function: sdssplitlen
sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count) {
    int elements = 0, slots = 5, start = 0, j;
    sds *tokens;

    if (seplen < 1 || len < 0) return NULL;

    tokens = zmalloc(sizeof(sds)*slots);
    if (tokens == NULL) return NULL;

    if (len == 0) {
        *count = 0;
        return tokens;
    }
    
    // T = O(N^2)
    for (j = 0; j < (len-(seplen-1)); j++) {
        /* make sure there is room for the next element and the final one */
        if (slots < elements+2) {
            sds *newtokens;

            slots *= 2;
            newtokens = zrealloc(tokens,sizeof(sds)*slots);
            if (newtokens == NULL) goto cleanup;
            tokens = newtokens;
        }
        /* search the separator */
        // T = O(N)
        if ((seplen == 1 && *(s+j) == sep[0]) || (memcmp(s+j,sep,seplen) == 0)) {
            tokens[elements] = sdsnewlen(s+start,j-start);
            if (tokens[elements] == NULL) goto cleanup;
            elements++;
            start = j+seplen;
            j = j+seplen-1; /* skip the separator */
        }
    }
    /* Add the final element. We are sure there is room in the tokens array. */
    tokens[elements] = sdsnewlen(s+start,len-start);
    if (tokens[elements] == NULL) goto cleanup;
    elements++;
    *count = elements;
    return tokens;

cleanup:
    {
        int i;
        for (i = 0; i < elements; i++) sdsfree(tokens[i]);
        zfree(tokens);
        *count = 0;
        return NULL;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x5, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x1, -0x24(%rbp)
jl 0x2d5db
cmpl $0x0, -0x14(%rbp)
jge 0x2d5e8
movq $0x0, -0x8(%rbp)
jmp 0x2d7c4
movslq -0x38(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2e130
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x2d60d
movq $0x0, -0x8(%rbp)
jmp 0x2d7c4
cmpl $0x0, -0x14(%rbp)
jne 0x2d62a
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2d7c4
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl -0x14(%rbp), %ecx
movl -0x24(%rbp), %edx
subl $0x1, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x2d729
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x2d685
movl -0x38(%rbp), %eax
shll %eax
movl %eax, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x38(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2e270
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x2d67d
jmp 0x2d77e
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x1, -0x24(%rbp)
jne 0x2d6a2
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x2d6bf
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movslq -0x24(%rbp), %rdx
callq 0x1f950
cmpl $0x0, %eax
jne 0x2d719
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %eax
subl -0x3c(%rbp), %eax
movslq %eax, %rsi
callq 0x2c000
movq %rax, %rdx
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x2d6fb
jmp 0x2d77e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2d71b
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2d631
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rax
addq %rax, %rdi
movl -0x14(%rbp), %eax
subl -0x3c(%rbp), %eax
movslq %eax, %rsi
callq 0x2c000
movq %rax, %rdx
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x2d762
jmp 0x2d77e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2d7c4
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x2d7a9
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2c160
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x2d785
movq -0x48(%rbp), %rdi
callq 0x2e3a0
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop