#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct stat {
  int /*<<< orphan*/ st_size;
};
struct TYPE_2__ {
  int /*<<< orphan*/ e_entry;
};
typedef TYPE_1__ Elf32_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fstat(int, struct stat *);
unsigned char *mmap(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                    int /*<<< orphan*/, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int main() {
  Elf32_Ehdr *elfheader;
  unsigned char *file;
  int fd;
  struct stat st;
  fd = open("programa2", O_RDONLY);
  fstat(fd, &st);
  file = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
  elfheader = (Elf32_Ehdr *)file;
  printf("Entry Point: %p\n", elfheader->e_entry);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <fstat@plt>
mov    -0x20(%rbp),%esi
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    0x2e52(%rip),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1070 <fstat@plt>
mov    0x8(%rsp),%esi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
mov    0x2e5c(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    (%rax),%esi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i32 }
@.str = [10 x i8] c"programa2\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [17 x i8] c"Entry Point: %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.TYPE_2__*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.stat
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i32 @fstat(i32 %8, %struct.stat* %5)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_SHARED
%14 = load i32, i32* %4
%15 = call i8* @mmap(i32 0, i32 %11, i32 %12, i32 %13, i32 %14, i32 0)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = bitcast i8* %16 to %struct.TYPE_2__*
store %struct.TYPE_2__* %17, %struct.TYPE_2__** %2
%18 = load %struct.TYPE_2__*, %struct.TYPE_2__** %2
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [10 x i8] c"programa2\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [17 x i8] c"Entry Point: %p\0A\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 @fstat(i32 %4, %struct.stat* %1)
%6 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @MAP_SHARED
%10 = tail call i8* @mmap(i32 0, i32 %7, i32 %8, i32 %9, i32 %4, i32 0)
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
%13 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @close(i32 %4)
ret i32 0
}