// File: /workspace/github_c_makefile_star2_O3/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
movl %ecx, %r15d
movq %rdx, 0x28(%rsp)
testl %ecx, %ecx
setle %al
testl %esi, %esi
sets %cl
orb %al, %cl
jne 0x2918c
movq %r8, %r13
movl %esi, %ebp
movq %rdi, %r14
movl $0x28, %edi
callq 0x299b5
xorl %edx, %edx
testq %rax, %rax
je 0x2918c
movq %rax, %rbx
testl %ebp, %ebp
je 0x29208
movq %r14, 0x18(%rsp)
movq %r13, 0x8(%rsp)
movl %ebp, 0x10(%rsp)
subl %r15d, %ebp
incl %ebp
movl %ebp, 0x14(%rsp)
testl %ebp, %ebp
jle 0x29190
movq %r15, 0x20(%rsp)
movl %r15d, %eax
movq %rax, 0x30(%rsp)
movl $0x5, %r13d
xorl %r14d, %r14d
movq %rbx, %r15
xorl %ebp, %ebp
xorl %edx, %edx
movq %rdx, %r12
leal 0x2(%rdx), %eax
cmpl %eax, %r13d
jge 0x2910c
addl %r13d, %r13d
movslq %r13d, %rsi
shlq $0x3, %rsi
movq %r15, %rdi
callq 0x29a61
movq %rax, %rbx
testq %rax, %rax
jne 0x2910f
jmp 0x291d1
movq %r15, %rbx
movl %r14d, %edi
cmpl $0x1, 0x20(%rsp)
movq 0x18(%rsp), %r15
jne 0x2912b
movb (%r15,%rdi), %al
movq 0x28(%rsp), %rcx
cmpb (%rcx), %al
je 0x29146
addq %r15, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1f6a0
testl %eax, %eax
je 0x29146
movq %r12, %rdx
jmp 0x29179
movl %ebp, %edi
addq %r15, %rdi
movl %r14d, %eax
subl %ebp, %eax
movslq %eax, %rsi
callq 0x283f4
movq %r12, %rdx
movslq %edx, %rcx
movq %rax, (%rbx,%rcx,8)
testq %rax, %rax
je 0x291c7
incl %edx
movl %r14d, %ebp
movq 0x20(%rsp), %rax
addl %eax, %ebp
addl %eax, %r14d
decl %r14d
incl %r14d
movq %rbx, %r15
cmpl 0x14(%rsp), %r14d
jl 0x290e2
jmp 0x29194
xorl %ebx, %ebx
jmp 0x2920c
xorl %edx, %edx
xorl %ebp, %ebp
movl %ebp, %eax
movq 0x18(%rsp), %rdi
addq %rax, %rdi
movl 0x10(%rsp), %eax
subl %ebp, %eax
movslq %eax, %rsi
movq %rdx, %r14
callq 0x283f4
movq %r14, %rdx
movslq %edx, %rcx
movq %rax, (%rbx,%rcx,8)
testq %rax, %rax
je 0x291c7
incl %edx
movq 0x8(%rsp), %r13
jmp 0x29208
movq %rbx, %r15
movq 0x8(%rsp), %r13
jmp 0x291d9
movq 0x8(%rsp), %r13
movq %r12, %rdx
testl %edx, %edx
jle 0x291fc
movl %edx, %ebx
xorl %r14d, %r14d
movq (%r15,%r14,8), %rdi
testq %rdi, %rdi
je 0x291f4
addq $-0x8, %rdi
callq 0x29af7
incq %r14
cmpq %r14, %rbx
jne 0x291e2
movq %r15, %rdi
callq 0x29af7
xorl %edx, %edx
xorl %ebx, %ebx
movl %edx, (%r13)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq