// File: /workspace/github_c_makefile_star2_O2/Astor-Bizard[P]ProjetS5_Groupe2/src/displayCorrectionSymbols.c
// Function: main
int main(int argc, char *argv[])
{
	Elf32_Ehdr Old_elfHeaders, New_elfHeaders;;
	SectionsHeadersList Old_section_headers, New_section_headers;
	ListeSymboles sym_tab,newST;
	Str_Reloc str_reloc;
	Table_Donnees tab_donnees;
	FILE *f_read, *f_write;
	
	if(argc < 3)
	{
		printf("Erreur nombre d'argument :\n\t./displayCorrectionSymbols <fichier_Elf_lecture> <fichier_Elf_ecriture>\n");
		return 1;
	}

	f_read = fopen(argv[1], "r");
	if (f_read == NULL) {
		printf("Fichier introuvable: %s\n", argv[1]);
		return 1;
	}

	f_write = fopen(argv[2], "w");
	if (f_write == NULL) {
		printf("Fichier introuvable: %s\n", argv[2]);
		fclose(f_read);
		return 1;
	}

	Old_elfHeaders = lecture_Headers(f_read, SILENT);
	
	rewind(f_read);
	Old_section_headers = readSectionsHeadersFromFile(f_read, Old_elfHeaders, SILENT);
	
	rewind(f_read);
	sym_tab = lectureSymbolTab(f_read, Old_elfHeaders, Old_section_headers, SILENT);

	rewind(f_read);
	str_reloc = affichage_relocation(f_read, Old_elfHeaders, Old_section_headers, sym_tab, SILENT);
	
	//printf("-----Fin de la lecture de %s-----\n",argv[1]);	

	tab_donnees = remplirDonnees(argc,argv,Old_elfHeaders, Old_section_headers);
	rewind(f_read);
	New_section_headers = renumerote_section(f_read, f_write, Old_elfHeaders, Old_section_headers, &New_elfHeaders, tab_donnees);
	
	//afficher_headers(New_elfHeaders);
	//displaySectionsHeaders(New_elfHeaders, New_section_headers);
	
	rewind(f_read);
	newST = applySymbolsCorrections(f_read, Old_elfHeaders, New_elfHeaders, Old_section_headers, New_section_headers, sym_tab, SILENT);

	afficherTableSymboles(sym_tab, Old_elfHeaders);
	printf("\n");
	afficherTableSymboles(newST, New_elfHeaders);

	//ecrire_nouvelles_sections(f_read, f_write, New_section_headers, Old_section_headers); 

	//writeSectionsHeadersToFile(f_write, New_elfHeaders, New_section_headers);

	//reimplantation_R_ARM(f_read, f_write, Old_elfHeaders, Old_section_headers, New_section_headers, str_reloc, newST);

	//printf("-----Fin de l'ecriture dans %s-----\n", argv[2]);

	fclose(f_read);
	fclose(f_write);

	free_Tab_Donnees(tab_donnees);
	free_Str_Reloc(str_reloc);
	free_SectionsHeadersList(Old_section_headers);
	free_SectionsHeadersList(New_section_headers);
	free_ListeSymboles(sym_tab);
	free_ListeSymboles(newST);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
cmpl $0x2, %edi
jg 0x1433
leaq 0x3cb3(%rip), %rdi      # 0x50dc
callq 0x1060
jmp 0x1876
movq %rsi, %rbp
movl %edi, %r14d
movq 0x8(%rsi), %rdi
leaq 0x4091(%rip), %rsi      # 0x54d5
callq 0x1130
testq %rax, %rax
je 0x1848
movq %rax, %rbx
movq 0x10(%rbp), %rdi
leaq 0x3bbd(%rip), %rsi      # 0x501d
callq 0x1130
testq %rax, %rax
je 0x185c
leaq 0x190(%rsp), %r13
pushq $0x1
popq %r15
movq %r13, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movq %rax, 0xc0(%rsp)
callq 0x18ea
movq %rbx, %rdi
callq 0x10a0
movl 0x30(%r13), %eax
movl %eax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x140(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x2225
movq %rbx, %rdi
callq 0x10a0
movq 0x10(%r12), %rax
movq %rax, 0x48(%rsp)
movups (%r12), %xmm0
movups %xmm0, 0x38(%rsp)
movl 0x30(%r13), %eax
movl %eax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
pushq $0x1
popq %rdx
callq 0x2930
movq %rbx, %rdi
callq 0x10a0
movq 0x10(%r15), %rax
movq %rax, 0x60(%rsp)
movups (%r15), %xmm0
movups %xmm0, 0x50(%rsp)
movq 0x10(%r12), %rax
movq %rax, 0x48(%rsp)
movups (%r12), %xmm0
movq %r12, %r15
movups %xmm0, 0x38(%rsp)
movl 0x30(%r13), %eax
movl %eax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xf8(%rsp), %rdi
movq %rbx, %rsi
pushq $0x1
popq %rdx
callq 0x3336
movq 0x10(%r12), %rax
movq %rax, 0x48(%rsp)
movups (%r12), %xmm0
movups %xmm0, 0x38(%rsp)
movl 0x30(%r13), %eax
movl %eax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
movl %r14d, %esi
movq %rbp, %rdx
callq 0x1317
movq %rbx, %rdi
callq 0x10a0
movq 0x10(%r12), %rax
movq %rax, 0x60(%rsp)
movups (%r12), %xmm0
movups %xmm0, 0x50(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x48(%rsp)
movups (%r15), %xmm0
movups %xmm0, 0x38(%rsp)
movl 0x30(%r13), %eax
movl %eax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x110(%rsp), %rbp
leaq 0x158(%rsp), %r14
movq %rbp, %rdi
movq %rbx, %rsi
movq 0xc0(%rsp), %r12
movq %r12, %rdx
movq %r14, %rcx
callq 0x34b3
movq %rbx, %rdi
callq 0x10a0
leaq 0xc8(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0xb0(%rsp)
movups (%rcx), %xmm0
movups %xmm0, 0xa0(%rsp)
movq 0x10(%rbp), %rax
movq %rax, 0x98(%rsp)
movups (%rbp), %xmm0
movups %xmm0, 0x88(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x80(%rsp)
movups (%r15), %xmm0
movups %xmm0, 0x70(%rsp)
movl 0x30(%r14), %eax
movl %eax, 0x68(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x58(%rsp)
movups %xmm1, 0x48(%rsp)
movups %xmm0, 0x38(%rsp)
movl 0x30(%r13), %eax
movl %eax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x128(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
pushq $0x1
popq %rdx
callq 0x39ab
movl 0x30(%r13), %eax
movl %eax, 0x48(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x38(%rsp)
movups %xmm1, 0x28(%rsp)
movups %xmm0, 0x18(%rsp)
leaq 0xc8(%rsp), %r13
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
callq 0x2c8d
pushq $0xa
popq %rdi
callq 0x1040
movl 0x30(%r14), %eax
movl %eax, 0x48(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x38(%rsp)
movups %xmm1, 0x28(%rsp)
movups %xmm0, 0x18(%rsp)
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
callq 0x2c8d
movq %rbx, %rdi
callq 0x1070
movq %r12, %rdi
callq 0x1070
leaq 0xe0(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x3482
leaq 0xf8(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x346c
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
callq 0x3440
leaq 0x110(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x3440
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
callq 0x3456
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
callq 0x3456
xorl %eax, %eax
jmp 0x1879
movq 0x8(%rbp), %rsi
leaq 0x37b1(%rip), %rdi      # 0x5004
xorl %eax, %eax
callq 0x1090
jmp 0x1876
movq 0x10(%rbp), %rsi
leaq 0x379d(%rip), %rdi      # 0x5004
xorl %eax, %eax
callq 0x1090
movq %rbx, %rdi
callq 0x1070
pushq $0x1
popq %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop