// File: /workspace/github_c_makefile_star2_O3/Astor-Bizard[P]ProjetS5_Groupe2/src/lectureST.c
// Function: lectureSymbolTab
ListeSymboles lectureSymbolTab(FILE *f, Elf32_Ehdr elfHeader, SectionsHeadersList shList, int silent)
{
	uint32_t sectionSymbolTabSize;
	uint32_t sectionSymbolTabOffset;
	int i = 0;
	int j = 0;
	ListeSymboles listeSymboles;

	char* nomSection = getSectionNameBis(shList.names, shList.headers[i]);
	while(i<shList.size && strcmp(nomSection, ".symtab"))
	{
		free(nomSection);
		i++;
		nomSection = getSectionNameBis(shList.names, shList.headers[i]);
	}
	if(i==shList.size){
		listeSymboles.symboles=NULL;
		listeSymboles.names=NULL;
		listeSymboles.nbSymboles=0;
		printf("Pas de table de symboles\n");
		return listeSymboles;
	}
	free(nomSection);
	sectionSymbolTabSize = shList.headers[i].sh_size;
	sectionSymbolTabOffset = shList.headers[i].sh_offset;

	listeSymboles.symboles = (Elf32_Sym*) malloc(sizeof(Elf32_Sym)*(sectionSymbolTabSize/16));
	if(listeSymboles.symboles == NULL)
	{
		printf("Erreur d'allocation\n");
		listeSymboles.symboles = NULL;
		listeSymboles.names = NULL;
		listeSymboles.nbSymboles = 0;
		return listeSymboles;
	}
	listeSymboles.names = fetchSymbolNames(f, shList, i);

	fseek(f, sectionSymbolTabOffset, SEEK_SET);
	for(i = 0; i<sectionSymbolTabSize; i=i+16)
	{
		listeSymboles.symboles[j].st_name = (uint32_t) lire_octets(elfHeader.e_ident[EI_DATA], f, 4);
		listeSymboles.symboles[j].st_value = (Elf32_Addr) lire_octets(elfHeader.e_ident[EI_DATA], f, 4);
		listeSymboles.symboles[j].st_size = (uint32_t) lire_octets(elfHeader.e_ident[EI_DATA], f, 4);
		listeSymboles.symboles[j].st_info = (unsigned char) lire_octets(elfHeader.e_ident[EI_DATA], f, 1);
		listeSymboles.symboles[j].st_other = (unsigned char) lire_octets(elfHeader.e_ident[EI_DATA], f, 1);
		listeSymboles.symboles[j].st_shndx = (uint16_t) lire_octets(elfHeader.e_ident[EI_DATA], f, 2);
		j++;
	}
	listeSymboles.nbSymboles = j;

	if (!silent)
		afficherTableSymboles(listeSymboles, elfHeader);

	return listeSymboles;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, 0x5c(%rsp)
movq %rsi, %r14
movq %rdi, 0x50(%rsp)
movq 0x108(%rsp), %r12
movq 0x110(%rsp), %r15
movq 0x20(%r12), %rax
movq %rax, 0x80(%rsp)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movaps %xmm1, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x60(%rsp), %xmm0
movaps 0x70(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x1e35
movq %rax, %r13
movslq 0x118(%rsp), %rbx
testq %rbx, %rbx
movq %r12, 0x90(%rsp)
jle 0x28b9
leaq 0x28(%r12), %rbp
xorl %r12d, %r12d
movq %r13, %rdi
leaq 0x248c(%rip), %rsi      # 0x4cdd
callq 0x10b0
testl %eax, %eax
je 0x28bc
movq %r13, %rdi
callq 0x1030
incq %r12
movq 0x20(%rbp), %rax
movq %rax, 0x80(%rsp)
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movaps %xmm1, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x60(%rsp), %xmm0
movaps 0x70(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x1e35
movq %rax, %r13
addq $0x28, %rbp
cmpq %r12, %rbx
jne 0x2847
jmp 0x28c1
xorl %r12d, %r12d
cmpl %ebx, %r12d
jne 0x28f4
xorps %xmm0, %xmm0
movq 0x50(%rsp), %rbx
movups %xmm0, (%rbx)
movl $0x0, 0x10(%rbx)
leaq 0x24b5(%rip), %rdi      # 0x4d8f
callq 0x1060
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x1030
movl %r12d, %eax
leaq (%rax,%rax,4), %rax
movq 0x90(%rsp), %rcx
movl 0x10(%rcx,%rax,8), %r13d
movl 0x14(%rcx,%rax,8), %ebp
movl %ebp, %edi
andl $-0x10, %edi
callq 0x10d0
movq 0x50(%rsp), %rbx
movq %rax, (%rbx)
testq %rax, %rax
je 0x2a74
movq %rax, %r15
leaq 0x108(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movups (%rax), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
movl %r12d, %esi
callq 0x2a92
movq %rax, 0x8(%rbx)
xorl %ebx, %ebx
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x10e0
testl %ebp, %ebp
je 0x2a1b
decl %ebp
movl %ebp, %ebx
shrl $0x4, %ebx
incl %ebx
andl $-0x10, %ebp
addq $0x10, %rbp
xorl %r13d, %r13d
leaq 0xd0(%rsp), %rax
movsbl 0x5(%rax), %r12d
movl %r12d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, (%r15,%r13)
movl %r12d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, 0x4(%r15,%r13)
movl %r12d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, 0x8(%r15,%r13)
movl %r12d, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x168c
movb %al, 0xc(%r15,%r13)
movl %r12d, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x168c
movb %al, 0xd(%r15,%r13)
movl %r12d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0xe(%r15,%r13)
addq $0x10, %r13
cmpq %r13, %rbp
jne 0x2990
movq 0x50(%rsp), %rax
movl %ebx, 0x10(%rax)
movq %rax, %rbx
cmpl $0x0, 0x5c(%rsp)
jne 0x28df
leaq 0xd0(%rsp), %rcx
movl 0x30(%rcx), %eax
movl %eax, 0x48(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x38(%rsp)
movups %xmm1, 0x28(%rsp)
movups %xmm0, 0x18(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x2b12
jmp 0x28df
leaq 0x2300(%rip), %rdi      # 0x4d7b
callq 0x1060
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl $0x0, 0x10(%rbx)
jmp 0x28df