// File: /workspace/github_c_makefile_star2_O1/Astor-Bizard[P]ProjetS5_Groupe2/src/affichage_relocation.c
// Function: afficher_sectionR
void afficher_sectionR(FILE *f,
                        SectionsHeadersList liste_sections,
                        Elf32_Ehdr header,
                        int numS, 
                        Str_Reloc *RETOUR, 
                        ListeSymboles table_symbol, 
                        int silent)
{
	int i;
	unsigned char *section;
    section = recuperer_section_num(f, liste_sections, numS); // Y'a rien a voir circulez!
	unsigned long long int addr;
	unsigned long long int info;
    unsigned char type;
    unsigned int sym;
    
    char *nom_section = getSectionNameBis(liste_sections.names, liste_sections.headers[numS]);
    if(!silent)
    {
    	printf("\nRelocation section '%s' at offset 0x%x contains %i entries:\n",
                nom_section,
                liste_sections.headers[numS].sh_offset,
    			(int) liste_sections.headers[numS].sh_size/8);
    	printf(" Offset     Info    Type            Sym.Value  Sym. Name\n");
    }
    free(nom_section);

    RETOUR->Rel = realloc(RETOUR->Rel,sizeof(Elf32_Rel)*(RETOUR->nb_Rel+(int) liste_sections.headers[numS].sh_size/8));
    RETOUR->Sec_Rel = realloc(RETOUR->Sec_Rel,sizeof(int)*(RETOUR->nb_Rel+(int) liste_sections.headers[numS].sh_size/8));

	for(i=0; i<(int) liste_sections.headers[numS].sh_size/8; i++)
	{
		addr = lire_octets_charT(section, header.e_ident[EI_DATA], i*8, 4);
		info = lire_octets_charT(section, header.e_ident[EI_DATA], i*8 +4,4);
        type = info;
        sym = info >>8;

        if(!silent)
        {
    		printf("%08llx  %08llx ", addr,info);
            type_relocation(type);
            if(type != 40) print_symbol(sym, table_symbol, header, liste_sections);
            //print_section(addr, liste_sections, header); 
            
            //on affiche les infos.
            sym = sym *2;
            printf("\n");
        }
        RETOUR->nb_Rel ++;

        
        RETOUR->Rel[RETOUR->nb_Rel-1].r_offset = addr;
        RETOUR->Rel[RETOUR->nb_Rel-1].r_info = info;
        RETOUR->Sec_Rel[RETOUR->nb_Rel-1] = numS;
	}
	free(section);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %ecx, %r12d
movq %rdx, %r14
movl %esi, %ebx
leaq 0xf0(%rsp), %r13
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movaps (%r13), %xmm0
movups %xmm0, (%rsp)
callq 0x2718
movq %rax, 0x80(%rsp)
movq (%r13), %rax
movq 0x8(%r13), %rdi
movl %ebx, 0x6c(%rsp)
movslq %ebx, %rbx
leaq (%rbx,%rbx,4), %rdx
movq 0x20(%rax,%rdx,8), %rcx
movq %rcx, 0xb0(%rsp)
movups (%rax,%rdx,8), %xmm0
movq %rdx, 0x70(%rsp)
movups 0x10(%rax,%rdx,8), %xmm1
movaps %xmm1, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1e49
movq %rax, %r15
testl %r12d, %r12d
jne 0x302b
movq (%r13), %rax
movq 0x70(%rsp), %rcx
movl 0x10(%rax,%rcx,8), %edx
movl 0x14(%rax,%rcx,8), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
leaq 0x20c6(%rip), %rdi      # 0x50db
movq %r15, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x2103(%rip), %rdi      # 0x5129
callq 0x1060
movq %r15, %rdi
callq 0x1030
movq 0x8(%r14), %rdi
movslq (%r14), %rax
movq (%r13), %rcx
shlq $0x3, %rbx
leaq (%rbx,%rbx,4), %rbx
movl 0x14(%rcx,%rbx), %ecx
leal 0x7(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
movslq %edx, %rsi
addq %rax, %rsi
shlq $0x3, %rsi
callq 0x10f0
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
movslq (%r14), %rax
movq (%r13), %rcx
movl 0x14(%rcx,%rbx), %ecx
leal 0x7(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
movslq %edx, %rsi
addq %rax, %rsi
shlq $0x2, %rsi
callq 0x10f0
movq %rax, 0x10(%r14)
movq (%r13), %rax
cmpl $0x8, 0x14(%rax,%rbx)
movl 0x6c(%rsp), %edi
movq 0x70(%rsp), %r9
jl 0x326f
movq %r14, %rsi
movq %r13, %r8
leaq 0x108(%rsp), %rax
movb 0x5(%rax), %r10b
movq 0x80(%rsp), %rbp
movq %rbp, %rbx
addq $0x4, %rbx
xorl %r14d, %r14d
movl %r12d, 0x7c(%rsp)
movq %rsi, 0x88(%rsp)
movb %r10b, 0x6b(%rsp)
cmpb $0x2, %r10b
jne 0x3105
xorl %eax, %eax
xorl %r13d, %r13d
shlq $0x8, %r13
movzbl (%rbp,%rax), %ecx
orq %rcx, %r13
incq %rax
cmpq $0x4, %rax
jne 0x30ee
jmp 0x3125
xorl %ecx, %ecx
movq %rbp, %rax
xorl %r13d, %r13d
movzbl (%rax), %edx
shll %cl, %edx
movslq %edx, %rdx
orq %rdx, %r13
incq %rax
addq $0x8, %rcx
cmpq $0x20, %rcx
jne 0x310d
cmpb $0x2, %r10b
jne 0x3146
xorl %eax, %eax
xorl %r15d, %r15d
shlq $0x8, %r15
movzbl (%rbx,%rax), %ecx
orq %rcx, %r15
incq %rax
cmpq $0x4, %rax
jne 0x3130
jmp 0x3166
xorl %ecx, %ecx
movq %rbx, %rax
xorl %r15d, %r15d
movzbl (%rax), %edx
shll %cl, %edx
movslq %edx, %rdx
orq %rdx, %r15
incq %rax
addq $0x8, %rcx
cmpq $0x20, %rcx
jne 0x314e
testl %r12d, %r12d
jne 0x3228
leaq 0x1fa3(%rip), %rdi      # 0x5119
movq %r13, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1090
movzbl %r15b, %r12d
movl %r12d, %edi
callq 0x2dd9
cmpl $0x28, %r12d
je 0x31fb
movq %r15, %rdi
shrq $0x8, %rdi
leaq 0xf0(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x60(%rsp)
movups (%rcx), %xmm0
movups %xmm0, 0x50(%rsp)
leaq 0x108(%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)
leaq 0x140(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x2e72
movl $0xa, %edi
callq 0x1040
movl 0x7c(%rsp), %r12d
movq 0x88(%rsp), %rsi
movl 0x6c(%rsp), %edi
leaq 0xf0(%rsp), %r8
movq 0x70(%rsp), %r9
movb 0x6b(%rsp), %r10b
movslq (%rsi), %rax
leaq 0x1(%rax), %rcx
movl %ecx, (%rsi)
movq 0x8(%rsi), %rcx
movl %r13d, (%rcx,%rax,8)
movl %r15d, 0x4(%rcx,%rax,8)
movq 0x10(%rsi), %rcx
movl %edi, (%rcx,%rax,4)
incq %r14
movq (%r8), %rax
movl 0x14(%rax,%r9,8), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
movslq %ecx, %rax
addq $0x8, %rbp
addq $0x8, %rbx
cmpq %rax, %r14
jl 0x30e3
movq 0x80(%rsp), %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030