// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x38(%rsp)
movq %rcx, 0x18(%rsp)
testl %ecx, %ecx
setle %al
testl %esi, %esi
sets %cl
orb %al, %cl
jne 0x27ca9
movq %r8, %rbx
movl %esi, %r14d
movq %rdi, 0x30(%rsp)
pushq $0x28
popq %rdi
callq 0x2828d
xorl %r13d, %r13d
testq %rax, %rax
je 0x27ca9
movq %rax, %rbp
testl %r14d, %r14d
je 0x27d09
movq %rbx, 0x28(%rsp)
movl %r14d, 0x20(%rsp)
movq 0x18(%rsp), %rax
subl %eax, %r14d
incl %r14d
movl %r14d, 0x24(%rsp)
movl %eax, %eax
movq %rax, 0x40(%rsp)
pushq $0x5
popq %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %r15d, %r15d
movl %ecx, %ebx
movslq %r13d, %r12
cmpl 0x24(%rsp), %r15d
movq %r13, 0x10(%rsp)
jge 0x27cad
movl %ecx, 0xc(%rsp)
leal 0x2(%r13), %eax
cmpl %eax, %r14d
jge 0x27c23
addl %r14d, %r14d
movslq %r14d, %rsi
shlq $0x3, %rsi
movq %rbp, %rdi
callq 0x28337
movq %rax, %r13
testq %rax, %rax
jne 0x27c26
jmp 0x27cd5
movq %rbp, %r13
movl %r15d, %edi
cmpl $0x1, 0x18(%rsp)
movq 0x30(%rsp), %rbp
jne 0x27c42
movb (%rbp,%rdi), %al
movq 0x38(%rsp), %rcx
cmpb (%rcx), %al
je 0x27c5e
addq %rbp, %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x1f6a0
testl %eax, %eax
je 0x27c5e
movl 0xc(%rsp), %ecx
jmp 0x27c99
addq %rbp, %rbx
movl %r15d, %eax
subl 0xc(%rsp), %eax
movslq %eax, %rsi
movq %rbx, %rdi
callq 0x27158
movq %rax, (%r13,%r12,8)
testq %rax, %rax
je 0x27cd2
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movl %r15d, %ecx
movq 0x18(%rsp), %rax
addl %eax, %ecx
addl %eax, %r15d
decl %r15d
incl %r15d
movq %r13, %rbp
movq 0x10(%rsp), %r13
jmp 0x27be2
xorl %ebp, %ebp
jmp 0x27d0c
movq 0x30(%rsp), %rdi
addq %rbx, %rdi
movl 0x20(%rsp), %eax
subl %ecx, %eax
movslq %eax, %rsi
callq 0x27158
movq %rax, (%rbp,%r12,8)
testq %rax, %rax
je 0x27cd5
incl %r13d
jmp 0x27d04
movq %r13, %rbp
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
testl %r14d, %r14d
cmovlel %ebx, %r14d
cmpq %rbx, %r14
je 0x27cf7
movq (%rbp,%rbx,8), %rdi
callq 0x271f7
incq %rbx
jmp 0x27ce3
movq %rbp, %rdi
callq 0x283cd
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x28(%rsp), %rbx
movl %r13d, (%rbx)
movq %rbp, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq