#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*/ Ehdr;
int ElfW(int /*<<< orphan*/);
int MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ PROT_WRITE;
int close(int);
int ehdr_ehdr;
int errno;
int exe_ehdr;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
size_t getpagesize();
int /*<<< orphan*/ memcpy(int, int, int);
int mmap(int /*<<< orphan*/, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
         int, int /*<<< orphan*/);
int munmap(int, size_t);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char *argv[]) {
  char *pgm_name = argv[0];
  char *ehdr_name;
  char *exe_name;
  int fd;
  ElfW(Ehdr) * ehdr_ehdr;
  ElfW(Ehdr) * exe_ehdr;
  size_t page_size;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <ehdr> <exe>\n", pgm_name);
    exit(1);
  }
  ehdr_name = argv[1];
  exe_name = argv[2];
  page_size = getpagesize();
  fd = open(ehdr_name, O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "%s: can't open '%s'. Errno = %d (%s)\n", pgm_name,
            ehdr_name, errno, strerror(errno));
    exit(1);
  }
  ehdr_ehdr = mmap(0, page_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (ehdr_ehdr == MAP_FAILED) {
    fprintf(stderr, "%s: can't mmap '%s'. Errno = %d (%s)\n", pgm_name,
            ehdr_name, errno, strerror(errno));
    exit(1);
  }
  if (close(fd) == -1) {
    fprintf(stderr, "%s: can't close '%s'. Errno = %d (%s)\n", pgm_name,
            ehdr_name, errno, strerror(errno));
    exit(1);
  }
  fd = open(exe_name, O_RDWR);
  if (fd == -1) {
    fprintf(stderr, "%s: can't open '%s'. Errno = %d (%s)\n", pgm_name,
            exe_name, errno, strerror(errno));
    exit(1);
  }
  exe_ehdr = mmap(0, page_size, PROT_WRITE, MAP_SHARED, fd, 0);
  if (exe_ehdr == MAP_FAILED) {
    fprintf(stderr, "%s: can't mmap '%s'. Errno = %d (%s)\n", pgm_name,
            exe_name, errno, strerror(errno));
    exit(1);
  }
  memcpy(exe_ehdr, ehdr_ehdr, sizeof(ElfW(Ehdr)));
  if (munmap(exe_ehdr, page_size) == -1) {
    fprintf(stderr, "%s: can't munmap '%s'. Errno = %d (%s)\n", pgm_name,
            exe_name, errno, strerror(errno));
    exit(1);
  }
  if (close(fd) == -1) {
    fprintf(stderr, "%s: can't close '%s'. Errno = %d (%s)\n", pgm_name,
            exe_name, errno, strerror(errno));
    exit(1);
  }
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1090 <ElfW@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1090 <ElfW@plt>
cmpl   $0x3,-0x8(%rbp)
je     120f <main+0x6f>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10a0 <getpagesize@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12b1 <main+0x111>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x3c(%rbp),%r8d
mov    %rax,%r9
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    0x2d3c(%rip),%rax
mov    (%rax),%edx
mov    0x2cd3(%rip),%rax
mov    (%rax),%ecx
mov    -0x2c(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %eax,%ecx
mov    0x2cf9(%rip),%rax
mov    %ecx,(%rax)
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    0x2c97(%rip),%rcx
cmp    (%rcx),%eax
jne    1359 <main+0x1b9>
mov    0x2cb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%r8d
mov    %rax,%r9
lea    0xcf6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    13d0 <main+0x230>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2c18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2c0c(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x70(%rbp),%r8d
mov    %rax,%r9
lea    0xca5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2bf5(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1467 <main+0x2c7>
mov    0x2bba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    0x2b8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2b7e(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rdx
mov    -0x90(%rbp),%rcx
mov    -0x88(%rbp),%r8d
mov    %rax,%r9
lea    0xbc2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    0x2b2e(%rip),%rax
mov    (%rax),%edx
mov    0x2b6d(%rip),%rax
mov    (%rax),%ecx
mov    -0x2c(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %eax,%ecx
mov    0x2afb(%rip),%rax
mov    %ecx,(%rax)
mov    0x2af2(%rip),%rax
mov    (%rax),%eax
mov    0x2ae1(%rip),%rcx
cmp    (%rcx),%eax
jne    1527 <main+0x387>
mov    0x2afa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2acd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
mov    0x2abe(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    -0xa0(%rbp),%r8d
mov    %rax,%r9
lea    0xb28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2a62(%rip),%rax
mov    (%rax),%edi
mov    0x2aa1(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0x2a46(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rsi
call   1070 <munmap@plt>
cmp    $0xffffffff,%eax
jne    15d6 <main+0x436>
mov    0x2a4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xcc(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    0x2a1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
mov    0x2a0f(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rdx
mov    -0xc0(%rbp),%rcx
mov    -0xb8(%rbp),%r8d
mov    %rax,%r9
lea    0xac6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    165f <main+0x4bf>
mov    0x29c2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    0x2995(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2986(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xe4(%rbp),%edi
mov    -0xe0(%rbp),%rdx
mov    -0xd8(%rbp),%rcx
mov    -0xd0(%rbp),%r8d
mov    %rax,%r9
lea    0xa16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
mov    (%rsi),%r15
mov    0x2e0e(%rip),%r14
mov    (%r14),%edi
call   1090 <ElfW@plt>
mov    (%r14),%edi
call   1090 <ElfW@plt>
cmp    $0x3,%ebx
jne    1227 <main+0x87>
mov    0x8(%rbp),%r13
mov    0x10(%rbp),%rbx
xor    %eax,%eax
call   10a0 <getpagesize@plt>
mov    %rax,%r12
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    124b <main+0xab>
mov    0x2db2(%rip),%rax
mov    (%rax),%ebp
mov    0x2da1(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xe01(%rip),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %ebx,%r8d
jmp    12e1 <main+0x141>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    %rbx,(%rsp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    0x2d37(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r12,%rsi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2d5e(%rip),%rbx
mov    %eax,(%rbx)
mov    0x2d05(%rip),%r14
cmp    (%r14),%eax
jne    12aa <main+0x10a>
mov    0x2d21(%rip),%rax
mov    (%rax),%ebx
mov    0x2d10(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xd96(%rip),%rsi
jmp    12d6 <main+0x136>
mov    %ebp,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    12f5 <main+0x155>
mov    0x2cf3(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce2(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xd8e(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %ebp,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%esi
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    133e <main+0x19e>
mov    0x2c9a(%rip),%rax
mov    (%rax),%r14d
mov    0x2c88(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xce8(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %rbp,%rcx
jmp    121f <main+0x7f>
mov    %eax,%r13d
mov    0x2c58(%rip),%rax
mov    (%rax),%edx
mov    0x2c97(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2c26(%rip),%rbp
mov    %eax,0x0(%rbp)
cmp    (%r14),%eax
jne    1394 <main+0x1f4>
mov    0x2c37(%rip),%rax
mov    (%rax),%ebx
mov    0x2c26(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xcac(%rip),%rsi
jmp    1401 <main+0x261>
mov    (%rbx),%esi
mov    %eax,%edi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1070 <munmap@plt>
cmp    $0xffffffff,%eax
jne    13d4 <main+0x234>
mov    0x2bf7(%rip),%rax
mov    (%rax),%ebx
mov    0x2be6(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xcb9(%rip),%rsi
jmp    1401 <main+0x261>
mov    %r13d,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    140f <main+0x26f>
mov    0x2bc8(%rip),%rax
mov    (%rax),%ebx
mov    0x2bb7(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xc63(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    (%rsp),%rcx
jmp    12de <main+0x13e>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@Ehdr = global i32 0
@ehdr_ehdr = global i32 0
@exe_ehdr = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <ehdr> <exe>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"%s: can't open '%s'. Errno = %d (%s)\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i32 0
@.str.2 = [38 x i8] c"%s: can't mmap '%s'. Errno = %d (%s)\0A\00"
@.str.3 = [39 x i8] c"%s: can't close '%s'. Errno = %d (%s)\0A\00"
@O_RDWR = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [40 x i8] c"%s: can't munmap '%s'. Errno = %d (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i32, i32* @Ehdr
%15 = call i32 @ElfW(i32 %14)
%16 = load i32, i32* @ehdr_ehdr
%17 = mul nsw i32 %15, %16
%18 = load i32, i32* @Ehdr
%19 = call i32 @ElfW(i32 %18)
%20 = load i32, i32* @exe_ehdr
%21 = mul nsw i32 %19, %20
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 3
br i1 %23, label %24, label %29
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %6
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
store i8* %32, i8** %7
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
store i8* %35, i8** %8
%36 = call i64 (...) @getpagesize()
store i64 %36, i64* %10
%37 = load i8*, i8** %7
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %51
42: ; preds = %29
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = load i32, i32* @errno
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %45, i32 %46, i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %29
%52 = load i64, i64* %10
%53 = load i32, i32* @PROT_READ
%54 = load i32, i32* @MAP_PRIVATE
%55 = load i32, i32* %9
%56 = call i32 @mmap(i32 0, i64 %52, i32 %53, i32 %54, i32 %55, i32 0)
store i32 %56, i32* @ehdr_ehdr
%57 = load i32, i32* @ehdr_ehdr
%58 = load i32, i32* @MAP_FAILED
%59 = icmp eq i32 %57, %58
br i1 %59, label %60, label %69
60: ; preds = %51
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %6
%63 = load i8*, i8** %7
%64 = load i32, i32* @errno
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %62, i8* %63, i32 %64, i8* %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %51
%70 = load i32, i32* %9
%71 = call i32 @close(i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %82
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = load i8*, i8** %6
%76 = load i8*, i8** %7
%77 = load i32, i32* @errno
%78 = load i32, i32* @errno
%79 = call i8* @strerror(i32 %78)
%80 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %76, i32 %77, i8* %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %69
%83 = load i8*, i8** %8
%84 = load i32, i32* @O_RDWR
%85 = call i32 @open(i8* %83, i32 %84)
store i32 %85, i32* %9
%86 = load i32, i32* %9
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %97
88: ; preds = %82
%89 = load i32, i32* @stderr
%90 = load i8*, i8** %6
%91 = load i8*, i8** %8
%92 = load i32, i32* @errno
%93 = load i32, i32* @errno
%94 = call i8* @strerror(i32 %93)
%95 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %90, i8* %91, i32 %92, i8* %94)
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %82
%98 = load i64, i64* %10
%99 = load i32, i32* @PROT_WRITE
%100 = load i32, i32* @MAP_SHARED
%101 = load i32, i32* %9
%102 = call i32 @mmap(i32 0, i64 %98, i32 %99, i32 %100, i32 %101, i32 0)
store i32 %102, i32* @exe_ehdr
%103 = load i32, i32* @exe_ehdr
%104 = load i32, i32* @MAP_FAILED
%105 = icmp eq i32 %103, %104
br i1 %105, label %106, label %115
106: ; preds = %97
%107 = load i32, i32* @stderr
%108 = load i8*, i8** %6
%109 = load i8*, i8** %8
%110 = load i32, i32* @errno
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %108, i8* %109, i32 %110, i8* %112)
%114 = call i32 @exit(i32 1)
unreachable
115: ; preds = %97
%116 = load i32, i32* @exe_ehdr
%117 = load i32, i32* @ehdr_ehdr
%118 = call i32 @memcpy(i32 %116, i32 %117, i32 4)
%119 = load i32, i32* @exe_ehdr
%120 = load i64, i64* %10
%121 = call i32 @munmap(i32 %119, i64 %120)
%122 = icmp eq i32 %121, -1
br i1 %122, label %123, label %132
123: ; preds = %115
%124 = load i32, i32* @stderr
%125 = load i8*, i8** %6
%126 = load i8*, i8** %8
%127 = load i32, i32* @errno
%128 = load i32, i32* @errno
%129 = call i8* @strerror(i32 %128)
%130 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %125, i8* %126, i32 %127, i8* %129)
%131 = call i32 @exit(i32 1)
unreachable
132: ; preds = %115
%133 = load i32, i32* %9
%134 = call i32 @close(i32 %133)
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %145
136: ; preds = %132
%137 = load i32, i32* @stderr
%138 = load i8*, i8** %6
%139 = load i8*, i8** %8
%140 = load i32, i32* @errno
%141 = load i32, i32* @errno
%142 = call i8* @strerror(i32 %141)
%143 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %137, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %138, i8* %139, i32 %140, i8* %142)
%144 = call i32 @exit(i32 1)
unreachable
145: ; preds = %132
%146 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@Ehdr = global i32 0
@ehdr_ehdr = global i32 0
@exe_ehdr = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <ehdr> <exe>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"%s: can't open '%s'. Errno = %d (%s)\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i32 0
@.str.2 = [38 x i8] c"%s: can't mmap '%s'. Errno = %d (%s)\0A\00"
@.str.3 = [39 x i8] c"%s: can't close '%s'. Errno = %d (%s)\0A\00"
@O_RDWR = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [40 x i8] c"%s: can't munmap '%s'. Errno = %d (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = load i32, i32* @Ehdr
%5 = tail call i32 @ElfW(i32 %4)
%6 = load i32, i32* @Ehdr
%7 = tail call i32 @ElfW(i32 %6)
%8 = icmp eq i32 %0, 3
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %3)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 (...) @getpagesize()
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %15, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %15, i32 %24, i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %13
%29 = load i32, i32* @PROT_READ
%30 = load i32, i32* @MAP_PRIVATE
%31 = tail call i32 @mmap(i32 0, i64 %18, i32 %29, i32 %30, i32 %20, i32 0)
store i32 %31, i32* @ehdr_ehdr
%32 = load i32, i32* @MAP_FAILED
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %15, i32 %36, i8* %37)
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %28
%41 = tail call i32 @close(i32 %20)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = tail call i8* @strerror(i32 %45)
%47 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %15, i32 %45, i8* %46)
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %40
%50 = load i32, i32* @O_RDWR
%51 = tail call i32 @open(i8* %17, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = tail call i8* @strerror(i32 %55)
%57 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %17, i32 %55, i8* %56)
%58 = tail call i32 @exit(i32 1)
unreachable
59: ; preds = %49
%60 = load i32, i32* @PROT_WRITE
%61 = load i32, i32* @MAP_SHARED
%62 = tail call i32 @mmap(i32 0, i64 %18, i32 %60, i32 %61, i32 %51, i32 0)
store i32 %62, i32* @exe_ehdr
%63 = load i32, i32* @MAP_FAILED
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %71
65: ; preds = %59
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = tail call i8* @strerror(i32 %67)
%69 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %17, i32 %67, i8* %68)
%70 = tail call i32 @exit(i32 1)
unreachable
71: ; preds = %59
%72 = load i32, i32* @ehdr_ehdr
%73 = tail call i32 @memcpy(i32 %62, i32 %72, i32 4)
%74 = load i32, i32* @exe_ehdr
%75 = tail call i32 @munmap(i32 %74, i64 %18)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %83
77: ; preds = %71
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = tail call i8* @strerror(i32 %79)
%81 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %3, i8* %17, i32 %79, i8* %80)
%82 = tail call i32 @exit(i32 1)
unreachable
83: ; preds = %71
%84 = tail call i32 @close(i32 %51)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %92
86: ; preds = %83
%87 = load i32, i32* @stderr
%88 = load i32, i32* @errno
%89 = tail call i8* @strerror(i32 %88)
%90 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %17, i32 %88, i8* %89)
%91 = tail call i32 @exit(i32 1)
unreachable
92: ; preds = %83
%93 = tail call i32 @exit(i32 0)
unreachable
}