// File: /workspace/github_c_makefile_star2_O3/Astor-Bizard[P]ProjetS5_Groupe2/src/lecture_headers.c
// Function: afficher_headers
void afficher_headers(Elf32_Ehdr headers)
{
	int i;
	printf("ELF Header:\n  Magic:   ");
	for(i=0;i<EI_NIDENT;i++) printf("%02x ",headers.e_ident[i]);
	printf("\n  Class:                             ELF%d\n",headers.e_ident[EI_CLASS]*32);
	printf("  Data:                              2's complement, ");
	if (headers.e_ident[EI_DATA] == L_ENDIAN) printf("little endian\n");
	else printf("big endian\n");

	printf("  Version:                           %d (current)\n",headers.e_ident[EI_VERSION]);

	printf("  OS/ABI:                            ");
	if(headers.e_machine==40)
		printf("UNIX - System V\n");
	else
		printf("Machine numero : %d (incompatible)\n", headers.e_machine);

	printf("  ABI Version:                       0\n");

	printf("  Type:                              ");
	switch(headers.e_type)
	{
		case ET_NONE:
			printf("NONE (No file type)\n");
			break;
		case ET_REL:
			printf("REL (Relocatable file)\n");
			break;
		case ET_EXEC:
			printf("EXEC (Executable)\n");
			break;
		case ET_DYN:
			printf("DYN (Shared object file)\n");
			break;
		case ET_CORE:
			printf("CORE (Core file)\n");
			break;
		case ET_LOPROC:
			printf("LOPROC (Processor-specific)\n");
			break;
		case ET_HIPROC:
			printf("HIPROC (Processor-specific)\n");
			break;
	}
	printf("  Machine:                           ARM\n");
	printf("  Version:                           0x%x\n",headers.e_version);
	printf("  Entry point address:               0x%x\n",headers.e_entry);

	printf("  Start of program headers:          %u (bytes into file)\n",headers.e_phoff);

	printf("  Start of section headers:          %u (bytes into file)\n",headers.e_shoff);

	printf("  Flags:                             0x%x",headers.e_flags);
	if(headers.e_flags==0x5000000) printf(", Version5 EABI");
	printf("\n");

	printf("  Size of this header:               %d (bytes)\n", headers.e_ehsize);
	printf("  Size of program headers:           %d (bytes)\n", headers.e_phentsize);
	printf("  Number of program headers:         %d\n", headers.e_phnum);
	printf("  Size of section headers:           %d (bytes)\n", headers.e_shentsize);
	printf("  Number of section headers:         %d\n", headers.e_shnum);

	if(headers.e_shstrndx==SHN_UNDEF)
		printf("  Section header string table index: SHN_UNDEF\n");
	else
		printf("  Section header string table index: %d\n", headers.e_shstrndx);

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
leaq 0x20(%rsp), %r14
leaq 0x28c1(%rip), %rdi      # 0x42d4
xorl %eax, %eax
callq 0x1090
leaq 0x28cb(%rip), %rbx      # 0x42ec
xorl %r15d, %r15d
movzbl (%r14,%r15), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1090
incq %r15
cmpq $0x10, %r15
jne 0x1a24
movzbl 0x4(%r14), %esi
shll $0x5, %esi
leaq 0x28a7(%rip), %rdi      # 0x42f2
xorl %eax, %eax
callq 0x1090
leaq 0x28c6(%rip), %rdi      # 0x431f
xorl %eax, %eax
callq 0x1090
cmpb $0x1, 0x5(%r14)
leaq 0x2c6d(%rip), %rax      # 0x46d9
leaq 0x2c5b(%rip), %rdi      # 0x46ce
cmoveq %rax, %rdi
callq 0x1060
movzbl 0x6(%r14), %esi
leaq 0x28cd(%rip), %rdi      # 0x4355
xorl %eax, %eax
callq 0x1090
leaq 0x28f2(%rip), %rdi      # 0x4388
xorl %eax, %eax
callq 0x1090
movzwl 0x12(%r14), %esi
cmpl $0x28, %esi
jne 0x1ab5
leaq 0x2c39(%rip), %rdi      # 0x46e7
callq 0x1060
jmp 0x1ac3
leaq 0x28f2(%rip), %rdi      # 0x43ae
xorl %eax, %eax
callq 0x1090
leaq 0x2c2d(%rip), %rdi      # 0x46f7
callq 0x1060
leaq 0x28fc(%rip), %rdi      # 0x43d2
xorl %eax, %eax
callq 0x1090
movzwl 0x10(%r14), %eax
cmpq $0x4, %rax
ja 0x1b01
leaq 0x27ad(%rip), %rcx      # 0x429c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2caa(%rip), %rdi      # 0x47a9
jmp 0x1b43
cmpl $0xff00, %eax           # imm = 0xFF00
je 0x1b21
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x1b48
leaq 0x2c08(%rip), %rdi      # 0x471e
jmp 0x1b43
leaq 0x2c37(%rip), %rdi      # 0x4756
jmp 0x1b43
leaq 0x2c12(%rip), %rdi      # 0x473a
jmp 0x1b43
leaq 0x2c4f(%rip), %rdi      # 0x4780
jmp 0x1b43
leaq 0x2c2d(%rip), %rdi      # 0x4767
jmp 0x1b43
leaq 0x2c4f(%rip), %rdi      # 0x4792
callq 0x1060
leaq 0x2c6e(%rip), %rdi      # 0x47bd
callq 0x1060
movl 0x14(%r14), %esi
leaq 0x2899(%rip), %rdi      # 0x43f8
xorl %eax, %eax
callq 0x1090
movl 0x18(%r14), %esi
leaq 0x28b2(%rip), %rdi      # 0x4423
xorl %eax, %eax
callq 0x1090
movl 0x1c(%r14), %esi
leaq 0x28cb(%rip), %rdi      # 0x444e
xorl %eax, %eax
callq 0x1090
movl 0x20(%r14), %esi
leaq 0x28f4(%rip), %rdi      # 0x4489
xorl %eax, %eax
callq 0x1090
movl 0x24(%r14), %ebx
leaq 0x291d(%rip), %rdi      # 0x44c4
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
cmpl $0x5000000, %ebx        # imm = 0x5000000
jne 0x1bc6
leaq 0x292f(%rip), %rdi      # 0x44ee
xorl %eax, %eax
callq 0x1090
movl $0xa, %edi
callq 0x1040
movzwl 0x28(%r14), %esi
leaq 0x2922(%rip), %rdi      # 0x44fe
xorl %eax, %eax
callq 0x1090
movzwl 0x2a(%r14), %esi
leaq 0x2940(%rip), %rdi      # 0x452f
xorl %eax, %eax
callq 0x1090
movzwl 0x2c(%r14), %esi
leaq 0x295e(%rip), %rdi      # 0x4560
xorl %eax, %eax
callq 0x1090
movzwl 0x2e(%r14), %esi
leaq 0x2974(%rip), %rdi      # 0x4589
xorl %eax, %eax
callq 0x1090
movzwl 0x30(%r14), %esi
leaq 0x2992(%rip), %rdi      # 0x45ba
xorl %eax, %eax
callq 0x1090
movzwl 0x32(%r14), %esi
testl %esi, %esi
je 0x1c4b
leaq 0x29a4(%rip), %rdi      # 0x45e3
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x1090
leaq 0x2b94(%rip), %rdi      # 0x47e6
popq %rbx
popq %r14
popq %r15
jmp 0x1060