// File: /workspace/github_cpp_makefile_star2_O2/gersteinlab[P]MUSIC/src/ms_ansi_string.cpp
// Function: t_string::get_first_n_tokens(char*, int, char const*, int&)
vector<t_string*>* t_string::get_first_n_tokens(char* string, int n_tokens, const char* delimiter_list, int& i_next_char)
{
	vector<t_string*>* first_tokens = new vector<t_string*>();
	
	// This is the pointer to the next character in the string.
	int i_s = 0;

	// Process the next character.
	t_string* next_token = new t_string();
	while((int)first_tokens->size() != n_tokens &&
		string[i_s] != 0)
	{
		bool is_delim = false;
		int n_delimiters = t_string::string_length(delimiter_list);
		for(int i_d = 0; 
			!is_delim && i_d < n_delimiters; 
			i_d++)
		{
			if(delimiter_list[i_d] == string[i_s])
			{
				is_delim = true;
			}
		} // i_d loop.

		// This is not a delimiter.
		if(!is_delim)
		{
			next_token->concat_char(string[i_s]);
		} // delimiter check.
		else
		{
			// If this token contains characters, add it.
			if(next_token->length() > 0)
			{
				// Add the next token.
				first_tokens->push_back(next_token);

				// Reallocate the next token.
				next_token = new t_string();
			}
			else
			{
				delete(next_token);
				next_token = new t_string();
			}
		}

		//fprintf(stderr, "Procesing %d: %d. tokens: %s\n", i_s, first_tokens->size(), next_token->str());
		i_s++;
	} // token addition loop.

	// If the next token was generated for the last string in the string, add it to the list of tokens.
	// This is not added because the token adding is done per delimiter character.
	if(next_token->length() > 0)
	{
		first_tokens->push_back(next_token);
	}
	else
	{
		delete(next_token);
	}

	// Skip over all the delimiters.	
	bool is_delim = true;
	while(is_delim && string[i_s] != 0)
	{
		is_delim = false;

		int n_delimiters = t_string::string_length(delimiter_list);
		for(int i_d = 0; 
			!is_delim && i_d < n_delimiters; 
			i_d++)
		{
			if(delimiter_list[i_d] == string[i_s])
			{
				is_delim = true;
			}
		} // i_d loop.

		if(is_delim)
		{
			i_s++;
		}
	} // delimiter skipping loop.

	// Next character is the index of next character in the string, which is a delimiter.
	i_next_char = i_s;

	return(first_tokens);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r13
movq %rdx, %r14
movl %esi, 0xc(%rsp)
movq %rdi, %r15
pushq $0x18
popq %rdi
callq 0x2170
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %rbx
movq %rax, %rdi
callq 0x20cd8
movq %r13, 0x10(%rsp)
movq %rsp, %rax
movq %rbx, (%rax)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %ebx, %ebx
subq %rax, %rcx
shrq $0x3, %rcx
cmpl 0xc(%rsp), %ecx
je 0x21dcb
movb (%r15,%rbx), %bpl
testb %bpl, %bpl
je 0x21dcb
movq %r14, %rdi
callq 0x20d90
cltq
xorl %ecx, %ecx
xorl %edx, %edx
testb $0x1, %dl
jne 0x21d4b
cmpq %rax, %rcx
jge 0x21d4b
cmpb %bpl, (%r14,%rcx)
sete %dl
incq %rcx
jmp 0x21d35
movq (%rsp), %r13
testb $0x1, %dl
je 0x21d7e
movq (%r13), %rax
cmpl $0x0, 0xc(%rax)
jle 0x21d8c
movq %r12, %rdi
movq %rsp, %rsi
callq 0x22cbc
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %r13
movq %rax, %rdi
callq 0x20cd8
jmp 0x21db6
movsbl %bpl, %esi
movq %r13, %rdi
callq 0x213f4
jmp 0x21dba
movq %r13, %rdi
callq 0x212b2
movq %r13, %rdi
pushq $0x8
popq %r13
movq %r13, %rsi
callq 0x2180
movq %r13, %rdi
callq 0x2170
movq %rax, %r13
movq %rax, %rdi
callq 0x20cd8
movq %r13, (%rsp)
incq %rbx
movq (%r12), %rax
movq 0x8(%r12), %rcx
jmp 0x21d09
movq (%rsp), %r13
movq (%r13), %rax
cmpl $0x0, 0xc(%rax)
jle 0x21de6
movq %rsp, %rsi
movq %r12, %rdi
callq 0x22cbc
jmp 0x21df9
movq %r13, %rdi
callq 0x212b2
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x2180
movb $0x1, %al
pushq $0x1
popq %rbp
testb $0x1, %al
je 0x21e40
movl %ebx, %eax
movb (%r15,%rax), %r13b
testb %r13b, %r13b
je 0x21e40
movq %r14, %rdi
callq 0x20d90
movslq %eax, %rcx
xorl %edx, %edx
xorl %eax, %eax
testb $0x1, %al
jne 0x21e34
cmpq %rcx, %rdx
jge 0x21e34
cmpb %r13b, (%r14,%rdx)
movzbl %al, %eax
cmovel %ebp, %eax
incq %rdx
jmp 0x21e1c
movl %eax, %ecx
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %ebx
jmp 0x21dfe
movq 0x10(%rsp), %rax
movl %ebx, (%rax)
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
pushq $0x8
popq %rsi
movq %rbx, %rdi
jmp 0x21e6f
jmp 0x21e66
movq %rax, %r14
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x2180
movq %r14, %rdi
callq 0x22d0