// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %esi, %ebp
movq %rdi, %r15
movq %rdx, 0x30(%rsp)
movl (%rdx), %eax
movq %rax, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq (%rcx), %rax
movq %rax, (%rsp)
callq 0x4210
movslq %eax, %rsi
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %edx, %edx
movq %rsi, 0x10(%rsp)
cmpq %rsi, %r14
jg 0x35afe
movslq %edx, %r8
testl %ebp, %ebp
je 0x35a2f
movsbl (%r15,%r14), %eax
testl %eax, %eax
setne %cl
cmpl %ebp, %eax
setne %al
testb %al, %cl
jne 0x35a6c
testl %r13d, %r13d
sete %al
cmpl %ebp, %r13d
sete %cl
orb %al, %cl
jne 0x35af1
movb $0x0, (%r15,%r14)
movq 0x8(%rsp), %rax
cmpl %eax, %edx
jne 0x35a8a
leal (%rax,%rax), %r13d
testl %eax, %eax
pushq $0x2
popq %rax
cmovel %eax, %r13d
movslq %r13d, %rsi
shlq $0x2, %rsi
movq (%rsp), %rdi
movq %rdi, %rbx
movq %r8, 0x20(%rsp)
movl %edx, 0x2c(%rsp)
callq 0x48c0
movq 0x10(%rsp), %rsi
movl 0x2c(%rsp), %edx
movq 0x20(%rsp), %r8
movl %r13d, %ecx
movq %rcx, 0x8(%rsp)
testq %rax, %rax
jne 0x35a8e
jmp 0x35b27
movq %r8, 0x20(%rsp)
movl %edx, %ebx
callq 0x4580
movq (%rax), %rcx
movsbq (%r15,%r14), %rdx
movslq %r13d, %rax
movzwl (%rcx,%rax,2), %eax
testq %rdx, %rdx
je 0x35a7c
movzwl (%rcx,%rdx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x35a7c
testl %r13d, %r13d
cmovel %r14d, %r12d
testw $0x2000, %ax            # imm = 0x2000
cmovnel %r14d, %r12d
jmp 0x35a81
testl %r13d, %r13d
cmovel %r14d, %r12d
cmpl %ebp, %r13d
cmovel %r14d, %r12d
jmp 0x35af1
testw %ax, %ax
js 0x35a96
movl %ebx, %edx
movq 0x10(%rsp), %rsi
jmp 0x35af1
movq (%rsp), %rax
incl %edx
movl %r12d, (%rax,%r8,4)
jmp 0x35aed
movb $0x0, (%r15,%r14)
movq 0x8(%rsp), %rax
cmpl %eax, %ebx
jne 0x35ad7
leal (%rax,%rax), %r13d
testl %eax, %eax
pushq $0x2
popq %rax
cmovel %eax, %r13d
movslq %r13d, %rsi
shlq $0x2, %rsi
movq (%rsp), %rdi
callq 0x48c0
movl %ebx, %edx
movl %r13d, %ecx
movq %rcx, 0x8(%rsp)
testq %rax, %rax
movq 0x10(%rsp), %rsi
jne 0x35ae2
jmp 0x35b2c
movl %ebx, %edx
movq (%rsp), %rax
movq 0x10(%rsp), %rsi
incl %edx
movq 0x20(%rsp), %rcx
movl %r12d, (%rax,%rcx,4)
movq %rax, (%rsp)
movsbl (%r15,%r14), %r13d
incq %r14
jmp 0x35995
movq 0x30(%rsp), %rax
movq 0x8(%rsp), %rcx
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, (%rax)
movl %edx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
jmp 0x35b30
movq (%rsp), %rdi
callq 0x4600
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x18(%rsp), %rax
jmp 0x35b13