// File: /workspace/github_c_makefile_star2_O1/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
movb $0x2, 0x5(%rdi)
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 0x1701
cmpq $0x7f454c46, %r15       # imm = 0x7F454C46
jne 0x1974
movl $0x2, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x1680
movq %rax, %r15
movb %r15b, 0x4(%rbx)
movzbl %r15b, %eax
addl $-0x3, %eax
cmpl $-0x3, %eax
jbe 0x198c
movl $0x464c457f, (%rbx)     # imm = 0x464C457F
movl $0x2, %r15d
movl $0x2, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x1680
movq %rax, %r12
movb %r12b, 0x5(%rbx)
movzbl %r12b, %eax
leal -0x3(%rax), %ecx
cmpl $-0x3, %ecx
jbe 0x199e
xorl %ecx, %ecx
cmpl $0x1, %eax
sete %cl
movb $0x2, %r12b
subb %cl, %r12b
movb %r12b, 0x5(%rbx)
subl %ecx, %r15d
movl %r15d, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x1680
movb %al, 0x6(%rbx)
testb %al, %al
je 0x19b7
movzbl %r12b, %edi
movq %r14, %rsi
movl $0x9, %edx
callq 0x1680
movq $0x0, 0x7(%rbx)
movb $0x0, 0xf(%rbx)
movsbl 0x5(%rbx), %r15d
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x10(%rbx)
cmpw $0x5, %ax
jae 0x194a
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x12(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, 0x14(%rbx)
testl %eax, %eax
je 0x19d5
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, 0x18(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, 0x1c(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, 0x20(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1680
movl %eax, 0x24(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x28(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x2a(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x2c(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x2e(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x30(%rbx)
movl %r15d, %edi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1680
movw %ax, 0x32(%rbx)
testl %ebp, %ebp
jne 0x1938
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 0x19fe
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 0x17f6
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x17f6
leaq 0x2ce9(%rip), %rdi      # 0x4653
callq 0x1060
jmp 0x19f4
leaq 0x2d31(%rip), %rdi      # 0x46ac
callq 0x1060
leaq 0x2929(%rip), %rdi      # 0x42b0
movq %r15, %rsi
jmp 0x19ed
leaq 0x2cfa(%rip), %rdi      # 0x468d
callq 0x1060
movzbl %r15b, %esi
jmp 0x19ae
leaq 0x2ccb(%rip), %rdi      # 0x4670
callq 0x1060
movzbl %r12b, %esi
leaq 0x290e(%rip), %rdi      # 0x42c3
jmp 0x19cc
leaq 0x2c4e(%rip), %rdi      # 0x460c
callq 0x1060
leaq 0x28f9(%rip), %rdi      # 0x42c3
xorl %esi, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x19f4
leaq 0x2c57(%rip), %rdi      # 0x4633
callq 0x1060
leaq 0x28c8(%rip), %rdi      # 0x42b0
movl $0x7f454c46, %esi       # imm = 0x7F454C46
xorl %eax, %eax
callq 0x1090
movl $0x1, %edi
callq 0x1130