// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/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) {					\
				int *tmp;				\
				max = max? max<<1 : 2;			\
				if ((tmp = (int*)realloc(offsets, sizeof(int) * max))) {  \
					offsets = tmp;			\
				} else	{				\
					free(offsets);			\
					*_offsets = NULL;		\
					return 0;			\
				}					\
			}						\
			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, %r13
movq %rdx, 0x18(%rsp)
movl (%rdx), %eax
movl %eax, 0x4(%rsp)
movq %rcx, 0x20(%rsp)
movq (%rcx), %rax
movq %rax, 0x8(%rsp)
callq 0x4230
movq %rax, %rsi
xorl %edx, %edx
testl %esi, %esi
js 0x4222f
incl %esi
xorl %r15d, %r15d
xorl %edx, %edx
xorl %ebx, %ebx
xorl %r12d, %r12d
movq %rsi, 0x10(%rsp)
testl %ebp, %ebp
je 0x42164
movsbl (%r13,%r15), %eax
testl %eax, %eax
setne %cl
cmpl %ebp, %eax
setne %al
testb %al, %cl
jne 0x4219f
testl %r12d, %r12d
sete %al
cmpl %ebp, %r12d
sete %cl
orb %al, %cl
jne 0x4221d
movb $0x0, (%r13,%r15)
cmpl 0x4(%rsp), %edx
movq 0x8(%rsp), %r12
jne 0x421be
leal (%rdx,%rdx), %eax
testl %edx, %edx
movl $0x2, %ecx
cmovel %ecx, %eax
movl %eax, 0x4(%rsp)
movslq %eax, %rsi
shlq $0x2, %rsi
movq %r12, %rdi
movq %rdx, %r14
callq 0x48d0
movq %r14, %rdx
movq 0x10(%rsp), %rsi
testq %rax, %rax
jne 0x42210
jmp 0x42258
movq %rdx, %r14
callq 0x4580
movq (%rax), %rcx
movsbq (%r13,%r15), %rdx
movslq %r12d, %rax
movzwl (%rcx,%rax,2), %eax
testq %rdx, %rdx
je 0x421af
movzwl (%rcx,%rdx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x421af
testl %r12d, %r12d
cmovel %r15d, %ebx
testl $0x2000, %eax           # imm = 0x2000
cmovnel %r15d, %ebx
jmp 0x421b4
testl %r12d, %r12d
cmovel %r15d, %ebx
cmpl %ebp, %r12d
cmovel %r15d, %ebx
jmp 0x4221d
testw %ax, %ax
js 0x421c3
movq %r14, %rdx
movq 0x10(%rsp), %rsi
jmp 0x4221d
movq %r12, %rax
jmp 0x42210
movb $0x0, (%r13,%r15)
movq %r14, %rdx
cmpl 0x4(%rsp), %edx
jne 0x42206
leal (%rdx,%rdx), %eax
testl %edx, %edx
movl $0x2, %ecx
cmovel %ecx, %eax
movl %eax, 0x4(%rsp)
movslq %eax, %rsi
shlq $0x2, %rsi
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x48d0
movq %r14, %rdx
testq %rax, %rax
movq 0x10(%rsp), %rsi
jne 0x42210
jmp 0x42258
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rsi
movslq %edx, %rcx
incl %edx
movl %ebx, (%rax,%rcx,4)
movq %rax, 0x8(%rsp)
movsbl (%r13,%r15), %r12d
incq %r15
cmpq %r15, %rsi
jne 0x420e6
movq 0x18(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq 0x8(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movl %edx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x4610
xorl %ecx, %ecx
xorl %edx, %edx
jmp 0x4223f