// File: /workspace/github_c_makefile_star2_O2/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 $0xa8, %rsp
movl %edx, 0x6c(%rsp)
movq %rsi, %r14
movq %rdi, 0x60(%rsp)
leaq 0x118(%rsp), %r12
movq (%r12), %r13
movq 0x8(%r12), %r15
movq 0x20(%r13), %rax
movq %rax, 0x90(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movaps %xmm1, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x70(%rsp), %xmm0
movaps 0x80(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x1d62
movq %rax, %rbx
movl 0x10(%r12), %eax
xorl %r12d, %r12d
testl %eax, %eax
movl $0x0, %ebp
movl %eax, 0x5c(%rsp)
cmovgl %eax, %ebp
movq %r13, 0xa0(%rsp)
addq $0x28, %r13
cmpq %r12, %rbp
je 0x27ce
movq %rbx, %rdi
leaq 0x2569(%rip), %rsi      # 0x4cc9
callq 0x10b0
testl %eax, %eax
je 0x27cb
movq %rbx, %rdi
callq 0x1030
incq %r12
movq 0x20(%r13), %rax
movq %rax, 0x90(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movaps %xmm1, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x70(%rsp), %xmm0
movaps 0x80(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x1d62
movq %rax, %rbx
addq $0x28, %r13
jmp 0x2751
movl %r12d, %ebp
cmpl 0x5c(%rsp), %ebp
jne 0x27f4
xorps %xmm0, %xmm0
movq 0x60(%rsp), %rbx
movups %xmm0, (%rbx)
andl $0x0, 0x10(%rbx)
leaq 0x2591(%rip), %rdi      # 0x4d7b
callq 0x1060
jmp 0x297f
movq %rbx, %rdi
callq 0x1030
movl %ebp, %eax
imulq $0x28, %rax, %rax
movq 0xa0(%rsp), %rcx
movl 0x10(%rcx,%rax), %r13d
movl 0x14(%rcx,%rax), %r12d
movl %r12d, %edi
andl $-0x10, %edi
callq 0x10d0
movq 0x60(%rsp), %rbx
movq %rax, (%rbx)
testq %rax, %rax
je 0x2969
movq %rax, %r15
leaq 0x118(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
movl %ebp, %esi
callq 0x2994
movq %rax, 0x8(%rbx)
xorl %ebx, %ebx
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x10e0
addl $0xf, %r12d
movl %r12d, %eax
shrl $0x4, %eax
movl %eax, 0x5c(%rsp)
andl $-0x10, %r12d
leaq 0xe0(%rsp), %rax
movq %r12, %rbp
movsbl 0x5(%rax), %r12d
cmpq %rbx, %rbp
je 0x2916
movl %r12d, %edi
movq %r14, %rsi
pushq $0x4
popq %r13
movl %r13d, %edx
callq 0x160c
movl %eax, (%r15,%rbx)
movl %r12d, %edi
movq %r14, %rsi
movl %r13d, %edx
callq 0x160c
movl %eax, 0x4(%r15,%rbx)
movl %r12d, %edi
movq %r14, %rsi
movl %r13d, %edx
callq 0x160c
movl %eax, 0x8(%r15,%rbx)
movl %r12d, %edi
movq %r14, %rsi
pushq $0x1
popq %r13
movl %r13d, %edx
callq 0x160c
movb %al, 0xc(%r15,%rbx)
movl %r12d, %edi
movq %r14, %rsi
movl %r13d, %edx
callq 0x160c
movb %al, 0xd(%r15,%rbx)
movl %r12d, %edi
movq %r14, %rsi
pushq $0x2
popq %rdx
callq 0x160c
movw %ax, 0xe(%r15,%rbx)
addq $0x10, %rbx
jmp 0x288a
movq 0x60(%rsp), %rbx
movl 0x5c(%rsp), %eax
movl %eax, 0x10(%rbx)
cmpl $0x0, 0x6c(%rsp)
jne 0x297f
leaq 0xe0(%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 0x2a0d
jmp 0x297f
leaq 0x23f7(%rip), %rdi      # 0x4d67
callq 0x1060
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
andl $0x0, 0x10(%rbx)
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq