// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/kstring.c
// Function: ksplit_core
int ksplit_core(char *s, int delimiter, int *_max, int **_offsets)
{
	int i, n, max, last_char, last_start, *offsets, l;
	n = 0; max = *_max; offsets = *_offsets;
	l = strlen(s);
	
#define __ksplit_aux do {												\
		if (_offsets) {													\
			s[i] = 0;													\
			if (n == max) {												\
				max = max? max<<1 : 2;									\
				offsets = (int*)realloc(offsets, sizeof(int) * max);	\
			}															\
			offsets[n++] = last_start;									\
		} else ++n;														\
	} while (0)

	for (i = 0, last_char = last_start = 0; i <= l; ++i) {
		if (delimiter == 0) {
			if (isspace(s[i]) || s[i] == 0) {
				if (isgraph(last_char)) __ksplit_aux; // the end of a field
			} else {
				if (isspace(last_char) || last_char == 0) last_start = i;
			}
		} else {
			if (s[i] == delimiter || s[i] == 0) {
				if (last_char != 0 && last_char != delimiter) __ksplit_aux; // the end of a field
			} else {
				if (last_char == delimiter || last_char == 0) last_start = i;
			}
		}
		last_char = s[i];
	}
	*_max = max; *_offsets = offsets;
	return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
movq %rdi, %r15
movq %rdx, 0x28(%rsp)
movl (%rdx), %eax
movl %eax, 0xc(%rsp)
movq %rcx, 0x30(%rsp)
movq (%rcx), %rax
movq %rax, 0x10(%rsp)
callq 0x172d0
movslq %eax, %rdx
xorl %r12d, %r12d
xorl %esi, %esi
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rdx, 0x18(%rsp)
cmpq %rdx, %r12
jg 0x2d716f
movslq %esi, %rdi
testl %ebp, %ebp
je 0x2d70a3
movsbl (%r15,%r12), %eax
testl %eax, %eax
setne %cl
cmpl %ebp, %eax
setne %al
testb %al, %cl
jne 0x2d70e9
testl %r13d, %r13d
sete %al
cmpl %ebp, %r13d
sete %cl
orb %al, %cl
jne 0x2d7162
movb $0x0, (%r15,%r12)
cmpl 0xc(%rsp), %esi
jne 0x2d7108
leal (%rsi,%rsi), %eax
testl %esi, %esi
pushq $0x2
popq %rcx
cmovel %ecx, %eax
movl %eax, 0xc(%rsp)
movq %rsi, %r14
movslq %eax, %rsi
shlq $0x2, %rsi
movq %rdi, %r13
movq 0x10(%rsp), %rdi
callq 0x17f58
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
jmp 0x2d710d
movq %rdi, 0x20(%rsp)
movq %rsi, %r14
callq 0x17820
movq (%rax), %rcx
movsbq (%r15,%r12), %rdx
movslq %r13d, %rax
movzwl (%rcx,%rax,2), %eax
testq %rdx, %rdx
je 0x2d70f9
movzwl (%rcx,%rdx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x2d70f9
testl %r13d, %r13d
cmovel %r12d, %ebx
testw $0x2000, %ax            # imm = 0x2000
cmovnel %r12d, %ebx
movq 0x18(%rsp), %rdx
movq %r14, %rsi
jmp 0x2d7162
testl %r13d, %r13d
cmovel %r12d, %ebx
cmpl %ebp, %r13d
cmovel %r12d, %ebx
jmp 0x2d7162
testw %ax, %ax
movq %r14, %rsi
js 0x2d7119
movq 0x18(%rsp), %rdx
jmp 0x2d7162
movq 0x10(%rsp), %rax
incl %esi
movq %rax, 0x10(%rsp)
movl %ebx, (%rax,%rdi,4)
jmp 0x2d7162
movb $0x0, (%r15,%r12)
cmpl 0xc(%rsp), %esi
jne 0x2d7149
leal (%rsi,%rsi), %eax
testl %esi, %esi
pushq $0x2
popq %rcx
cmovel %ecx, %eax
movl %eax, 0xc(%rsp)
movslq %eax, %rsi
shlq $0x2, %rsi
movq 0x10(%rsp), %rdi
callq 0x17f58
movq %r14, %rsi
jmp 0x2d714e
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
incl %esi
movq %rax, 0x10(%rsp)
movl %ebx, (%rax,%rcx,4)
movsbl (%r15,%r12), %r13d
incq %r12
jmp 0x2d7026
movq 0x28(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movl %esi, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq