#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ p_memsz;
  scalar_t__ p_vaddr;
};
typedef TYPE_1__ Elf64_Phdr;
typedef int /*<<< orphan*/ Elf64_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ _mmap(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ copy(char *, char *, int /*<<< orphan*/, int);
Elf64_Ehdr *extract_elf(Elf64_Phdr *phdr) {
  _mmap((void *)(0xffff400000), phdr->p_memsz, 0);
  copy((char *)(0xffff400000), (char *)phdr->p_vaddr, phdr->p_memsz, 0x90);
  return ((Elf64_Ehdr *)(0xffff400000));
}


x86 assembly (clang, -O0):
<extract_elf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
movabs $0xffff400000,%rdi
xor    %edx,%edx
call   1040 <_mmap@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
movabs $0xffff400000,%rdi
mov    $0x90,%ecx
call   1030 <copy@plt>
movabs $0xffff400000,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_elf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%esi
movabs $0xffff400000,%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1040 <_mmap@plt>
mov    0x8(%rbx),%rsi
mov    (%rbx),%edx
mov    %r14,%rdi
mov    $0x90,%ecx
call   1030 <copy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64 }
define i32* @extract_elf(%struct.TYPE_3__* %0) {
%2 = alloca %struct.TYPE_3__*
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %2
%3 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
%5 = load i32, i32* %4
%6 = call i32 @_mmap(i8* inttoptr (i64 1099499044864 to i8*), i32 %5, i32 0)
%7 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i32 0, i32 1
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i8*
%11 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @copy(i8* inttoptr (i64 1099499044864 to i8*), i8* %10, i32 %13, i32 144)
ret i32* inttoptr (i64 1099499044864 to i32*)
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64 }
define i32* @extract_elf(%struct.TYPE_3__* nocapture %0) {
%2 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = tail call i32 @_mmap(i8* inttoptr (i64 1099499044864 to i8*), i32 %3, i32 0)
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = inttoptr i64 %6 to i8*
%8 = load i32, i32* %2
%9 = tail call i32 @copy(i8* inttoptr (i64 1099499044864 to i8*), i8* %7, i32 %8, i32 144)
ret i32* inttoptr (i64 1099499044864 to i32*)
}