// File: /workspace/github_cpp_makefile_star2_O3/giovannarosone[P]BCR_LCP_GSA/TransposeFasta.cpp
// Function: TransposeFasta::convertFromCycFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool TransposeFasta::convertFromCycFile(const string& input, char const * fileOutput, string BCRprefPrev) {

	int res=true;
	res=findLengthNseq(input, fileOutput, BCRprefPrev);
	if (res == false) {  //Error in the reading
		std::cerr << "Error in transpose findLengthNseq! \n";
		exit (EXIT_FAILURE);
	}

  	//TO DO
	//The distribution of characters is useful
	//for alpha[SIZE_ALPHA] -->Corresponding between the alphabet, the piles and tableOcc
	//and to know sizeAlpha

	//lengthTexts = lengthRead * nSeq;
	
		dataTypedimAlpha sizeAlpha=0;
	for (dataTypedimAlpha i = 0; i < SIZE_ALPHA-1; ++i)
		if (freq[i] > 0) {
			sizeAlpha++;
		}
	if (freq[SIZE_ALPHA-1] > 0) {		
		sizeAlpha++;
	}
	
	char *fnAux = new char[strlen(fileOutput)+10];
	sprintf (fnAux,"%s%s",fileOutput,".info\0");
	FILE* OutFile = fopen(fnAux, "wb");
	if (OutFile==NULL) {
		std::cerr << "TransposeFasta: (lengthBWT+NSequences+sizeAlpha) Error opening " << fnAux << std::endl;
		exit (EXIT_FAILURE);
	}
	
	dataTypeNChar lenTot=lengthTexts+nSeq;
	fwrite(&lenTot,sizeof(dataTypeNChar),1,OutFile);
	fwrite(&nSeq,sizeof(dataTypeNSeq),1,OutFile);
	fwrite(&sizeAlpha,sizeof(dataTypedimAlpha),1,OutFile);
	fclose(OutFile);
	delete [] fnAux;
	
	cerr << "TransposeFasta: The max length (Read) is: " << (int)lengthRead << endl;
	cerr << "TransposeFasta: Number of reads: " << nSeq << endl;
	cerr << "TransposeFasta: Number of chars: " << 	lengthTexts << endl;	
	cerr << "TransposeFasta: Size Alpha: " << 	(int)sizeAlpha << endl;
	
	
	
	
	
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
movq %r14, %rsi
callq 0x3100
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x3fce
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x82f0
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x95fe
callq 0x3260
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9611
callq 0x3260
movl $0x3, %eax
xorl %ebp, %ebp
cmpq $0x1, (%rbx,%rax,8)
sbbb $-0x1, %bpl
incq %rax
cmpq $0x102, %rax            # imm = 0x102
jne 0x9618
movq 0x810(%rbx), %r12
movq %r14, %rdi
callq 0x3120
leaq 0xa(%rax), %rdi
callq 0x3040
movq %rax, %r15
leaq 0x34b6(%rip), %rsi      # 0xcb04
leaq 0x3fb0(%rip), %rcx      # 0xd605
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3070
leaq 0x34a0(%rip), %rsi      # 0xcb09
movq %r15, %rdi
callq 0x32e0
testq %rax, %rax
je 0x981b
movq %rax, %r14
cmpq $0x1, %r12
sbbb $-0x1, %bpl
leaq 0x10(%rbx), %r12
movl 0x10(%rbx), %eax
addq 0x8(%rbx), %rax
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x34c0
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x34c0
movsbl %bpl, %ebp
movl %ebp, %edi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x32a0
movq %r15, %rdi
callq 0x3330
movq 0x790c(%rip), %r14      # 0x10ff0
leaq 0x3c65(%rip), %rsi      # 0xd350
movl $0x2a, %edx
movq %r14, %rdi
callq 0x32d0
movzbl (%rbx), %esi
movq %r14, %rdi
callq 0x3440
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3050
movq %rax, %rdi
callq 0x31e0
leaq 0x3c47(%rip), %rsi      # 0xd37b
movl $0x21, %edx
movq %r14, %rdi
callq 0x32d0
movl 0x10(%rbx), %esi
movq %r14, %rdi
callq 0x31d0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3050
movq %rax, %rdi
callq 0x31e0
leaq 0x3c84(%rip), %rsi      # 0xd401
movl $0x21, %edx
movq %r14, %rdi
callq 0x32d0
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x31d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3050
movq %rax, %rdi
callq 0x31e0
leaq 0x3c14(%rip), %rsi      # 0xd3db
movl $0x1c, %edx
movq %r14, %rdi
callq 0x32d0
movzbl %bpl, %esi
movq %r14, %rdi
callq 0x3440
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3050
movq %rax, %rdi
callq 0x31e0
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x77ce(%rip), %rdi      # 0x10ff0
leaq 0x3ae7(%rip), %rsi      # 0xd310
callq 0x3290
movq %rax, %rdi
movq %r15, %rsi
callq 0x3290
movq %rax, %rdi
callq 0x3140
movl $0x1, %edi
callq 0x3300
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x9862
callq 0x3260
jmp 0x9862
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9875
callq 0x3260
movq %rbx, %rdi
callq 0x3460
nop