#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ int2le(int, unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int ccpmp_encode(char *iname, char *oname) {
  size_t len;
  int length;
  FILE *file;
  unsigned char *outbuf;
  file = fopen(iname, "rb");
  if (!file) {
    perror(iname);
    return -1;
  }
  fseek(file, 0, SEEK_END);
  length = ftell(file);
  fseek(file, 0, SEEK_SET);
  outbuf = malloc(0x500000);
  if (!outbuf) {
    printf("out of memory!\n");
    return -1;
  }
  len = fread(outbuf, 1, length, file);
  if (len < (size_t)length) {
    perror(iname);
    return -2;
  }
  fclose(file);
  memset(&outbuf[length], 0xFF, 0x500000 - length);
  int2le(length, &outbuf[0x4]);
  file = fopen(oname, "wb");
  if (!file) {
    perror(oname);
    return -3;
  }
  len = fwrite(outbuf, 1, 0x500000, file);
  if (len < (size_t)length) {
    perror(oname);
    return -4;
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<ccpmp_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f4 <ccpmp_encode+0x44>
mov    -0x10(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1353 <ccpmp_encode+0x1a3>
mov    -0x30(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    $0x500000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1259 <ccpmp_encode+0xa9>
lea    0xdbb(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1353 <ccpmp_encode+0x1a3>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jae    1298 <ccpmp_encode+0xe8>
mov    -0x10(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1353 <ccpmp_encode+0x1a3>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    $0x500000,%edx
sub    -0x24(%rbp),%edx
mov    $0xff,%esi
call   1060 <memset@plt>
mov    -0x24(%rbp),%edi
mov    -0x38(%rbp),%rsi
add    $0x4,%rsi
call   10c0 <int2le@plt>
mov    -0x18(%rbp),%rdi
lea    0xd3a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1302 <ccpmp_encode+0x152>
mov    -0x18(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1353 <ccpmp_encode+0x1a3>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x500000,%edx
call   10d0 <fwrite@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jae    1343 <ccpmp_encode+0x193>
mov    -0x18(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1353 <ccpmp_encode+0x1a3>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccpmp_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe38(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12c8 <ccpmp_encode+0x118>
mov    %rax,%rbx
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%r13d
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    $0x500000,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12a8 <ccpmp_encode+0xf8>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movslq %r13d,%rbp
cmp    %rbp,%rax
jb     12d2 <ccpmp_encode+0x122>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    (%r12,%rbp,1),%rdi
mov    $0x500000,%edx
sub    %ebp,%edx
mov    $0xff,%esi
call   1060 <memset@plt>
mov    %r12,%rsi
add    $0x4,%rsi
mov    %r13d,%edi
call   10c0 <int2le@plt>
lea    0xd91(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12e1 <ccpmp_encode+0x131>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x500000,%edx
mov    %rax,%rcx
call   10d0 <fwrite@plt>
cmp    %rbp,%rax
jb     12f0 <ccpmp_encode+0x140>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    12b9 <ccpmp_encode+0x109>
lea    0xd57(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   10b0 <perror@plt>
jmp    12b4 <ccpmp_encode+0x104>
mov    %r15,%rdi
call   10b0 <perror@plt>
mov    $0xfffffffe,%eax
jmp    12b9 <ccpmp_encode+0x109>
mov    %r14,%rdi
call   10b0 <perror@plt>
mov    $0xfffffffd,%eax
jmp    12b9 <ccpmp_encode+0x109>
mov    %r14,%rdi
call   10b0 <perror@plt>
mov    $0xfffffffc,%eax
jmp    12b9 <ccpmp_encode+0x109>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [16 x i8] c"out of memory!\0A\00"
@.str.2 = [3 x i8] c"wb\00"
define i32 @ccpmp_encode(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @perror(i8* %15)
store i32 -1, i32* %3
br label %78
17: ; preds = %2
%18 = load i32*, i32** %8
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = load i32*, i32** %8
%22 = call i32 @ftell(i32* %21)
store i32 %22, i32* %7
%23 = load i32*, i32** %8
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = call i8* @malloc(i32 5242880)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %17
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %78
31: ; preds = %17
%32 = load i8*, i8** %9
%33 = load i32, i32* %7
%34 = load i32*, i32** %8
%35 = call i64 @fread(i8* %32, i32 1, i32 %33, i32* %34)
store i64 %35, i64* %6
%36 = load i64, i64* %6
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = icmp ult i64 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %31
%41 = load i8*, i8** %4
%42 = call i32 @perror(i8* %41)
store i32 -2, i32* %3
br label %78
43: ; preds = %31
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %9
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i32, i32* %7
%51 = sub nsw i32 5242880, %50
%52 = call i32 @memset(i8* %49, i32 255, i32 %51)
%53 = load i32, i32* %7
%54 = load i8*, i8** %9
%55 = getelementptr inbounds i8, i8* %54, i64 4
%56 = call i32 @int2le(i32 %53, i8* %55)
%57 = load i8*, i8** %5
%58 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %58, i32** %8
%59 = load i32*, i32** %8
%60 = icmp ne i32* %59, null
br i1 %60, label %64, label %61
61: ; preds = %43
%62 = load i8*, i8** %5
%63 = call i32 @perror(i8* %62)
store i32 -3, i32* %3
br label %78
64: ; preds = %43
%65 = load i8*, i8** %9
%66 = load i32*, i32** %8
%67 = call i64 @fwrite(i8* %65, i32 1, i32 5242880, i32* %66)
store i64 %67, i64* %6
%68 = load i64, i64* %6
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = icmp ult i64 %68, %70
br i1 %71, label %72, label %75
72: ; preds = %64
%73 = load i8*, i8** %5
%74 = call i32 @perror(i8* %73)
store i32 -4, i32* %3
br label %78
75: ; preds = %64
%76 = load i32*, i32** %8
%77 = call i32 @fclose(i32* %76)
store i32 0, i32* %3
br label %78
78: ; preds = %75, %72, %61, %40, %29, %14
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@str = [15 x i8] c"out of memory!\00"
define i32 @ccpmp_encode(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* %0)
br label %41
7: ; preds = %2
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %3, i32 0, i32 %8)
%10 = tail call i32 @ftell(i32* %3)
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %3, i32 0, i32 %11)
%13 = tail call dereferenceable_or_null(5242880) i8* @malloc(i32 5242880)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %41
17: ; preds = %7
%18 = tail call i64 @fread(i8* %13, i32 1, i32 %10, i32* %3)
%19 = sext i32 %10 to i64
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @perror(i8* %0)
br label %41
23: ; preds = %17
%24 = tail call i32 @fclose(i32* %3)
%25 = getelementptr inbounds i8, i8* %13, i64 %19
%26 = sub nsw i32 5242880, %10
%27 = tail call i32 @memset(i8* %25, i32 255, i32 %26)
%28 = getelementptr inbounds i8, i8* %13, i64 4
%29 = tail call i32 @int2le(i32 %10, i8* %28)
%30 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = tail call i32 @perror(i8* %1)
br label %41
34: ; preds = %23
%35 = tail call i64 @fwrite(i8* %13, i32 1, i32 5242880, i32* %30)
%36 = icmp ult i64 %35, %19
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = tail call i32 @perror(i8* %1)
br label %41
39: ; preds = %34
%40 = tail call i32 @fclose(i32* %30)
br label %41
41: ; preds = %39, %37, %32, %21, %15, %5
%42 = phi i32 [ -2, %21 ], [ -4, %37 ], [ 0, %39 ], [ -3, %32 ], [ -1, %15 ], [ -1, %5 ]
ret i32 %42
}