// File: /workspace/github_c_makefile_star2_O1/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 0x28c5(%rip), %rdi      # 0x42d4
xorl %eax, %eax
callq 0x1090
leaq 0x28cf(%rip), %rbx      # 0x42ec
xorl %r15d, %r15d
movzbl (%r14,%r15), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1090
incq %r15
cmpq $0x10, %r15
jne 0x1a20
movzbl 0x4(%r14), %esi
shll $0x5, %esi
leaq 0x28ab(%rip), %rdi      # 0x42f2
xorl %eax, %eax
callq 0x1090
leaq 0x28ca(%rip), %rdi      # 0x431f
xorl %eax, %eax
callq 0x1090
cmpb $0x1, 0x5(%r14)
leaq 0x2c71(%rip), %rax      # 0x46d9
leaq 0x2c5f(%rip), %rdi      # 0x46ce
cmoveq %rax, %rdi
callq 0x1060
movzbl 0x6(%r14), %esi
leaq 0x28d1(%rip), %rdi      # 0x4355
xorl %eax, %eax
callq 0x1090
leaq 0x28f6(%rip), %rdi      # 0x4388
xorl %eax, %eax
callq 0x1090
movzwl 0x12(%r14), %esi
cmpl $0x28, %esi
jne 0x1ab1
leaq 0x2c3d(%rip), %rdi      # 0x46e7
callq 0x1060
jmp 0x1abf
leaq 0x28f6(%rip), %rdi      # 0x43ae
xorl %eax, %eax
callq 0x1090
leaq 0x2c31(%rip), %rdi      # 0x46f7
callq 0x1060
leaq 0x2900(%rip), %rdi      # 0x43d2
xorl %eax, %eax
callq 0x1090
movzwl 0x10(%r14), %eax
cmpq $0x4, %rax
ja 0x1afd
leaq 0x27b1(%rip), %rcx      # 0x429c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2cae(%rip), %rdi      # 0x47a9
jmp 0x1b3f
cmpl $0xff00, %eax           # imm = 0xFF00
je 0x1b1d
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x1b44
leaq 0x2c0c(%rip), %rdi      # 0x471e
jmp 0x1b3f
leaq 0x2c3b(%rip), %rdi      # 0x4756
jmp 0x1b3f
leaq 0x2c16(%rip), %rdi      # 0x473a
jmp 0x1b3f
leaq 0x2c53(%rip), %rdi      # 0x4780
jmp 0x1b3f
leaq 0x2c31(%rip), %rdi      # 0x4767
jmp 0x1b3f
leaq 0x2c53(%rip), %rdi      # 0x4792
callq 0x1060
leaq 0x2c72(%rip), %rdi      # 0x47bd
callq 0x1060
movl 0x14(%r14), %esi
leaq 0x289d(%rip), %rdi      # 0x43f8
xorl %eax, %eax
callq 0x1090
movl 0x18(%r14), %esi
leaq 0x28b6(%rip), %rdi      # 0x4423
xorl %eax, %eax
callq 0x1090
movl 0x1c(%r14), %esi
leaq 0x28cf(%rip), %rdi      # 0x444e
xorl %eax, %eax
callq 0x1090
movl 0x20(%r14), %esi
leaq 0x28f8(%rip), %rdi      # 0x4489
xorl %eax, %eax
callq 0x1090
movl 0x24(%r14), %ebx
leaq 0x2921(%rip), %rdi      # 0x44c4
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
cmpl $0x5000000, %ebx        # imm = 0x5000000
jne 0x1bc2
leaq 0x2933(%rip), %rdi      # 0x44ee
xorl %eax, %eax
callq 0x1090
movl $0xa, %edi
callq 0x1040
movzwl 0x28(%r14), %esi
leaq 0x2926(%rip), %rdi      # 0x44fe
xorl %eax, %eax
callq 0x1090
movzwl 0x2a(%r14), %esi
leaq 0x2944(%rip), %rdi      # 0x452f
xorl %eax, %eax
callq 0x1090
movzwl 0x2c(%r14), %esi
leaq 0x2962(%rip), %rdi      # 0x4560
xorl %eax, %eax
callq 0x1090
movzwl 0x2e(%r14), %esi
leaq 0x2978(%rip), %rdi      # 0x4589
xorl %eax, %eax
callq 0x1090
movzwl 0x30(%r14), %esi
leaq 0x2996(%rip), %rdi      # 0x45ba
xorl %eax, %eax
callq 0x1090
movzwl 0x32(%r14), %esi
testl %esi, %esi
je 0x1c47
leaq 0x29a8(%rip), %rdi      # 0x45e3
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x1090
leaq 0x2b98(%rip), %rdi      # 0x47e6
popq %rbx
popq %r14
popq %r15
jmp 0x1060