#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 */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ Load(char *, int);
int MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *);
void *mmap(int /*<<< orphan*/, int, int, int, int /*<<< orphan*/,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int /*<<< orphan*/ stderr;
int main() {
  void *mem = mmap(0, 0x2000, PROT_READ | PROT_WRITE,
                   MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
  fprintf(stderr, "Allocated %p\n", mem);
  munmap(mem, 0x2000);
  Load("libone.so", 1);
  Load("libtwo.so", 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
mov    0x2e69(%rip),%rax
or     (%rax),%edx
mov    0x2e78(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4f(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0x2000,%esi
mov    %r9d,%edi
mov    %r9d,%r8d
call   1040 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2000,%esi
call   1060 <munmap@plt>
lea    0xe56(%rip),%rdi
mov    $0x1,%esi
call   1030 <Load@plt>
lea    0xe4f(%rip),%rdi
mov    $0x2,%esi
call   1030 <Load@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e86(%rip),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x2000,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1060 <munmap@plt>
lea    0xe68(%rip),%rdi
mov    $0x1,%esi
call   1030 <Load@plt>
lea    0xe61(%rip),%rdi
mov    $0x2,%esi
call   1030 <Load@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"Allocated %p\0A\00"
@.str.1 = [10 x i8] c"libone.so\00"
@.str.2 = [10 x i8] c"libtwo.so\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %3, %4
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = load i32, i32* @MAP_PRIVATE
%8 = or i32 %6, %7
%9 = call i8* @mmap(i32 0, i32 8192, i32 %5, i32 %8, i32 0, i32 0)
store i8* %9, i8** %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 @munmap(i8* %13, i32 8192)
%15 = call i32 @Load(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 1)
%16 = call i32 @Load(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 2)
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"Allocated %p\0A\00"
@.str.1 = [10 x i8] c"libone.so\00"
@.str.2 = [10 x i8] c"libtwo.so\00"
define i32 @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_ANONYMOUS
%5 = load i32, i32* @MAP_PRIVATE
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i32 0, i32 8192, i32 %3, i32 %6, i32 0, i32 0)
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %7)
%10 = tail call i32 @munmap(i8* %7, i32 8192)
%11 = tail call i32 @Load(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = tail call i32 @Load(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 2)
ret i32 0
}