// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, -0x38(%rbp)
movl %edx, %r15d
movq %rsi, -0x48(%rbp)
movq 0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x5102(%rip), %rsi      # 0x14795
callq 0x10d0
testq %rax, %rax
je 0xfb77
movq %rax, %rbx
leaq 0x10(%rbp), %r13
leaq 0x61da(%rip), %rdi      # 0x15889
pushq $0x12
popq %r12
pushq $0x1
popq %r14
movq %r12, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x11d0
leaq 0x61d0(%rip), %rdi      # 0x1589c
pushq $0x10
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11d0
leaq 0x61cc(%rip), %rdi      # 0x158ad
pushq $0xf
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11d0
leaq 0x61c7(%rip), %rdi      # 0x158bd
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11d0
leaq 0x61c5(%rip), %rdi      # 0x158d0
pushq $0x14
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11d0
leaq 0x61c5(%rip), %rdi      # 0x158e5
pushq $0x1c
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11d0
leaq 0x61cd(%rip), %rdi      # 0x15902
pushq $0x11
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11d0
movl 0x48(%r13), %edx
leaq 0x61c6(%rip), %rsi      # 0x15914
xorl %r12d, %r12d
movq %rbx, %rdi
movl %edx, -0x3c(%rbp)
xorl %eax, %eax
callq 0x1170
movl %r15d, -0x40(%rbp)
cmpl $0x1, %r15d
leaq 0x6716(%rip), %rax      # 0x15e83
leaq 0x5364(%rip), %rdx      # 0x14ad8
cmoveq %rax, %rdx
leaq 0x619e(%rip), %rsi      # 0x1591d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1170
movl (%r13), %r15d
leaq 0x6199(%rip), %rsi      # 0x1592d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x1170
leaq 0x618d(%rip), %rdi      # 0x15935
pushq $0x6
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11d0
movq 0x18(%r13), %r13
testl %r15d, %r15d
movl $0x0, %r14d
movq %r15, -0x30(%rbp)
cmovgl %r15d, %r14d
pushq $0x2c
popq %r15
cmpq %r12, %r14
je 0xf7f6
testq %r12, %r12
je 0xf7e4
movl %r15d, %edi
movq %rbx, %rsi
callq 0x1120
movq 0x8(%r13,%r12,8), %rdi
movq %rbx, %rsi
callq 0x10b0
incq %r12
jmp 0xf7cf
leaq 0x613f(%rip), %rdi      # 0x1593c
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
movq -0x30(%rbp), %r12
addl %r12d, %r12d
subl -0x3c(%rbp), %r12d
addl $-0x3, %r12d
leaq 0x10(%rbp), %rax
movq 0x30(%rax), %r13
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
movq %r12, -0x30(%rbp)
shlq $0x4, %r12
leaq 0x610d(%rip), %r15      # 0x15947
xorl %r14d, %r14d
cmpq %r14, %r12
je 0xf86f
testq %r14, %r14
je 0xf852
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x1120
movq (%r13,%r14), %rcx
movq 0x8(%r13,%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1170
addq $0x10, %r14
jmp 0xf83d
leaq 0x60d9(%rip), %rdi      # 0x1594f
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
leaq 0x10(%rbp), %rax
movq 0x38(%rax), %r13
movl -0x30(%rbp), %r12d
xorl %r14d, %r14d
leaq 0x4ba1(%rip), %r15      # 0x1443b
cmpq %r14, %r12
je 0xf8c8
testq %r14, %r14
je 0xf8af
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x1120
movsd (%r13,%r14,8), %xmm0
movq %rbx, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x1170
incq %r14
jmp 0xf89a
cmpl $0x1, -0x40(%rbp)
jne 0xf967
leaq 0x6083(%rip), %rdi      # 0x1595c
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
xorl %eax, %eax
movq -0x38(%rbp), %rcx
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, -0x38(%rbp)
imulq $0xa8, %rcx, %r13
pushq $0x1
popq %r15
xorl %r12d, %r12d
xorl %eax, %eax
movq -0x48(%rbp), %r14
cmpq %r12, %r13
je 0xf981
cmpl $0x0, 0xa8(%r14,%r12)
jle 0xf95e
cmpl $0x1, %eax
jne 0xf92a
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x1120
movl 0x128(%r14,%r12), %edx
movl 0x12c(%r14,%r12), %ecx
movl 0x130(%r14,%r12), %r8d
movl 0x134(%r14,%r12), %r9d
movq %rbx, %rdi
leaq 0x6010(%rip), %rsi      # 0x15964
xorl %eax, %eax
callq 0x1170
movl %r15d, %eax
addq $0xa8, %r12
jmp 0xf90a
leaq 0x604c(%rip), %rdi      # 0x159ba
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
jmp 0xfb61
leaq 0x5fe8(%rip), %rdi      # 0x15970
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
movl -0x38(%rbp), %eax
movq %rax, -0x30(%rbp)
imulq $0xa8, %rax, %r15
pushq $0x1
popq %r13
xorl %r12d, %r12d
xorl %eax, %eax
cmpq %r12, %r15
je 0xfa0a
cmpl $0x0, 0xa8(%r14,%r12)
jle 0xfa01
cmpl $0x1, %eax
jne 0xf9cd
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x1120
movl 0x140(%r14,%r12), %edx
movl 0x144(%r14,%r12), %ecx
movl 0x148(%r14,%r12), %r8d
movl 0x14c(%r14,%r12), %r9d
movq %rbx, %rdi
leaq 0x5f6d(%rip), %rsi      # 0x15964
xorl %eax, %eax
callq 0x1170
movl %r13d, %eax
addq $0xa8, %r12
jmp 0xf9ad
cmpq $0x0, -0x50(%rbp)
je 0xfa6e
leaq 0x5f66(%rip), %rdi      # 0x1597e
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
xorl %r13d, %r13d
pushq $0x2c
popq %r15
leaq 0x5f56(%rip), %r12      # 0x1598a
xorl %r14d, %r14d
cmpq %r13, -0x30(%rbp)
je 0xfa6e
testb $0x1, %r14b
je 0xfa4e
movl %r15d, %edi
movq %rbx, %rsi
callq 0x1120
movq -0x50(%rbp), %rax
movsd 0x8(%rax,%r13,8), %xmm0
movb $0x1, %r14b
movq %rbx, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x1170
incq %r13
jmp 0xfa37
leaq 0x5f1c(%rip), %rdi      # 0x15991
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
imulq $0xa8, -0x30(%rbp), %r15
pushq $0x1
popq %r13
xorl %r12d, %r12d
xorl %eax, %eax
movq -0x48(%rbp), %r14
cmpq %r12, %r15
je 0xfade
movl 0xa8(%r14,%r12), %edx
testl %edx, %edx
jle 0xfad5
cmpl $0x1, %eax
jne 0xfac1
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x1120
movl 0xa8(%r14,%r12), %edx
movq %rbx, %rdi
leaq 0x570f(%rip), %rsi      # 0x151da
xorl %eax, %eax
callq 0x1170
movl %r13d, %eax
addq $0xa8, %r12
jmp 0xfa98
leaq 0x5ebb(%rip), %rdi      # 0x159a0
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11d0
imulq $0xa8, -0x30(%rbp), %r13
pushq $0x1
popq %r15
xorl %r12d, %r12d
xorl %eax, %eax
cmpq %r12, %r13
je 0xfb49
cmpl $0x0, 0xa8(%r14,%r12)
jle 0xfb40
cmpl $0x1, %eax
jne 0xfb24
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x1120
movl 0x13c(%r14,%r12), %edx
movq %rbx, %rdi
leaq 0x56a4(%rip), %rsi      # 0x151da
xorl %eax, %eax
callq 0x1170
movl %r15d, %eax
addq $0xa8, %r12
jmp 0xfb04
leaq 0x10(%rbp), %rax
movl 0x20(%rax), %edx
leaq 0x5e5a(%rip), %rsi      # 0x159b1
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1170
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1080
leaq 0x5cef(%rip), %rdi      # 0x1586d
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %rdi
callq 0x1100