// File: /workspace/github_c_makefile_star2_O1/mattn[P]orelang/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, %r12
movq %rdx, 0x20(%rsp)
movl (%rdx), %eax
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq (%rcx), %rax
movq %rax, 0x8(%rsp)
callq 0x20c0
movq %rax, %r14
testl %r14d, %r14d
js 0xb7bc
incl %r14d
xorl %r13d, %r13d
movl $0x0, 0x4(%rsp)
xorl %r15d, %r15d
xorl %ebx, %ebx
testl %ebp, %ebp
je 0xb6dd
movsbl (%r12,%r13), %eax
testl %eax, %eax
setne %cl
cmpl %ebp, %eax
setne %al
testb %al, %cl
jne 0xb716
testl %ebx, %ebx
sete %al
cmpl %ebp, %ebx
sete %cl
orb %al, %cl
jne 0xb7a9
movb $0x0, (%r12,%r13)
movq 0x10(%rsp), %rax
movl 0x4(%rsp), %ecx
cmpl %eax, %ecx
movq 0x8(%rsp), %rbx
jne 0xb6c6
testl %eax, %eax
leal (%rax,%rax), %eax
movl $0x2, %ecx
cmovel %ecx, %eax
movq %rax, 0x10(%rsp)
movslq %eax, %rsi
shlq $0x2, %rsi
movq %rbx, %rdi
callq 0x21e0
movq %rbx, %rcx
movq %rax, %rbx
testq %rax, %rax
jne 0xb6b6
movq %rcx, %rdi
movq %rcx, 0x8(%rsp)
callq 0x22c0
movq 0x18(%rsp), %rax
movq $0x0, (%rax)
movq 0x8(%rsp), %rax
testq %rbx, %rbx
movq %rax, %rbx
movl 0x4(%rsp), %ecx
je 0xb7f0
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x4(%rsp)
movq %rbx, 0x8(%rsp)
movl %r15d, (%rbx,%rax,4)
jmp 0xb7a9
callq 0x22b0
movq (%rax), %rcx
movsbq (%r12,%r13), %rdx
movslq %ebx, %rax
movzwl (%rcx,%rax,2), %eax
testq %rdx, %rdx
je 0xb727
movzwl (%rcx,%rdx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0xb727
testl %ebx, %ebx
cmovel %r13d, %r15d
testl $0x2000, %eax           # imm = 0x2000
cmovnel %r13d, %r15d
jmp 0xb7a9
testl %ebx, %ebx
cmovel %r13d, %r15d
cmpl %ebp, %ebx
cmovel %r13d, %r15d
jmp 0xb7a9
testw %ax, %ax
jns 0xb7a9
movb $0x0, (%r12,%r13)
movq 0x10(%rsp), %rax
movl 0x4(%rsp), %ecx
cmpl %eax, %ecx
jne 0xb792
testl %eax, %eax
leal (%rax,%rax), %eax
movl $0x2, %ecx
cmovel %ecx, %eax
movq %rax, 0x10(%rsp)
movslq %eax, %rsi
shlq $0x2, %rsi
movq 0x8(%rsp), %rdi
callq 0x21e0
movq %rax, %rbx
testq %rax, %rax
jne 0xb784
movq 0x8(%rsp), %rdi
callq 0x22c0
movq 0x18(%rsp), %rax
movq $0x0, (%rax)
movq 0x8(%rsp), %rax
testq %rbx, %rbx
movq %rax, %rdx
movl 0x4(%rsp), %ecx
jne 0xb797
jmp 0xb7f0
movq 0x8(%rsp), %rdx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x4(%rsp)
movq %rdx, 0x8(%rsp)
movl %r15d, (%rdx,%rax,4)
movsbl (%r12,%r13), %ebx
incq %r13
cmpq %r13, %r14
jne 0xb624
jmp 0xb7c4
movl $0x0, 0x4(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movl 0x4(%rsp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0xb7e1