// File: /workspace/github_cpp_makefile_star2_O2/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 0x30f0
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x3350
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x776c
leaq 0x28(%rsp), %rdi
callq 0x3120
leaq 0x8(%rsp), %rdi
callq 0x3120
pushq $0x3
popq %rax
xorl %ebp, %ebp
cmpq $0x102, %rax            # imm = 0x102
je 0x85b4
cmpq $0x1, (%rbx,%rax,8)
sbbb $-0x1, %bpl
incq %rax
jmp 0x859e
movq 0x810(%rbx), %r12
movq %r14, %rdi
callq 0x3110
leaq 0xa(%rax), %rdi
callq 0x3040
movq %rax, %r15
leaq 0x2506(%rip), %rsi      # 0xaadc
leaq 0x3000(%rip), %rcx      # 0xb5dd
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3060
leaq 0x24f0(%rip), %rsi      # 0xaae1
movq %r15, %rdi
callq 0x32c0
testq %rax, %rax
je 0x8703
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)
pushq $0x8
popq %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r14, %rcx
callq 0x3490
pushq $0x4
popq %rsi
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3490
movsbl %bpl, %ebp
movl %ebp, %edi
movq %r14, %rsi
callq 0x32f0
movq %r14, %rdi
callq 0x3280
movq %r15, %rdi
callq 0x3310
movq 0x7988(%rip), %r14      # 0xfff0
leaq 0x2cb9(%rip), %rsi      # 0xb328
movq %r14, %rdi
callq 0x3270
movzbl (%rbx), %esi
movq %rax, %rdi
callq 0x3430
movq %rax, %rdi
callq 0x3130
leaq 0x2cc2(%rip), %rsi      # 0xb353
movq %r14, %rdi
callq 0x3270
movl 0x10(%rbx), %esi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3130
leaq 0x2d26(%rip), %rsi      # 0xb3d9
movq %r14, %rdi
callq 0x3270
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3130
leaq 0x2cdd(%rip), %rsi      # 0xb3b3
movq %r14, %rdi
callq 0x3270
movzbl %bpl, %esi
movq %rax, %rdi
callq 0x3430
movq %rax, %rdi
callq 0x3130
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x78e6(%rip), %rdi      # 0xfff0
leaq 0x2bd7(%rip), %rsi      # 0xb2e8
callq 0x3270
movq %rax, %rdi
movq %r15, %rsi
callq 0x3270
movq %rax, %rdi
callq 0x3130
pushq $0x1
popq %rdi
callq 0x32e0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3120
jmp 0x8743
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3450
nop