// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
movq %rdx, %r15
movl %esi, 0xc(%rsp)
movq %rdi, %r12
movl $0x18, %edi
callq 0x2180
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movl $0x8, %edi
callq 0x2180
movq %rax, %r13
movl $0x10, %edi
callq 0x2180
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq %rax, (%r13)
movl $0x1f4, 0x8(%rax)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
movq %rbp, 0x10(%rsp)
movq %rax, (%rbx)
movl $0x0, 0xc(%rbx)
movb $0x0, (%rax)
movq %r13, (%rsp)
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
testl %ebx, %ebx
je 0x27f8f
xorl %esi, %esi
movb (%r12,%rbp), %al
testb %al, %al
je 0x27f6d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
incl %ecx
cmpb $0x0, (%r15,%rcx)
jne 0x27e52
testl %ecx, %ecx
jle 0x27e9f
movl %ecx, %ecx
movl $0x1, %edx
movb -0x1(%r15,%rdx), %dil
cmpb %al, %dil
je 0x27e7c
leaq 0x1(%rdx), %r8
cmpq %rcx, %rdx
movq %r8, %rdx
jb 0x27e66
movq (%rsp), %r13
cmpb %al, %dil
jne 0x27ea3
movq (%r13), %rax
cmpl $0x0, 0xc(%rax)
jle 0x27eb3
cmpq 0x10(%r14), %rsi
je 0x27eff
movq %r13, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0x27f0a
movq (%rsp), %r13
movsbl %al, %esi
movq %r13, %rdi
callq 0x2724c
jmp 0x27f54
movq %r13, %rdi
callq 0x27096
movl $0x8, %esi
movq %r13, %rdi
callq 0x2190
movl $0x8, %edi
callq 0x2180
movq %rax, %r13
movl $0x10, %edi
callq 0x2180
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq %rax, (%r13)
movl $0x1f4, 0x8(%rax)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
jmp 0x27f3f
movq %r14, %rdi
movq %rsp, %rdx
callq 0x29d64
movl $0x8, %edi
callq 0x2180
movq %rax, %r13
movl $0x10, %edi
callq 0x2180
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq %rax, (%r13)
movl $0x1f4, 0x8(%rax)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
movq %rax, (%rbx)
movl $0x0, 0xc(%rbx)
movb $0x0, (%rax)
movq %r13, (%rsp)
movl 0xc(%rsp), %ebx
incq %rbp
movq 0x8(%r14), %rsi
movq %rsi, %rax
subq (%r14), %rax
shrq $0x3, %rax
cmpl %ebx, %eax
jne 0x27e41
movq (%rsp), %r13
movq (%r13), %rax
cmpl $0x0, 0xc(%rax)
jle 0x27f8f
cmpq 0x10(%r14), %rsi
je 0x28010
movq %r13, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0x27fa4
movq %r13, %rdi
callq 0x27096
movl $0x8, %esi
movq %r13, %rdi
callq 0x2190
movl $0x1, %eax
movslq %ebp, %rcx
movb (%r12,%rcx), %cl
testb %cl, %cl
je 0x27ff7
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
incl %edx
cmpb $0x0, (%r15,%rdx)
jne 0x27fb9
testl %edx, %edx
jle 0x27ff7
movl %edx, %esi
movl $0x1, %edi
xorl %edx, %edx
cmpb %cl, -0x1(%r15,%rdi)
movzbl %dl, %edx
cmovel %eax, %edx
testb $0x1, %dl
jne 0x27feb
leaq 0x1(%rdi), %r8
cmpq %rsi, %rdi
movq %r8, %rdi
jb 0x27fcf
andb $0x1, %dl
movzbl %dl, %ecx
addl %ecx, %ebp
testb %cl, %cl
jne 0x27fa9
movq 0x10(%rsp), %rax
movl %ebp, (%rax)
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rdx
movq %r14, %rdi
callq 0x29d64
jmp 0x27fa4
jmp 0x28021
jmp 0x28021
movq %rax, %rbx
movl $0x8, %esi
movq %r13, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x22e0
nop