// File: /workspace/github_c_makefile_star2_O1/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, 0x64(%rsp)
movq %rsi, %r14
movq %rdi, 0x58(%rsp)
movq 0x108(%rsp), %rbp
movq 0x110(%rsp), %r15
movq 0x20(%rbp), %rax
movq %rax, 0x90(%rsp)
movups (%rbp), %xmm0
movups 0x10(%rbp), %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 0x1e49
movq %rax, %r13
movl 0x118(%rsp), %ebx
testl %ebx, %ebx
jle 0x28af
movq %rbp, 0x68(%rsp)
addq $0x28, %rbp
xorl %r12d, %r12d
movq %r13, %rdi
leaq 0x24e4(%rip), %rsi      # 0x4d1d
callq 0x10b0
testl %eax, %eax
je 0x28a8
movq %r13, %rdi
callq 0x1030
incq %r12
movq 0x20(%rbp), %rax
movq %rax, 0x90(%rsp)
movups (%rbp), %xmm0
movups 0x10(%rbp), %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 0x1e49
movq %rax, %r13
addq $0x28, %rbp
cmpq %r12, %rbx
jne 0x282f
movl %ebx, %r12d
movq 0x68(%rsp), %rbp
jmp 0x28b2
xorl %r12d, %r12d
cmpl %ebx, %r12d
jne 0x28da
xorps %xmm0, %xmm0
movq 0x58(%rsp), %rbx
movups %xmm0, (%rbx)
movl $0x0, 0x10(%rbx)
leaq 0x24ff(%rip), %rdi      # 0x4dcf
callq 0x1060
jmp 0x2a5b
movq %r13, %rdi
callq 0x1030
movl %r12d, %eax
leaq (%rax,%rax,4), %rax
movl 0x10(%rbp,%rax,8), %r13d
movl 0x14(%rbp,%rax,8), %ebp
movl %ebp, %edi
andl $-0x10, %edi
callq 0x10d0
movq 0x58(%rsp), %rbx
movq %rax, (%rbx)
testq %rax, %rax
je 0x2a42
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 0x2a70
movq %rax, 0x8(%rbx)
xorl %ebx, %ebx
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x10e0
testl %ebp, %ebp
je 0x29f0
decl %ebp
shrl $0x4, %ebp
incl %ebp
addq $0xe, %r15
xorl %ebx, %ebx
leaq 0xd0(%rsp), %rax
movsbl 0x5(%rax), %r12d
movl %r12d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, -0xe(%r15)
movl %r12d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, -0xa(%r15)
movl %r12d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, -0x6(%r15)
movl %r12d, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x1680
movb %al, -0x2(%r15)
movl %r12d, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x1680
movb %al, -0x1(%r15)
movl %r12d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, (%r15)
incq %rbx
addq $0x10, %r15
cmpq %rbx, %rbp
jne 0x2968
movq 0x58(%rsp), %rax
movl %ebx, 0x10(%rax)
movq %rax, %rbx
cmpl $0x0, 0x64(%rsp)
jne 0x2a5b
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 0x2af2
jmp 0x2a5b
leaq 0x2372(%rip), %rdi      # 0x4dbb
callq 0x1060
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl $0x0, 0x10(%rbx)
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq