#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 */
typedef int size;

/* Variables and functions */
unsigned char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ftruncate(int, int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned char *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
                    int /*<<< orphan*/);
int /*<<< orphan*/ munmap(unsigned char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stubify_elf(unsigned char *, unsigned char *, int, int, int);
int /*<<< orphan*/ unlink(char *);
int pack_elf(char *src, char *dest, int level, int flags) {
  int in, out, size, t;
  unsigned char *i, *o;
  printf("Packing%s%s%s '%s' to '%s'\n", flags & 2 ? ", scrambling" : "",
         flags & 4 ? ", locking" : "", flags & 1 ? " without banner" : "", src,
         dest);
  in = open(src, O_RDONLY);
  if (in < 0) {
    perror(src);
    return 1;
  }
  out = open(dest, O_CREAT | O_RDWR | O_TRUNC, 0744);
  if (out < 0) {
    perror(dest);
    return 1;
  }
  size = lseek(in, 0, SEEK_END);
  ftruncate(out, ((size * 2) & (~4095)) + 4096);
  i = mmap(NULL, (((size) + 4095) & (~4095)), PROT_READ, MAP_SHARED, in, 0);
  if (i == MAP_FAILED) {
    perror("mmap");
    close(in);
    close(out);
    return 1;
  }
  o = mmap(NULL, ((size * 2) & (~4095)) + 4096, PROT_READ | PROT_WRITE,
           MAP_SHARED, out, 0);
  if (o == MAP_FAILED) {
    perror("mmap");
    close(in);
    close(out);
    munmap(i, (((size) + 4095) & (~4095)));
    return 1;
  }
  t = stubify_elf(i, o, size, level, flags);
  munmap(i, (((size) + 4095) & (~4095)));
  munmap(o, ((size * 2) & (~4095)) + 4096);
  if (t >= 0) {
    printf("\rOk, compressed to %.2f%% (%d => %d)\n", t * 100.0 / size, size,
           t);
    ftruncate(out, t);
    close(out);
  } else {
    printf("\rCompression failed!\n");
    close(out);
    unlink(dest);
  }
  close(in);
  return t < 0 ? -1 : 0;
}


x86 assembly (clang, -O0):
<pack_elf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
and    $0x2,%ecx
lea    0xec8(%rip),%rsi
lea    0xe5a(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x20(%rbp),%ecx
and    $0x4,%ecx
lea    0xead(%rip),%rdx
lea    0xe4c(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x20(%rbp),%edi
and    $0x1,%edi
lea    0xe92(%rip),%rcx
lea    0xe3b(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1253 <pack_elf+0xb3>
mov    -0x10(%rbp),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ad <pack_elf+0x30d>
mov    -0x18(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    0x2d61(%rip),%rax
or     (%rax),%esi
mov    0x2d80(%rip),%rax
or     (%rax),%esi
mov    $0x1e4,%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    12a0 <pack_elf+0x100>
mov    -0x18(%rbp),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ad <pack_elf+0x30d>
mov    -0x24(%rbp),%edi
mov    0x2d16(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
shl    $0x1,%esi
and    $0xfffff000,%esi
add    $0x1000,%esi
call   1070 <ftruncate@plt>
mov    -0x2c(%rbp),%esi
add    $0xfff,%esi
and    $0xfffff000,%esi
mov    0x2d02(%rip),%rax
mov    (%rax),%edx
mov    0x2ce9(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2c90(%rip),%rcx
cmp    (%rcx),%rax
jne    1341 <pack_elf+0x1a1>
lea    0xd2b(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ad <pack_elf+0x30d>
mov    -0x2c(%rbp),%esi
shl    $0x1,%esi
and    $0xfffff000,%esi
add    $0x1000,%esi
mov    0x2c8e(%rip),%rax
mov    (%rax),%edx
mov    0x2c45(%rip),%rax
or     (%rax),%edx
mov    0x2c6c(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2c13(%rip),%rcx
cmp    (%rcx),%rax
jne    13d6 <pack_elf+0x236>
lea    0xcae(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0xfff,%esi
and    $0xfffff000,%esi
call   10a0 <munmap@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ad <pack_elf+0x30d>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1040 <stubify_elf@plt>
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0xfff,%esi
and    $0xfffff000,%esi
call   10a0 <munmap@plt>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
shl    $0x1,%esi
and    $0xfffff000,%esi
add    $0x1000,%esi
call   10a0 <munmap@plt>
cmpl   $0x0,-0x30(%rbp)
jl     1473 <pack_elf+0x2d3>
cvtsi2sdl -0x30(%rbp),%xmm0
movsd  0xbc6(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xbfc(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1070 <ftruncate@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
jmp    1492 <pack_elf+0x2f2>
lea    0xbfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x30(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_elf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbp
test   $0x2,%bl
lea    0xe50(%rip),%rax
lea    0xe4a(%rip),%rsi
cmove  %rax,%rsi
test   $0x4,%bl
lea    0xe49(%rip),%rdx
cmove  %rax,%rdx
test   $0x1,%bl
lea    0xe45(%rip),%rcx
cmove  %rax,%rcx
lea    0xe07(%rip),%rdi
mov    %rbp,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     13d1 <pack_elf+0x221>
mov    %eax,%r15d
mov    0x2dc5(%rip),%rax
mov    0x2d8e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dab(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1e4,%edx
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     13d6 <pack_elf+0x226>
mov    %eax,%ebp
mov    %r12d,0x8(%rsp)
mov    %ebx,0xc(%rsp)
mov    %r14,0x10(%rsp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
mov    %eax,%ebx
lea    (%rbx,%rbx,1),%r14d
add    $0x1000,%r14d
and    $0xfffff000,%r14d
mov    %ebp,%edi
mov    %r14d,%esi
call   1080 <ftruncate@plt>
lea    0xfff(%rbx),%r12d
and    $0xfffff000,%r12d
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
mov    0x2d1b(%rip),%r13
mov    0x0(%r13),%ecx
xor    %edi,%edi
mov    %r12d,%esi
mov    %r15d,(%rsp)
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%r15
mov    0x2cc1(%rip),%rax
cmp    (%rax),%r15
je     13e5 <pack_elf+0x235>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edx
mov    0x2cf0(%rip),%rax
or     (%rax),%edx
mov    0x0(%r13),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebp,0x4(%rsp)
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%r13
mov    0x2c84(%rip),%rax
cmp    (%rax),%r13
je     1407 <pack_elf+0x257>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
call   1050 <stubify_elf@plt>
mov    %rbx,%rbp
mov    %eax,%ebx
mov    %r15,%rdi
mov    %r12d,%esi
call   10b0 <munmap@plt>
mov    %r13,%rdi
mov    %r14d,%esi
call   10b0 <munmap@plt>
test   %ebx,%ebx
js     1396 <pack_elf+0x1e6>
cvtsi2sd %ebx,%xmm0
mulsd  0xc9a(%rip),%xmm0
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
lea    0xcdb(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    $0x1,%al
call   1070 <printf@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
mov    %ebx,%esi
call   1080 <ftruncate@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
jmp    13b5 <pack_elf+0x205>
lea    0xcd9(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
mov    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    (%rsp),%edi
call   10a0 <close@plt>
sar    $0x1f,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
jmp    13d9 <pack_elf+0x229>
mov    %r14,%rdi
call   10d0 <perror@plt>
mov    $0x1,%ebx
jmp    13c0 <pack_elf+0x210>
lea    0xc5f(%rip),%rdi
call   10d0 <perror@plt>
mov    (%rsp),%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    $0x1,%ebx
jmp    13c0 <pack_elf+0x210>
lea    0xc3d(%rip),%rdi
call   10d0 <perror@plt>
mov    (%rsp),%edi
call   10a0 <close@plt>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   10b0 <munmap@plt>
mov    $0x1,%ebx
jmp    13c0 <pack_elf+0x210>

LLVM IR (-O0):
@.str = [28 x i8] c"Packing%s%s%s '%s' to '%s'\0A\00"
@.str.1 = [13 x i8] c", scrambling\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [10 x i8] c", locking\00"
@.str.4 = [16 x i8] c" without banner\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@SEEK_END = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [5 x i8] c"mmap\00"
@PROT_WRITE = global i32 0
@.str.6 = [38 x i8] c"\0DOk, compressed to %.2f%% (%d => %d)\0A\00"
@.str.7 = [22 x i8] c"\0DCompression failed!\0A\00"
define i32 @pack_elf(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%16 = load i32, i32* %9
%17 = and i32 %16, 2
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%21 = load i32, i32* %9
%22 = and i32 %21, 4
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%26 = load i32, i32* %9
%27 = and i32 %26, 1
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%31 = load i8*, i8** %6
%32 = load i8*, i8** %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %25, i8* %30, i8* %31, i8* %32)
%34 = load i8*, i8** %6
%35 = load i32, i32* @O_RDONLY
%36 = call i32 (i8*, i32, ...) @open(i8* %34, i32 %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %4
%40 = load i8*, i8** %6
%41 = call i32 @perror(i8* %40)
store i32 1, i32* %5
br label %154
42: ; preds = %4
%43 = load i8*, i8** %7
%44 = load i32, i32* @O_CREAT
%45 = load i32, i32* @O_RDWR
%46 = or i32 %44, %45
%47 = load i32, i32* @O_TRUNC
%48 = or i32 %46, %47
%49 = call i32 (i8*, i32, ...) @open(i8* %43, i32 %48, i32 484)
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %42
%53 = load i8*, i8** %7
%54 = call i32 @perror(i8* %53)
store i32 1, i32* %5
br label %154
55: ; preds = %42
%56 = load i32, i32* %10
%57 = load i32, i32* @SEEK_END
%58 = call i32 @lseek(i32 %56, i32 0, i32 %57)
store i32 %58, i32* %12
%59 = load i32, i32* %11
%60 = load i32, i32* %12
%61 = mul nsw i32 %60, 2
%62 = and i32 %61, -4096
%63 = add nsw i32 %62, 4096
%64 = call i32 @ftruncate(i32 %59, i32 %63)
%65 = load i32, i32* %12
%66 = add nsw i32 %65, 4095
%67 = and i32 %66, -4096
%68 = load i32, i32* @PROT_READ
%69 = load i32, i32* @MAP_SHARED
%70 = load i32, i32* %10
%71 = call i8* @mmap(i32* null, i32 %67, i32 %68, i32 %69, i32 %70, i32 0)
store i8* %71, i8** %14
%72 = load i8*, i8** %14
%73 = load i8*, i8** @MAP_FAILED
%74 = icmp eq i8* %72, %73
br i1 %74, label %75, label %81
75: ; preds = %55
%76 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32, i32* %10
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* %11
%80 = call i32 @close(i32 %79)
store i32 1, i32* %5
br label %154
81: ; preds = %55
%82 = load i32, i32* %12
%83 = mul nsw i32 %82, 2
%84 = and i32 %83, -4096
%85 = add nsw i32 %84, 4096
%86 = load i32, i32* @PROT_READ
%87 = load i32, i32* @PROT_WRITE
%88 = or i32 %86, %87
%89 = load i32, i32* @MAP_SHARED
%90 = load i32, i32* %11
%91 = call i8* @mmap(i32* null, i32 %85, i32 %88, i32 %89, i32 %90, i32 0)
store i8* %91, i8** %15
%92 = load i8*, i8** %15
%93 = load i8*, i8** @MAP_FAILED
%94 = icmp eq i8* %92, %93
br i1 %94, label %95, label %106
95: ; preds = %81
%96 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%97 = load i32, i32* %10
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %11
%100 = call i32 @close(i32 %99)
%101 = load i8*, i8** %14
%102 = load i32, i32* %12
%103 = add nsw i32 %102, 4095
%104 = and i32 %103, -4096
%105 = call i32 @munmap(i8* %101, i32 %104)
store i32 1, i32* %5
br label %154
106: ; preds = %81
%107 = load i8*, i8** %14
%108 = load i8*, i8** %15
%109 = load i32, i32* %12
%110 = load i32, i32* %8
%111 = load i32, i32* %9
%112 = call i32 @stubify_elf(i8* %107, i8* %108, i32 %109, i32 %110, i32 %111)
store i32 %112, i32* %13
%113 = load i8*, i8** %14
%114 = load i32, i32* %12
%115 = add nsw i32 %114, 4095
%116 = and i32 %115, -4096
%117 = call i32 @munmap(i8* %113, i32 %116)
%118 = load i8*, i8** %15
%119 = load i32, i32* %12
%120 = mul nsw i32 %119, 2
%121 = and i32 %120, -4096
%122 = add nsw i32 %121, 4096
%123 = call i32 @munmap(i8* %118, i32 %122)
%124 = load i32, i32* %13
%125 = icmp sge i32 %124, 0
br i1 %125, label %126, label %141
126: ; preds = %106
%127 = load i32, i32* %13
%128 = sitofp i32 %127 to double
%129 = fmul double %128, 1.000000e+02
%130 = load i32, i32* %12
%131 = sitofp i32 %130 to double
%132 = fdiv double %129, %131
%133 = load i32, i32* %12
%134 = load i32, i32* %13
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), double %132, i32 %133, i32 %134)
%136 = load i32, i32* %11
%137 = load i32, i32* %13
%138 = call i32 @ftruncate(i32 %136, i32 %137)
%139 = load i32, i32* %11
%140 = call i32 @close(i32 %139)
br label %147
141: ; preds = %106
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%143 = load i32, i32* %11
%144 = call i32 @close(i32 %143)
%145 = load i8*, i8** %7
%146 = call i32 @unlink(i8* %145)
br label %147
147: ; preds = %141, %126
%148 = load i32, i32* %10
%149 = call i32 @close(i32 %148)
%150 = load i32, i32* %13
%151 = icmp slt i32 %150, 0
%152 = zext i1 %151 to i64
%153 = select i1 %151, i32 -1, i32 0
store i32 %153, i32* %5
br label %154
154: ; preds = %147, %95, %75, %52, %39
%155 = load i32, i32* %5
ret i32 %155
}

LLVM IR (-O2):
@.str = [28 x i8] c"Packing%s%s%s '%s' to '%s'\0A\00"
@.str.1 = [13 x i8] c", scrambling\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [10 x i8] c", locking\00"
@.str.4 = [16 x i8] c" without banner\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@SEEK_END = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [5 x i8] c"mmap\00"
@PROT_WRITE = global i32 0
@.str.6 = [38 x i8] c"\0DOk, compressed to %.2f%% (%d => %d)\0A\00"
@str = [21 x i8] c"\0DCompression failed!\00"
define i32 @pack_elf(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = and i32 %3, 2
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0)
%8 = and i32 %3, 4
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
%11 = and i32 %3, 1
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %10, i8* %13, i8* %0, i8* %1)
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = tail call i32 @perror(i8* %0)
br label %81
20: ; preds = %4
%21 = load i32, i32* @O_CREAT
%22 = load i32, i32* @O_RDWR
%23 = or i32 %22, %21
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %25, i32 484)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = tail call i32 @perror(i8* %1)
br label %81
30: ; preds = %20
%31 = load i32, i32* @SEEK_END
%32 = tail call i32 @lseek(i32 %16, i32 0, i32 %31)
%33 = shl nsw i32 %32, 1
%34 = add i32 %33, 4096
%35 = and i32 %34, -4096
%36 = tail call i32 @ftruncate(i32 %26, i32 %35)
%37 = add nsw i32 %32, 4095
%38 = and i32 %37, -4096
%39 = load i32, i32* @PROT_READ
%40 = load i32, i32* @MAP_SHARED
%41 = tail call i8* @mmap(i32* null, i32 %38, i32 %39, i32 %40, i32 %16, i32 0)
%42 = load i8*, i8** @MAP_FAILED
%43 = icmp eq i8* %41, %42
br i1 %43, label %44, label %48
44: ; preds = %30
%45 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%46 = tail call i32 @close(i32 %16)
%47 = tail call i32 @close(i32 %26)
br label %81
48: ; preds = %30
%49 = load i32, i32* @PROT_READ
%50 = load i32, i32* @PROT_WRITE
%51 = or i32 %50, %49
%52 = load i32, i32* @MAP_SHARED
%53 = tail call i8* @mmap(i32* null, i32 %35, i32 %51, i32 %52, i32 %26, i32 0)
%54 = load i8*, i8** @MAP_FAILED
%55 = icmp eq i8* %53, %54
br i1 %55, label %56, label %61
56: ; preds = %48
%57 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%58 = tail call i32 @close(i32 %16)
%59 = tail call i32 @close(i32 %26)
%60 = tail call i32 @munmap(i8* %41, i32 %38)
br label %81
61: ; preds = %48
%62 = tail call i32 @stubify_elf(i8* %41, i8* %53, i32 %32, i32 %2, i32 %3)
%63 = tail call i32 @munmap(i8* %41, i32 %38)
%64 = tail call i32 @munmap(i8* %53, i32 %35)
%65 = icmp sgt i32 %62, -1
br i1 %65, label %66, label %74
66: ; preds = %61
%67 = sitofp i32 %62 to double
%68 = fmul double %67, 1.000000e+02
%69 = sitofp i32 %32 to double
%70 = fdiv double %68, %69
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), double %70, i32 %32, i32 %62)
%72 = tail call i32 @ftruncate(i32 %26, i32 %62)
%73 = tail call i32 @close(i32 %26)
br label %78
74: ; preds = %61
%75 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%76 = tail call i32 @close(i32 %26)
%77 = tail call i32 @unlink(i8* %1)
br label %78
78: ; preds = %74, %66
%79 = tail call i32 @close(i32 %16)
%80 = ashr i32 %62, 31
br label %81
81: ; preds = %78, %56, %44, %28, %18
%82 = phi i32 [ 1, %18 ], [ 1, %28 ], [ 1, %44 ], [ 1, %56 ], [ %80, %78 ]
ret i32 %82
}