// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdx, 0x28(%rsp)
testl %ecx, %ecx
setle %al
testl %esi, %esi
sets %dl
orb %al, %dl
jne 0x28e81
movq %r8, %r13
movl %esi, %ebp
movq %rdi, %r15
movq %rcx, 0x10(%rsp)
movl $0x28, %edi
callq 0x29709
xorl %r12d, %r12d
testq %rax, %rax
je 0x28e81
movq %rax, %r14
testl %ebp, %ebp
je 0x28ef4
movq %r15, 0x20(%rsp)
movq %r13, 0x8(%rsp)
movl %ebp, 0x18(%rsp)
movq 0x10(%rsp), %rcx
subl %ecx, %ebp
incl %ebp
movl %ebp, 0x1c(%rsp)
testl %ebp, %ebp
jle 0x28e86
movl %ecx, %eax
movq %rax, 0x30(%rsp)
movl $0x5, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rsp), %rbx
leal 0x2(%r12), %eax
cmpl %eax, %r13d
jge 0x28e12
addl %r13d, %r13d
movslq %r13d, %rsi
shlq $0x3, %rsi
movq %r14, %rdi
callq 0x297b5
movq 0x10(%rsp), %rcx
testq %rax, %rax
cmovneq %rax, %r14
je 0x28ebc
movl %ebp, %edi
cmpl $0x1, %ecx
jne 0x28e25
movb (%rbx,%rdi), %al
movq 0x28(%rsp), %rcx
cmpb (%rcx), %al
je 0x28e42
addq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1f6a0
testl %eax, %eax
je 0x28e42
movq 0x10(%rsp), %rcx
jmp 0x28e73
movl %r15d, %edi
addq %rbx, %rdi
movl %ebp, %eax
subl %r15d, %eax
movslq %eax, %rsi
callq 0x28148
movslq %r12d, %rcx
movq %rax, (%r14,%rcx,8)
testq %rax, %rax
je 0x28ebc
incl %r12d
movl %ebp, %r15d
movq 0x10(%rsp), %rcx
addl %ecx, %r15d
addl %ecx, %ebp
decl %ebp
incl %ebp
cmpl 0x1c(%rsp), %ebp
jl 0x28de4
jmp 0x28e8c
xorl %r14d, %r14d
jmp 0x28ef8
xorl %r12d, %r12d
xorl %r15d, %r15d
movl %r15d, %eax
movq 0x20(%rsp), %rdi
addq %rax, %rdi
movl 0x18(%rsp), %eax
subl %r15d, %eax
movslq %eax, %rsi
callq 0x28148
movslq %r12d, %rcx
movq %rax, (%r14,%rcx,8)
testq %rax, %rax
je 0x28ebc
incl %r12d
movq 0x8(%rsp), %r13
jmp 0x28ef4
movq 0x8(%rsp), %r13
testl %r12d, %r12d
jle 0x28ee6
movl %r12d, %ebx
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
testq %rdi, %rdi
je 0x28ede
addq $-0x8, %rdi
callq 0x2984b
incq %r15
cmpq %r15, %rbx
jne 0x28ecc
movq %r14, %rdi
callq 0x2984b
xorl %r12d, %r12d
xorl %r14d, %r14d
movl %r12d, (%r13)
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq