// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rcx, %r12
movq %rdx, %r14
movl %esi, 0x14(%rsp)
movq %rdi, 0x18(%rsp)
movl $0x18, %edi
callq 0x2180
movq %rax, %r15
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)
movq $0x1f4, 0x8(%rax)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
movq %rax, (%rbx)
movl $0x0, 0xc(%rbx)
movb $0x0, (%rax)
movq 0x8(%r15), %rsi
movq %rsi, %rax
subq (%r15), %rax
movq %r13, 0x8(%rsp)
shrq $0x3, %rax
xorl %ebp, %ebp
movl 0x14(%rsp), %ebx
cmpl %ebx, %eax
jne 0x28516
movq 0x18(%rsp), %r13
jmp 0x2866b
movq %r12, 0x20(%rsp)
xorl %ebp, %ebp
movl $0x1, %r12d
movq 0x18(%rsp), %r13
movb (%r13,%rbp), %al
testb %al, %al
je 0x28666
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
incl %ecx
cmpb $0x0, (%r14,%rcx)
jne 0x2853a
testl %ecx, %ecx
jle 0x28590
movl %ecx, %ecx
movl $0x1, %edi
xorl %edx, %edx
cmpb %al, -0x1(%r14,%rdi)
movzbl %dl, %edx
cmovel %r12d, %edx
testb $0x1, %dl
jne 0x2856d
leaq 0x1(%rdi), %r8
cmpq %rcx, %rdi
movq %r8, %rdi
jb 0x28550
testb $0x1, %dl
je 0x28590
movq 0x8(%rsp), %rbx
movq (%rbx), %rax
cmpl $0x0, 0xc(%rax)
jle 0x285a2
cmpq 0x10(%r15), %rsi
je 0x285ef
movq %rbx, (%rsi)
addq $0x8, 0x8(%r15)
jmp 0x285fc
movq 0x8(%rsp), %rdi
movsbl %al, %esi
callq 0x278c0
jmp 0x2864d
movq %rbx, %rdi
callq 0x27708
movl $0x8, %esi
movq %rbx, %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)
movq $0x1f4, 0x8(%rax)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
jmp 0x28632
movq %r15, %rdi
leaq 0x8(%rsp), %rdx
callq 0x2a4d0
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)
movq $0x1f4, 0x8(%rax)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
movq %rax, (%rbx)
movl $0x0, 0xc(%rbx)
movb $0x0, (%rax)
movq %r13, 0x8(%rsp)
movq 0x18(%rsp), %r13
movl 0x14(%rsp), %ebx
incq %rbp
movq 0x8(%r15), %rsi
movq %rsi, %rax
subq (%r15), %rax
shrq $0x3, %rax
cmpl %ebx, %eax
jne 0x28528
movq 0x20(%rsp), %r12
movq 0x8(%rsp), %rbx
movq (%rbx), %rax
cmpl $0x0, 0xc(%rax)
jle 0x28689
cmpq 0x10(%r15), %rsi
je 0x286a0
movq %rbx, (%rsi)
addq $0x8, 0x8(%r15)
jmp 0x286ad
movq %rbx, %rdi
callq 0x27708
movl $0x8, %esi
movq %rbx, %rdi
callq 0x2190
jmp 0x286ad
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x2a4d0
movl $0x1, %eax
movslq %ebp, %rcx
movb (%r13,%rcx), %cl
testb %cl, %cl
je 0x28705
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
incl %edx
cmpb $0x0, (%r14,%rdx)
jne 0x286c3
testl %edx, %edx
jle 0x286f7
movl %edx, %esi
movl $0x1, %edi
xorl %edx, %edx
cmpb %cl, -0x1(%r14,%rdi)
movzbl %dl, %edx
cmovel %eax, %edx
testb $0x1, %dl
jne 0x286f9
leaq 0x1(%rdi), %r8
cmpq %rsi, %rdi
movq %r8, %rdi
jb 0x286d9
jmp 0x286f9
xorl %edx, %edx
andb $0x1, %dl
movzbl %dl, %ecx
addl %ecx, %ebp
testb %cl, %cl
jne 0x286b2
movl %ebp, (%r12)
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2871f
jmp 0x2871f
movq %rax, %rbx
movl $0x8, %esi
movq %r13, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x22e0
nop