// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq 0x36b1(%rip), %rdi      # 0x5458
movb $0x0, %al
callq 0x1070
movl $0x0, -0x4(%rbp)
cmpl $0x10, -0x4(%rbp)
jge 0x1de0
movq -0x10(%rbp), %rax
movslq -0x4(%rbp), %rcx
movzbl (%rax,%rcx), %esi
leaq 0x36a2(%rip), %rdi      # 0x5470
movb $0x0, %al
callq 0x1070
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x1db5
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %esi
shll $0x5, %esi
leaq 0x3684(%rip), %rdi      # 0x5476
movb $0x0, %al
callq 0x1070
leaq 0x36a3(%rip), %rdi      # 0x54a3
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
cmpl $0x1, %eax
jne 0x1e24
leaq 0x36be(%rip), %rdi      # 0x54d9
movb $0x0, %al
callq 0x1070
jmp 0x1e32
leaq 0x36bd(%rip), %rdi      # 0x54e8
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %esi
leaq 0x36b3(%rip), %rdi      # 0x54f4
movb $0x0, %al
callq 0x1070
leaq 0x36d8(%rip), %rdi      # 0x5527
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x28, %eax
jne 0x1e73
leaq 0x36e3(%rip), %rdi      # 0x554d
movb $0x0, %al
callq 0x1070
jmp 0x1e89
movq -0x10(%rbp), %rax
movzwl 0x12(%rax), %esi
leaq 0x36dc(%rip), %rdi      # 0x555e
movb $0x0, %al
callq 0x1070
leaq 0x36f2(%rip), %rdi      # 0x5582
xorl %eax, %eax
movb %al, -0x15(%rbp)
callq 0x1070
movb -0x15(%rbp), %al
leaq 0x3706(%rip), %rdi      # 0x55aa
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
movl %eax, -0x14(%rbp)
testl %eax, %eax
je 0x1efa
jmp 0x1eba
movl -0x14(%rbp), %eax
subl $0x1, %eax
je 0x1f0a
jmp 0x1ec4
movl -0x14(%rbp), %eax
subl $0x2, %eax
je 0x1f1a
jmp 0x1ece
movl -0x14(%rbp), %eax
subl $0x3, %eax
je 0x1f2a
jmp 0x1ed8
movl -0x14(%rbp), %eax
subl $0x4, %eax
je 0x1f3a
jmp 0x1ee2
movl -0x14(%rbp), %eax
subl $0xff00, %eax           # imm = 0xFF00
je 0x1f4a
jmp 0x1eee
movl -0x14(%rbp), %eax
subl $0xffff, %eax           # imm = 0xFFFF
je 0x1f5a
jmp 0x1f68
leaq 0x36cf(%rip), %rdi      # 0x55d0
movb $0x0, %al
callq 0x1070
jmp 0x1f68
leaq 0x36d4(%rip), %rdi      # 0x55e5
movb $0x0, %al
callq 0x1070
jmp 0x1f68
leaq 0x36dc(%rip), %rdi      # 0x55fd
movb $0x0, %al
callq 0x1070
jmp 0x1f68
leaq 0x36df(%rip), %rdi      # 0x5610
movb $0x0, %al
callq 0x1070
jmp 0x1f68
leaq 0x36e9(%rip), %rdi      # 0x562a
movb $0x0, %al
callq 0x1070
jmp 0x1f68
leaq 0x36eb(%rip), %rdi      # 0x563c
movb $0x0, %al
callq 0x1070
jmp 0x1f68
leaq 0x36f8(%rip), %rdi      # 0x5659
movb $0x0, %al
callq 0x1070
leaq 0x3707(%rip), %rdi      # 0x5676
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movl 0x14(%rax), %esi
leaq 0x371c(%rip), %rdi      # 0x56a0
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0x3732(%rip), %rdi      # 0x56cb
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
leaq 0x3748(%rip), %rdi      # 0x56f6
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movl 0x20(%rax), %esi
leaq 0x376e(%rip), %rdi      # 0x5731
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movl 0x24(%rax), %esi
leaq 0x3794(%rip), %rdi      # 0x576c
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
cmpl $0x5000000, 0x24(%rax)  # imm = 0x5000000
jne 0x1ffa
leaq 0x37a3(%rip), %rdi      # 0x5796
movb $0x0, %al
callq 0x1070
leaq 0x3a79(%rip), %rdi      # 0x5a7a
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x28(%rax), %esi
leaq 0x378f(%rip), %rdi      # 0x57a6
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x2a(%rax), %esi
leaq 0x37aa(%rip), %rdi      # 0x57d7
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x2c(%rax), %esi
leaq 0x37c5(%rip), %rdi      # 0x5808
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x2e(%rax), %esi
leaq 0x37d8(%rip), %rdi      # 0x5831
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %esi
leaq 0x37f3(%rip), %rdi      # 0x5862
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movzwl 0x32(%rax), %eax
cmpl $0x0, %eax
jne 0x2093
leaq 0x3801(%rip), %rdi      # 0x588b
movb $0x0, %al
callq 0x1070
jmp 0x20a9
movq -0x10(%rbp), %rax
movzwl 0x32(%rax), %esi
leaq 0x3819(%rip), %rdi      # 0x58bb
movb $0x0, %al
callq 0x1070
addq $0x20, %rsp
popq %rbp
retq
nop