// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 $0x28, %rsp
movl %esi, %ebp
movq %rdi, %r12
movq %rdx, 0x18(%rsp)
movl (%rdx), %eax
movq %rax, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
movq (%rcx), %r13
callq 0x31e0
movq %rax, %rdx
testl %edx, %edx
js 0x18cc9
incl %edx
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %ebx, %ebx
movl $0x0, 0x4(%rsp)
movq %rdx, 0x10(%rsp)
testl %ebp, %ebp
je 0x18c17
movsbl (%r12,%r15), %eax
testl %eax, %eax
setne %cl
cmpl %ebp, %eax
setne %al
testb %al, %cl
jne 0x18c4d
testl %ebx, %ebx
sete %al
cmpl %ebp, %ebx
sete %cl
orb %al, %cl
jne 0x18cb6
movb $0x0, (%r12,%r15)
movl 0x4(%rsp), %ecx
movq 0x8(%rsp), %rax
cmpl %eax, %ecx
jne 0x18ca8
leal (%rax,%rax), %ebx
testl %eax, %eax
movl $0x2, %eax
cmovel %eax, %ebx
movslq %ebx, %rsi
shlq $0x2, %rsi
movq %r13, %rdi
callq 0x3430
movq 0x10(%rsp), %rdx
movq %rax, %r13
movl %ebx, %eax
movq %rax, 0x8(%rsp)
movl 0x4(%rsp), %ecx
jmp 0x18ca8
callq 0x35f0
movq (%rax), %rcx
movsbq (%r12,%r15), %rdx
movslq %ebx, %rax
movzwl (%rcx,%rax,2), %eax
testq %rdx, %rdx
je 0x18c5b
movzwl (%rcx,%rdx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x18c5b
testl %ebx, %ebx
cmovel %r15d, %r14d
testl $0x2000, %eax           # imm = 0x2000
cmovnel %r15d, %r14d
jmp 0x18c60
testl %ebx, %ebx
cmovel %r15d, %r14d
cmpl %ebp, %ebx
cmovel %r15d, %r14d
jmp 0x18cb6
testw %ax, %ax
js 0x18c67
movq 0x10(%rsp), %rdx
jmp 0x18cb6
movb $0x0, (%r12,%r15)
movl 0x4(%rsp), %ecx
movq 0x8(%rsp), %rax
cmpl %eax, %ecx
jne 0x18ca3
leal (%rax,%rax), %ebx
testl %eax, %eax
movl $0x2, %eax
cmovel %eax, %ebx
movslq %ebx, %rsi
shlq $0x2, %rsi
movq %r13, %rdi
callq 0x3430
movq %rax, %r13
movl %ebx, %eax
movq %rax, 0x8(%rsp)
movl 0x4(%rsp), %ecx
movq 0x10(%rsp), %rdx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x4(%rsp)
movl %r14d, (%r13,%rax,4)
movsbl (%r12,%r15), %ebx
incq %r15
cmpq %r15, %rdx
jne 0x18ba0
jmp 0x18cd1
movl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
movl %ecx, (%rax)
movq 0x20(%rsp), %rax
movq %r13, (%rax)
movl 0x4(%rsp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq