// File: dcarrey[P]hgt-detection/./fonctions.cpp
// Function: saveTree(char*, InputTree, HGT*, int, int, char const*, char*, double*)
void saveTree(char * fichier,struct InputTree SpeciesTree,struct HGT *bestHGT, int addHGT,int cpt_hgt,const char *subtree,char *SCENARIO,double *bootStrap){
	
	FILE *out;
	int i, first=0;

	if ((out=fopen(fichier,"w+"))==NULL){
		printf("can't open species web file");
		exit(-1);
	}

	fprintf(out,"maptype = VERTICAL");
	fprintf(out,"\nintVerPrint = O");
	fprintf(out,"\nproportion = N");
	fprintf(out,"\ndrawRealNames = 1");
	fprintf(out,"\ncolorobject = BLACK");
	fprintf(out,"\ncolorreticulation = MAGENTA");
	fprintf(out,"\ncoloredge = BLUE");
	fprintf(out,"\nkt = %d",SpeciesTree.kt);
	fprintf(out,"\ndrawRetic = %s",(addHGT == 1)?"2":"0");
	fprintf(out,"\nn = %d",SpeciesTree.size);
	fprintf(out,"\net = ");
	for(i=1;i<=SpeciesTree.size;i++){
		if(i!=1) fprintf(out,",");
		fprintf(out,"%s",SpeciesTree.SpeciesName[i]);
	}
	fprintf(out,"\naretes = ");
	for(i=1;i<=2*SpeciesTree.size-3-SpeciesTree.kt;i++){
		if(i!=1) fprintf(out,",");
		fprintf(out,"%ld,%ld",SpeciesTree.ARETE[2*i-1],SpeciesTree.ARETE[2*i-2]);
	}
	fprintf(out,"\nlongueur = ");
	for(i=1;i<=2*SpeciesTree.size-3-SpeciesTree.kt;i++){
		if(i!=1) fprintf(out,",");
		fprintf(out,"%lf",SpeciesTree.LONGUEUR[i-1]);
	}
	if(addHGT == 1){
		fprintf(out,"\nhgt = ");
		for(i=1;i<=cpt_hgt;i++){
			if((bestHGT[i].valide >=1)/* && (bestHGT[i].trivial==0)*/){
				if(first==1) fprintf(out,","); 
				first=1;
				fprintf(out,"%d,%d,%d,%d",bestHGT[i].source_A,bestHGT[i].source_B,bestHGT[i].dest_A,bestHGT[i].dest_B);
			}
		}
		fprintf(out,"\nhgt_reels = ");
		first=0;
		for(i=1;i<=cpt_hgt;i++){
			if((bestHGT[i].valide >=1)/* && (bestHGT[i].trivial==0)*/){
				if(first==1) fprintf(out,","); 
				first=1;
				fprintf(out,"%d,%d,%d,%d",bestHGT[i].source_Ar,bestHGT[i].source_Br,bestHGT[i].dest_Ar,bestHGT[i].dest_Br);
			}
		}
		if(bootStrap != NULL){
			first=0;
			fprintf(out,"\nbootHGT = ");
			for(i=1;i<=cpt_hgt;i++){
				if(first==1) fprintf(out,","); 
				first=1;
				fprintf(out,"%1.0lf",bootStrap[i]);
			}
		}
		fprintf(out,"\nhgt_valide = ");
		first=0;
		for(i=1;i<=cpt_hgt;i++){
			if((bestHGT[i].valide >=1)/* && (bestHGT[i].trivial==0)*/){
				if(first==1) fprintf(out,","); 
				first=1;
				
				fprintf(out,"%d",bestHGT[i].valide);
			}
		}
		fprintf(out,"\nhgt_sequence = ");
		first=0;
		for(i=1;i<=cpt_hgt;i++){
			if((bestHGT[i].valide >=1)/* && (bestHGT[i].trivial==0)*/){
				if(first==1) fprintf(out,","); 
				first=1;
				fprintf(out,"%d",bestHGT[i].sequence);
			}
		}
	}
	if(addHGT == 1)
		fprintf(out,"\nroot=%d",SpeciesTree.Root);
	else
		fprintf(out,"\nroot=0");

	fclose(out);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x68(%rbp), %rax
leaq 0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x8a3d(%rip), %rsi      # 0x257c9
callq 0x10c0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x1cdb3
leaq 0x9b98(%rip), %rdi      # 0x2693a
movb $0x0, %al
callq 0x1030
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x10f0
movq -0x30(%rbp), %rdi
leaq 0x9b98(%rip), %rsi      # 0x26956
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
leaq 0x9b99(%rip), %rsi      # 0x26969
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
leaq 0x9b98(%rip), %rsi      # 0x2697a
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
leaq 0x9b96(%rip), %rsi      # 0x2698a
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
leaq 0x9b97(%rip), %rsi      # 0x2699d
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
leaq 0x9b9a(%rip), %rsi      # 0x269b2
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
leaq 0x9ba5(%rip), %rsi      # 0x269cf
movb $0x0, %al
callq 0x1140
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rdi
movl 0x48(%rax), %edx
leaq 0x9b9e(%rip), %rsi      # 0x269e1
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0x1ce65
leaq 0xa1e0(%rip), %rax      # 0x2703f
movq %rax, -0x50(%rbp)
jmp 0x1ce72
leaq 0x8cb8(%rip), %rax      # 0x25b24
movq %rax, -0x50(%rbp)
jmp 0x1ce72
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0x9b69(%rip), %rsi      # 0x269ea
movb $0x0, %al
callq 0x1140
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rdi
movl (%rax), %edx
leaq 0x9b61(%rip), %rsi      # 0x269fa
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
leaq 0x9b57(%rip), %rsi      # 0x26a02
movb $0x0, %al
callq 0x1140
movl $0x1, -0x34(%rbp)
movq -0x40(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jg 0x1cf09
cmpl $0x1, -0x34(%rbp)
je 0x1cedc
movq -0x30(%rbp), %rdi
leaq 0x89c2(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rdi
movq 0x18(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x95d2(%rip), %rsi      # 0x264c9
movb $0x0, %al
callq 0x1140
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1ceb9
movq -0x30(%rbp), %rdi
leaq 0x9af5(%rip), %rsi      # 0x26a09
movb $0x0, %al
callq 0x1140
movl $0x1, -0x34(%rbp)
movq -0x40(%rbp), %rdx
movl -0x34(%rbp), %eax
movl (%rdx), %ecx
shll %ecx
subl $0x3, %ecx
subl 0x48(%rdx), %ecx
cmpl %ecx, %eax
jg 0x1cf96
cmpl $0x1, -0x34(%rbp)
je 0x1cf4f
movq -0x30(%rbp), %rdi
leaq 0x894f(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rdi
movq 0x30(%rax), %rcx
movl -0x34(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rdx
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x9a90(%rip), %rsi      # 0x26a14
movb $0x0, %al
callq 0x1140
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1cf22
movq -0x30(%rbp), %rdi
leaq 0x9a7b(%rip), %rsi      # 0x26a1c
movb $0x0, %al
callq 0x1140
movl $0x1, -0x34(%rbp)
movq -0x40(%rbp), %rdx
movl -0x34(%rbp), %eax
movl (%rdx), %ecx
shll %ecx
subl $0x3, %ecx
subl 0x48(%rdx), %ecx
cmpl %ecx, %eax
jg 0x1d00f
cmpl $0x1, -0x34(%rbp)
je 0x1cfdc
movq -0x30(%rbp), %rdi
leaq 0x88c2(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rdi
movq 0x38(%rax), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0x841e(%rip), %rsi      # 0x2541b
movb $0x1, %al
callq 0x1140
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1cfaf
cmpl $0x1, -0x14(%rbp)
jne 0x1d388
movq -0x30(%rbp), %rdi
leaq 0x9a05(%rip), %rsi      # 0x26a29
movb $0x0, %al
callq 0x1140
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x1d0fc
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jl 0x1d0ec
cmpl $0x1, -0x38(%rbp)
jne 0x1d071
movq -0x30(%rbp), %rdi
leaq 0x882d(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movl $0x1, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x80(%rax), %edx
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x84(%rax), %ecx
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rsi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0x88(%rax), %r8d
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rsi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0x8c(%rax), %r9d
leaq 0x994c(%rip), %rsi      # 0x26a31
movb $0x0, %al
callq 0x1140
jmp 0x1d0ee
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d032
movq -0x30(%rbp), %rdi
leaq 0x9936(%rip), %rsi      # 0x26a3d
movb $0x0, %al
callq 0x1140
movl $0x0, -0x38(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x1d1e6
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jl 0x1d1d6
cmpl $0x1, -0x38(%rbp)
jne 0x1d15b
movq -0x30(%rbp), %rdi
leaq 0x8743(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movl $0x1, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x98(%rax), %edx
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x9c(%rax), %ecx
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rsi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0xa0(%rax), %r8d
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rsi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0xa4(%rax), %r9d
leaq 0x9862(%rip), %rsi      # 0x26a31
movb $0x0, %al
callq 0x1140
jmp 0x1d1d8
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d11c
cmpq $0x0, 0x68(%rbp)
je 0x1d260
movl $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x984c(%rip), %rsi      # 0x26a4b
movb $0x0, %al
callq 0x1140
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x1d25e
cmpl $0x1, -0x38(%rbp)
jne 0x1d22d
movq -0x30(%rbp), %rdi
leaq 0x8671(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movl $0x1, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq 0x68(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0x980b(%rip), %rsi      # 0x26a57
movb $0x1, %al
callq 0x1140
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d20d
jmp 0x1d260
movq -0x30(%rbp), %rdi
leaq 0x97f3(%rip), %rsi      # 0x26a5e
movb $0x0, %al
callq 0x1140
movl $0x0, -0x38(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x1d2f1
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jl 0x1d2e4
cmpl $0x1, -0x38(%rbp)
jne 0x1d2b7
movq -0x30(%rbp), %rdi
leaq 0x85e7(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movl $0x1, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
leaq 0x8fa2(%rip), %rsi      # 0x2627f
movb $0x0, %al
callq 0x1140
jmp 0x1d2e6
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d280
movq -0x30(%rbp), %rdi
leaq 0x9771(%rip), %rsi      # 0x26a6d
movb $0x0, %al
callq 0x1140
movl $0x0, -0x38(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x1d386
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jl 0x1d379
cmpl $0x1, -0x38(%rbp)
jne 0x1d348
movq -0x30(%rbp), %rdi
leaq 0x8556(%rip), %rsi      # 0x25897
movb $0x0, %al
callq 0x1140
movl $0x1, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x94(%rax), %edx
leaq 0x8f0d(%rip), %rsi      # 0x2627f
movb $0x0, %al
callq 0x1140
jmp 0x1d37b
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d311
jmp 0x1d388
cmpl $0x1, -0x14(%rbp)
jne 0x1d3a9
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rdi
movl 0x20(%rax), %edx
leaq 0x96de(%rip), %rsi      # 0x26a7e
movb $0x0, %al
callq 0x1140
jmp 0x1d3bb
movq -0x30(%rbp), %rdi
leaq 0x96d3(%rip), %rsi      # 0x26a87
movb $0x0, %al
callq 0x1140
movq -0x30(%rbp), %rdi
callq 0x1090
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)