// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4230
movl %eax, -0x4c(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jg 0x6264e
cmpl $0x0, -0x14(%rbp)
jne 0x6252f
callq 0x4610
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x62433
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x62502
callq 0x4610
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x62500
jmp 0x62453
cmpq $0x0, -0x28(%rbp)
je 0x624f3
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x624d9
cmpl $0x0, -0x34(%rbp)
je 0x62482
movl -0x34(%rbp), %eax
shll %eax
movl %eax, -0x64(%rbp)
jmp 0x6248c
movl $0x2, %eax
movl %eax, -0x64(%rbp)
jmp 0x6248c
movl -0x64(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x34(%rbp), %rsi
shlq $0x2, %rsi
callq 0x4990
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x624b7
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x624d7
movq -0x48(%rbp), %rdi
callq 0x46a0
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x62668
jmp 0x624d9
movl -0x3c(%rbp), %edx
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x30(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x624fc
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x624fe
jmp 0x62500
jmp 0x6252a
callq 0x4610
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x62522
cmpl $0x0, -0x38(%rbp)
jne 0x62528
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x6252a
jmp 0x62631
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
je 0x62555
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x62619
cmpl $0x0, -0x38(%rbp)
je 0x62617
movl -0x38(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x62617
jmp 0x6256d
cmpq $0x0, -0x28(%rbp)
je 0x6260a
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x625f0
cmpl $0x0, -0x34(%rbp)
je 0x6259c
movl -0x34(%rbp), %eax
shll %eax
movl %eax, -0x68(%rbp)
jmp 0x625a6
movl $0x2, %eax
movl %eax, -0x68(%rbp)
jmp 0x625a6
movl -0x68(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x34(%rbp), %rsi
shlq $0x2, %rsi
callq 0x4990
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x625d1
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x625ee
movq -0x48(%rbp), %rdi
callq 0x46a0
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x62668
jmp 0x625f0
movl -0x3c(%rbp), %edx
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x30(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x62613
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x62615
jmp 0x62617
jmp 0x6262f
movl -0x38(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x62627
cmpl $0x0, -0x38(%rbp)
jne 0x6262d
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x6262f
jmp 0x62631
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x623e3
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)