// File: 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:
subq $0xd8, %rsp
movq %rcx, 0x10(%rsp)
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
movq %rcx, 0xb8(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x1, 0xb4(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x34b0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x90(%rsp), %rdi
callq 0x3370
jmp 0x10ed9
movq 0x10(%rsp), %rsi
leaq 0x58(%rsp), %rdi
callq 0x3110
jmp 0x10eea
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
leaq 0x90(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0xf080
movb %al, 0xf(%rsp)
jmp 0x10f0c
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0xb4(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x3180
leaq 0x90(%rsp), %rdi
callq 0x3180
leaq 0x8f(%rsp), %rdi
callq 0x32b0
cmpl $0x0, 0xb4(%rsp)
jne 0x10fc7
movq 0xf09f(%rip), %rdi      # 0x1fff0
leaq 0x83f3(%rip), %rsi      # 0x1934b
callq 0x3260
movl $0x1, %edi
callq 0x3300
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x10fb5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x10fa8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x3180
leaq 0x90(%rsp), %rdi
callq 0x3180
leaq 0x8f(%rsp), %rdi
callq 0x32b0
jmp 0x1120c
movb $0x0, 0x57(%rsp)
movb $0x0, 0x56(%rsp)
movzbl 0x56(%rsp), %eax
cmpl $0xff, %eax
jge 0x11007
movq 0x18(%rsp), %rax
movzbl 0x56(%rsp), %ecx
cmpq $0x0, 0x18(%rax,%rcx,8)
jbe 0x10ff9
movb 0x57(%rsp), %al
addb $0x1, %al
movb %al, 0x57(%rsp)
jmp 0x10ffb
movb 0x56(%rsp), %al
addb $0x1, %al
movb %al, 0x56(%rsp)
jmp 0x10fd1
movq 0x18(%rsp), %rax
cmpq $0x0, 0x810(%rax)
jbe 0x11020
movb 0x57(%rsp), %al
addb $0x1, %al
movb %al, 0x57(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x3120
movq %rax, %rdi
addq $0xa, %rdi
callq 0x3040
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movq 0xc0(%rsp), %rdx
leaq 0x7bcc(%rip), %rsi      # 0x18c1e
leaq 0x8711(%rip), %rcx      # 0x1976a
movb $0x0, %al
callq 0x3060
movq 0x48(%rsp), %rdi
leaq 0x7a75(%rip), %rsi      # 0x18ae1
callq 0x32e0
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x110b7
movq 0xef6b(%rip), %rdi      # 0x1fff0
leaq 0x83e9(%rip), %rsi      # 0x19475
callq 0x3260
movq %rax, %rdi
movq 0x48(%rsp), %rsi
callq 0x3260
movq %rax, %rdi
movq 0xef18(%rip), %rsi      # 0x1ffc0
callq 0x32a0
movl $0x1, %edi
callq 0x3300
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rax
movl 0x10(%rcx), %ecx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rcx
leaq 0x38(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x3510
movq 0x18(%rsp), %rdi
addq $0x10, %rdi
movq 0x40(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x3510
movq 0x40(%rsp), %rcx
leaq 0x57(%rsp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x3510
movq 0x40(%rsp), %rdi
callq 0x3270
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x1113a
movq (%rsp), %rdi
callq 0x3330
movq 0xeeaf(%rip), %rdi      # 0x1fff0
leaq 0x836d(%rip), %rsi      # 0x194b5
callq 0x3260
movq %rax, %rdi
movq 0x18(%rsp), %rax
movzbl (%rax), %esi
callq 0x3480
movq %rax, %rdi
movq 0xee59(%rip), %rsi      # 0x1ffc0
callq 0x32a0
movq 0xee7d(%rip), %rdi      # 0x1fff0
leaq 0x8366(%rip), %rsi      # 0x194e0
callq 0x3260
movq %rax, %rdi
movq 0x18(%rsp), %rax
movl 0x10(%rax), %esi
callq 0x3350
movq %rax, %rdi
movq 0xee27(%rip), %rsi      # 0x1ffc0
callq 0x32a0
movq 0xee4b(%rip), %rdi      # 0x1fff0
leaq 0x83ba(%rip), %rsi      # 0x19566
callq 0x3260
movq %rax, %rdi
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x3090
movq %rax, %rdi
movq 0xedf4(%rip), %rsi      # 0x1ffc0
callq 0x32a0
movq 0xee18(%rip), %rdi      # 0x1fff0
leaq 0x8361(%rip), %rsi      # 0x19540
callq 0x3260
movq %rax, %rdi
movzbl 0x57(%rsp), %esi
callq 0x3480
movq %rax, %rdi
movq 0xedc5(%rip), %rsi      # 0x1ffc0
callq 0x32a0
movb $0x1, %al
andb $0x1, %al
addq $0xd8, %rsp
retq
movq 0x80(%rsp), %rdi
callq 0x34a0
nopl (%rax)