// File: /workspace/github_c_makefile_star2_O2/Astor-Bizard[P]ProjetS5_Groupe2/src/lecture_headers.c
// Function: lecture_Headers
Elf32_Ehdr lecture_Headers(FILE *f, int silent)
{
	long long int lec_Cour = 0;
	Elf32_Ehdr headers;
	headers.e_ident[EI_DATA]=(char) B_ENDIAN;
	int i;

	lec_Cour = lire_octets(headers.e_ident[EI_DATA],f,4);

	if (lec_Cour != 0x7f454c46)
	{
		printf("Erreur lecture_Header : 7f45 4c46\n");
		printf("Octets lus : %llx\n", lec_Cour);
		exit(1);
	}

	MEMORISER(1,headers.e_ident[EI_CLASS]);
	if (headers.e_ident[EI_CLASS] != 1 && headers.e_ident[EI_CLASS] != 2)
	{
		printf("Erreur lecture_Header : Classe\n");
		printf("Octets lus : %x\n", headers.e_ident[EI_CLASS]);
		exit(1);
	}

	headers.e_ident[EI_MAG0]=0x7F;
	headers.e_ident[EI_MAG1]='E';
	headers.e_ident[EI_MAG2]='L';
	headers.e_ident[EI_MAG3]='F';

	MEMORISER(1,headers.e_ident[EI_DATA]);
	if (headers.e_ident[EI_DATA] != 1 && headers.e_ident[EI_DATA] != 2)
	{
		printf("Erreur lecture_Header : Data\n");
		printf("Octets lus : %x\n", headers.e_ident[EI_DATA]);
		exit(1);
	}

	if (headers.e_ident[EI_DATA] == 0x01)
		headers.e_ident[EI_DATA] = (char) L_ENDIAN;
	else
		headers.e_ident[EI_DATA] = (char) B_ENDIAN;

	MEMORISER(1,headers.e_ident[EI_VERSION]);
	if(! (headers.e_ident[EI_VERSION]))
	{
		printf("Erreur lecture_Header : Version header\n");
		printf("Octets lus : %x\n", headers.e_ident[EI_VERSION]);
		exit(1);
	}

	lire_octets(headers.e_ident[EI_DATA],f,9);
	for(i=7;i<EI_NIDENT;i++) headers.e_ident[i]=0x0;

	MEMORISER(2,headers.e_type);
	switch(headers.e_type)
	{
		case ET_NONE:
		case ET_REL:
		case ET_EXEC:
		case ET_DYN:
		case ET_CORE:
		case ET_LOPROC:
		case ET_HIPROC:
			break;
		default:
			printf("Erreur lecture_Header : Type\n");
			exit(1);
	}

	MEMORISER(2,headers.e_machine);

	MEMORISER(4,headers.e_version);
	if(! (headers.e_version))
	{
		printf("Erreur lecture_Header : Version\n");
		printf("Octets lus : %llx\n", lec_Cour);
		exit(1);
	}

	MEMORISER(4,headers.e_entry);

	MEMORISER(4,headers.e_phoff);

	MEMORISER(4,headers.e_shoff);

	MEMORISER(4,headers.e_flags);

	MEMORISER(2,headers.e_ehsize);

	MEMORISER(2,headers.e_phentsize);

	MEMORISER(2,headers.e_phnum);

	MEMORISER(2,headers.e_shentsize);

	MEMORISER(2,headers.e_shnum);

	MEMORISER(2,headers.e_shstrndx);

	if(!silent)
	{
		afficher_headers(headers);
	}

	return headers;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x2
popq %rdi
pushq $0x4
popq %rdx
callq 0x160c
cmpq $0x7f454c46, %rax       # imm = 0x7F454C46
jne 0x18c4
pushq $0x2
popq %rdi
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x160c
movb %al, 0x4(%rbx)
movzbl %al, %r15d
leal -0x3(%r15), %eax
cmpl $-0x3, %eax
jbe 0x18df
movl $0x464c457f, (%rbx)     # imm = 0x464C457F
pushq $0x2
popq %r15
pushq $0x1
popq %rdx
movl %r15d, %edi
movq %r14, %rsi
callq 0x160c
movzbl %al, %r12d
leal -0x3(%r12), %eax
cmpl $-0x3, %eax
jbe 0x18f7
xorl %eax, %eax
cmpl $0x1, %r12d
sete %al
movb $0x2, %r12b
subb %al, %r12b
movb %r12b, 0x5(%rbx)
subl %eax, %r15d
pushq $0x1
popq %rdx
movl %r15d, %edi
movq %r14, %rsi
callq 0x160c
movb %al, 0x6(%rbx)
testb %al, %al
je 0x190f
movzbl %r12b, %edi
pushq $0x9
popq %rdx
movq %r14, %rsi
callq 0x160c
pushq $0x7
popq %rax
cmpq $0x10, %rax
je 0x1734
movb $0x0, (%rbx,%rax)
incq %rax
jmp 0x1725
movsbl 0x5(%rbx), %r15d
pushq $0x2
popq %rdx
movl %r15d, %edi
movq %r14, %rsi
callq 0x160c
movw %ax, 0x10(%rbx)
cmpw $0x5, %ax
jae 0x189a
pushq $0x2
popq %rdx
movl %r15d, %edi
movq %r14, %rsi
callq 0x160c
movw %ax, 0x12(%rbx)
pushq $0x4
popq %rdx
movl %r15d, %edi
movq %r14, %rsi
callq 0x160c
movl %eax, 0x14(%rbx)
testl %eax, %eax
je 0x192d
pushq $0x4
popq %r12
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movl %eax, 0x18(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movl %eax, 0x1c(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movl %eax, 0x20(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movl %eax, 0x24(%rbx)
pushq $0x2
popq %r12
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movw %ax, 0x28(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movw %ax, 0x2a(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movw %ax, 0x2c(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movw %ax, 0x2e(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movw %ax, 0x30(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl %r12d, %edx
callq 0x160c
movw %ax, 0x32(%rbx)
testl %ebp, %ebp
jne 0x1887
movl 0x30(%rbx), %eax
movl %eax, 0x70(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movaps %xmm2, 0x60(%rsp)
movaps %xmm1, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0x30(%rsp)
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movaps 0x60(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1954
movq %rbx, %rax
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movzwl %ax, %eax
cmpl $0xff00, %eax           # imm = 0xFF00
je 0x1755
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x1755
leaq 0x2d99(%rip), %rdi      # 0x4653
callq 0x1060
jmp 0x194c
movq %rax, %r15
leaq 0x2dde(%rip), %rdi      # 0x46ac
callq 0x1060
leaq 0x29d6(%rip), %rdi      # 0x42b0
movq %r15, %rsi
jmp 0x1945
leaq 0x2da7(%rip), %rdi      # 0x468d
callq 0x1060
leaq 0x29d1(%rip), %rdi      # 0x42c3
movl %r15d, %esi
jmp 0x1924
leaq 0x2d72(%rip), %rdi      # 0x4670
callq 0x1060
leaq 0x29b9(%rip), %rdi      # 0x42c3
movl %r12d, %esi
jmp 0x1924
leaq 0x2cf6(%rip), %rdi      # 0x460c
callq 0x1060
leaq 0x29a1(%rip), %rdi      # 0x42c3
xorl %esi, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x194c
leaq 0x2cff(%rip), %rdi      # 0x4633
callq 0x1060
leaq 0x2970(%rip), %rdi      # 0x42b0
movl $0x7f454c46, %esi       # imm = 0x7F454C46
xorl %eax, %eax
callq 0x1090
pushq $0x1
popq %rdi
callq 0x1130