// File: /workspace/github_c_makefile_star2_O0/Astor-Bizard[P]ProjetS5_Groupe2/src/correctionSymboles.c
// Function: applySymbolsCorrections
ListeSymboles applySymbolsCorrections(FILE* oldFile, Elf32_Ehdr oldElfHeader, Elf32_Ehdr newElfHeader, SectionsHeadersList oldSHList, SectionsHeadersList newSHList, ListeSymboles oldSymbolsTable, int silent) {
	int i, j;
	char* originalName;
	ListeSymboles newSymbolsTable;
	
	// Allocation de la nouvelle table des symboles, de la même longueur de l'ancienne
	newSymbolsTable.symboles = (Elf32_Sym*) malloc(sizeof(Elf32_Sym)*oldSymbolsTable.nbSymboles);
	if(newSymbolsTable.symboles == NULL)
	{
		printf("Erreur d'allocation\n");
		exit(1);
	}

	// Copie et correction de oldSymbolsTable vers newSymbolsTable
	i = index_Shdr(".symtab", oldSHList);
	newSymbolsTable.names = fetchSymbolNames(oldFile, oldSHList, i);
	for(j=0; j<oldSymbolsTable.nbSymboles; j++)
	{
		newSymbolsTable.symboles[j].st_name = oldSymbolsTable.symboles[j].st_name;
		newSymbolsTable.symboles[j].st_size = oldSymbolsTable.symboles[j].st_size;
		newSymbolsTable.symboles[j].st_info = oldSymbolsTable.symboles[j].st_info;
		newSymbolsTable.symboles[j].st_other = oldSymbolsTable.symboles[j].st_other;

		// Recherche du nouvel id de la section du symbole courant
		if (oldSymbolsTable.symboles[j].st_shndx==0) {
			newSymbolsTable.symboles[j].st_shndx = 0;
		}
		else if(oldSymbolsTable.symboles[j].st_shndx>65520){
			newSymbolsTable.symboles[j].st_shndx = oldSymbolsTable.symboles[j].st_shndx;
			newSymbolsTable.symboles[j].st_value = 0;
			continue;
		}
		else {
			originalName = getSectionNameBis(oldSHList.names, oldSHList.headers[oldSymbolsTable.symboles[j].st_shndx]); 
			newSymbolsTable.symboles[j].st_shndx = index_Shdr(originalName, newSHList);
			free(originalName);
		}
		if(newSymbolsTable.symboles[j].st_shndx==65535) {
			newSymbolsTable.symboles[j].st_shndx = 0;
			newSymbolsTable.symboles[j].st_value = 0;
			continue;
		}
		// Nouvelle valeur du symbole = Ancienne valeur + Adresse de la section parente
		newSymbolsTable.symboles[j].st_value = oldSymbolsTable.symboles[j].st_value + newSHList.headers[newSymbolsTable.symboles[j].st_shndx].sh_addr;
	}
	newSymbolsTable.nbSymboles = j;

	// Affichage si necessaire
	if (!silent)
		afficherTableSymboles(newSymbolsTable, newElfHeader);

	return newSymbolsTable;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x50(%rbp)
movq %rdi, -0x78(%rbp)
leaq 0xb0(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq 0x98(%rbp), %rcx
movq %rcx, -0x68(%rbp)
leaq 0x80(%rbp), %rcx
movq %rcx, -0x60(%rbp)
leaq 0x48(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movq %rsi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movslq 0x10(%rax), %rdi
shlq $0x4, %rdi
callq 0x10f0
movq -0x50(%rbp), %rdi
movq %rax, (%rdi)
cmpq $0x0, (%rdi)
jne 0x5565
leaq 0x26c2(%rip), %rdi      # 0x7c16
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1150
movq -0x60(%rbp), %rax
leaq 0x2684(%rip), %rdi      # 0x7bf4
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x3110
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x3b40
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x14(%rbp)
movq -0x70(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x5859
movq -0x70(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax), %rdx
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movl (%rdx), %esi
movq (%rcx), %rdx
movslq -0x14(%rbp), %rdi
shlq $0x4, %rdi
addq %rdi, %rdx
movl %esi, (%rdx)
movq (%rax), %rdx
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movl 0x8(%rdx), %esi
movq (%rcx), %rdx
movslq -0x14(%rbp), %rdi
shlq $0x4, %rdi
addq %rdi, %rdx
movl %esi, 0x8(%rdx)
movq (%rax), %rdx
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movb 0xc(%rdx), %sil
movq (%rcx), %rdx
movslq -0x14(%rbp), %rdi
shlq $0x4, %rdi
addq %rdi, %rdx
movb %sil, 0xc(%rdx)
movq (%rax), %rdx
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movb 0xd(%rdx), %dl
movq (%rcx), %rcx
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rcx
movb %dl, 0xd(%rcx)
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0xe(%rax), %eax
cmpl $0x0, %eax
jne 0x56a2
movq -0x50(%rbp), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movw $0x0, 0xe(%rax)
jmp 0x57b2
movq -0x70(%rbp), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0xe(%rax), %eax
cmpl $0xfff0, %eax           # imm = 0xFFF0
jle 0x5705
movq -0x50(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x14(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movw 0xe(%rcx), %dx
movq (%rax), %rcx
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rcx
movw %dx, 0xe(%rcx)
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x0, 0x4(%rax)
jmp 0x584b
movq -0x70(%rbp), %rax
movq -0x60(%rbp), %rcx
movq 0x8(%rcx), %rdx
movq %rdx, -0x80(%rbp)
movq (%rcx), %rsi
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0xe(%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq -0x48(%rbp), %rdi
movl $0x28, %edx
callq 0x10e0
movq -0x80(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2750
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x3110
movl %eax, %ecx
movq -0x50(%rbp), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0xe(%rax)
movq -0x20(%rbp), %rdi
callq 0x1030
jmp 0x57b2
movq -0x50(%rbp), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0xe(%rax), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x57fe
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movslq -0x14(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movw $0x0, 0xe(%rcx)
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x0, 0x4(%rax)
jmp 0x584b
movq -0x50(%rbp), %rax
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rcx
movl 0x4(%rcx), %ecx
movq (%rdx), %rdx
movq (%rax), %rsi
movslq -0x14(%rbp), %rdi
shlq $0x4, %rdi
addq %rdi, %rsi
movzwl 0xe(%rsi), %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rdx
addl 0xc(%rdx), %ecx
movq (%rax), %rax
movslq -0x14(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x55ce
movq -0x50(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, 0x10(%rax)
cmpl $0x0, -0xc(%rbp)
jne 0x58a4
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %rdx
movl 0x30(%rdx), %esi
movq %rsp, %rax
movl %esi, 0x48(%rax)
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movups %xmm2, 0x38(%rax)
movups %xmm1, 0x28(%rax)
movups %xmm0, 0x18(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movups (%rcx), %xmm0
movups %xmm0, (%rax)
callq 0x3c20
movq -0x78(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)