// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl $0x4, %r12d
xorl %r15d, %r15d
movq %r15, %r13
shlq $0x8, %r13
movq %r14, %rdi
callq 0x10a0
movslq %eax, %r15
orq %r13, %r15
decl %r12d
jne 0x1709
cmpq $0x7f454c46, %r15       # imm = 0x7F454C46
jne 0x1973
movl $0x2, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x168c
movb %al, 0x4(%rbx)
movzbl %al, %r15d
leal -0x3(%r15), %eax
cmpl $-0x3, %eax
jbe 0x198b
movl $0x464c457f, (%rbx)     # imm = 0x464C457F
movl $0x2, %r15d
movl $0x2, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x168c
movzbl %al, %r12d
leal -0x3(%r12), %eax
cmpl $-0x3, %eax
jbe 0x19a3
xorl %eax, %eax
cmpl $0x1, %r12d
sete %al
movb $0x2, %r12b
subb %al, %r12b
movb %r12b, 0x5(%rbx)
subl %eax, %r15d
movl %r15d, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x168c
movb %al, 0x6(%rbx)
testb %al, %al
je 0x19bb
movzbl %r12b, %r15d
movl %r15d, %edi
movq %r14, %rsi
movl $0x9, %edx
callq 0x168c
movq $0x0, 0x7(%rbx)
movb $0x0, 0xf(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x10(%rbx)
cmpw $0x5, %ax
jae 0x1949
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x12(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, 0x14(%rbx)
testl %eax, %eax
je 0x19d9
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, 0x18(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, 0x1c(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, 0x20(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x168c
movl %eax, 0x24(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x28(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x2a(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x2c(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x2e(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x30(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x168c
movw %ax, 0x32(%rbx)
testl %ebp, %ebp
jne 0x1937
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 0x1a02
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl %ax, %eax
cmpl $0xff00, %eax           # imm = 0xFF00
je 0x17f5
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x17f5
leaq 0x2cea(%rip), %rdi      # 0x4653
callq 0x1060
jmp 0x19f8
leaq 0x2d32(%rip), %rdi      # 0x46ac
callq 0x1060
leaq 0x292a(%rip), %rdi      # 0x42b0
movq %r15, %rsi
jmp 0x19f1
leaq 0x2cfb(%rip), %rdi      # 0x468d
callq 0x1060
leaq 0x2925(%rip), %rdi      # 0x42c3
movl %r15d, %esi
jmp 0x19d0
leaq 0x2cc6(%rip), %rdi      # 0x4670
callq 0x1060
leaq 0x290d(%rip), %rdi      # 0x42c3
movl %r12d, %esi
jmp 0x19d0
leaq 0x2c4a(%rip), %rdi      # 0x460c
callq 0x1060
leaq 0x28f5(%rip), %rdi      # 0x42c3
xorl %esi, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x19f8
leaq 0x2c53(%rip), %rdi      # 0x4633
callq 0x1060
leaq 0x28c4(%rip), %rdi      # 0x42b0
movl $0x7f454c46, %esi       # imm = 0x7F454C46
xorl %eax, %eax
callq 0x1090
movl $0x1, %edi
callq 0x1130