#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ pi_pack(char **, int *, char *, int);
scalar_t__ pi_read(int /*<<< orphan*/ **, char **, size_t *, char *);
scalar_t__ pi_write(int /*<<< orphan*/ **, char *, size_t, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int compress(char *filename, char *outputname) {
  int rc = 0, counter = 0;
  size_t input_filesize = 0;
  char *input_filename = NULL, *input_filedata = NULL;
  char *output_filename = NULL, *output_filedata = NULL;
  FILE *input = NULL, *output = NULL;
  input_filename = malloc(sizeof(char) * (int)strlen(filename) + 1);
  if (!input_filename) {
    printf("Memory error\n");
    rc = 1;
    goto cleanup;
  }
  strcpy(input_filename, filename);
  if (pi_read(&input, &input_filedata, &input_filesize, input_filename) != 0) {
    rc = 1;
    goto cleanup;
  }
  if (outputname) {
    output_filename = malloc(sizeof(char) * (int)strlen(outputname) + 1);
  } else {
    output_filename = malloc(sizeof(char) * (int)strlen(input_filename) + 10);
  }
  if (!output_filename) {
    printf("Memory error\n");
    rc = 1;
    goto cleanup;
  }
  if (outputname) {
    strcpy(output_filename, outputname);
  } else {
    strcpy(output_filename, input_filename);
    strcat(output_filename, ".compress");
  }
  pi_pack(&output_filedata, &counter, input_filedata, (int)input_filesize);
  if (pi_write(&output, output_filedata, (size_t)counter, output_filename) !=
      0) {
    rc = 1;
    goto cleanup;
  }
cleanup:
  if (input_filename) {
    free(input_filename);
  }
  if (output_filename) {
    free(output_filename);
  }
  if (input_filedata) {
    free(input_filedata);
  }
  if (output_filedata) {
    free(output_filedata);
  }
  return rc;
}


x86 assembly (clang, -O0):
<compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1227 <compress+0x97>
lea    0xdea(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    134f <compress+0x1bf>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rcx
lea    -0x48(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10a0 <pi_read@plt>
cmp    $0x0,%rax
je     125f <compress+0xcf>
movl   $0x1,-0x14(%rbp)
jmp    134f <compress+0x1bf>
cmpq   $0x0,-0x10(%rbp)
je     128d <compress+0xfd>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
jmp    12ab <compress+0x11b>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0xa,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12ce <compress+0x13e>
lea    0xd43(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    134f <compress+0x1bf>
cmpq   $0x0,-0x10(%rbp)
je     12eb <compress+0x15b>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1308 <compress+0x178>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xd0b(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
lea    -0x40(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <pi_pack@plt>
mov    -0x40(%rbp),%rsi
movslq -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    -0x50(%rbp),%rdi
call   1090 <pi_write@plt>
cmp    $0x0,%rax
je     134a <compress+0x1ba>
movl   $0x1,-0x14(%rbp)
jmp    134f <compress+0x1bf>
jmp    134f <compress+0x1bf>
cmpq   $0x0,-0x28(%rbp)
je     1363 <compress+0x1d3>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     1377 <compress+0x1e7>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     138b <compress+0x1fb>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     139f <compress+0x20f>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
movl   $0x0,0xc(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1223 <compress+0x93>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0x30(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %rbx,%rcx
call   10a0 <pi_read@plt>
test   %rax,%rax
je     1239 <compress+0xa9>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
jmp    12e5 <compress+0x155>
lea    0xde0(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%ebp
jmp    12e5 <compress+0x155>
test   %r14,%r14
je     1267 <compress+0xd7>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1310 <compress+0x180>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
jmp    129d <compress+0x10d>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xa(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1310 <compress+0x180>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xd6b(%rip),%rsi
mov    %r15,%rdi
call   10b0 <strcat@plt>
mov    0x18(%rsp),%rdx
mov    0x20(%rsp),%ecx
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1070 <pi_pack@plt>
mov    0x10(%rsp),%rsi
movslq 0xc(%rsp),%rdx
lea    0x28(%rsp),%rdi
mov    %r15,%rcx
call   1090 <pi_write@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     12f4 <compress+0x164>
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1303 <compress+0x173>
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf3(%rip),%rdi
call   1050 <puts@plt>
jmp    1211 <compress+0x81>

LLVM IR (-O0):
@.str = [14 x i8] c"Memory error\0A\00"
@.str.1 = [10 x i8] c".compress\00"
define i32 @compress(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i64 0, i64* %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
store i32* null, i32** %12
store i32* null, i32** %13
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = trunc i64 %15 to i32
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = add i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %2
%25 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %86
26: ; preds = %2
%27 = load i8*, i8** %8
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %8
%31 = call i64 @pi_read(i32** %12, i8** %9, i64* %7, i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 1, i32* %5
br label %86
34: ; preds = %26
%35 = load i8*, i8** %4
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = call i64 @strlen(i8* %38)
%40 = trunc i64 %39 to i32
%41 = sext i32 %40 to i64
%42 = mul i64 1, %41
%43 = add i64 %42, 1
%44 = trunc i64 %43 to i32
%45 = call i8* @malloc(i32 %44)
store i8* %45, i8** %10
br label %55
46: ; preds = %34
%47 = load i8*, i8** %8
%48 = call i64 @strlen(i8* %47)
%49 = trunc i64 %48 to i32
%50 = sext i32 %49 to i64
%51 = mul i64 1, %50
%52 = add i64 %51, 10
%53 = trunc i64 %52 to i32
%54 = call i8* @malloc(i32 %53)
store i8* %54, i8** %10
br label %55
55: ; preds = %46, %37
%56 = load i8*, i8** %10
%57 = icmp ne i8* %56, null
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %86
60: ; preds = %55
%61 = load i8*, i8** %4
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = load i8*, i8** %10
%65 = load i8*, i8** %4
%66 = call i32 @strcpy(i8* %64, i8* %65)
br label %73
67: ; preds = %60
%68 = load i8*, i8** %10
%69 = load i8*, i8** %8
%70 = call i32 @strcpy(i8* %68, i8* %69)
%71 = load i8*, i8** %10
%72 = call i32 @strcat(i8* %71, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %73
73: ; preds = %67, %63
%74 = load i8*, i8** %9
%75 = load i64, i64* %7
%76 = trunc i64 %75 to i32
%77 = call i32 @pi_pack(i8** %11, i32* %6, i8* %74, i32 %76)
%78 = load i8*, i8** %11
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = load i8*, i8** %10
%82 = call i64 @pi_write(i32** %13, i8* %78, i64 %80, i8* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %73
store i32 1, i32* %5
br label %86
85: ; preds = %73
br label %86
86: ; preds = %85, %84, %58, %33, %24
%87 = load i8*, i8** %8
%88 = icmp ne i8* %87, null
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i8*, i8** %8
%91 = call i32 @free(i8* %90)
br label %92
92: ; preds = %89, %86
%93 = load i8*, i8** %10
%94 = icmp ne i8* %93, null
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = load i8*, i8** %10
%97 = call i32 @free(i8* %96)
br label %98
98: ; preds = %95, %92
%99 = load i8*, i8** %9
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i8*, i8** %9
%103 = call i32 @free(i8* %102)
br label %104
104: ; preds = %101, %98
%105 = load i8*, i8** %11
%106 = icmp ne i8* %105, null
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i8*, i8** %11
%109 = call i32 @free(i8* %108)
br label %110
110: ; preds = %107, %104
%111 = load i32, i32* %5
ret i32 %111
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c".compress\00"
@str.2 = [13 x i8] c"Memory error\00"
define i32 @compress(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%11 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%12 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%13 = bitcast i32** %7 to i8*
store i32* null, i32** %7
%14 = bitcast i32** %8 to i8*
store i32* null, i32** %8
%15 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%16 = trunc i64 %15 to i32
%17 = add i32 %16, 1
%18 = tail call i8* @malloc(i32 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %45, label %20
20: ; preds = %2
%21 = tail call i32 @strcpy(i8* %18, i8* %0)
%22 = call i64 @pi_read(i32** %7, i8** %5, i64* %4, i8* %18)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %47
24: ; preds = %20
%25 = icmp eq i8* %1, null
br i1 %25, label %26, label %32
26: ; preds = %24
%27 = call i64 @strlen(i8* %18)
%28 = trunc i64 %27 to i32
%29 = add i32 %28, 10
%30 = call i8* @malloc(i32 %29)
%31 = icmp eq i8* %30, null
br i1 %31, label %38, label %42
32: ; preds = %24
%33 = call i64 @strlen(i8* %1)
%34 = trunc i64 %33 to i32
%35 = add i32 %34, 1
%36 = call i8* @malloc(i32 %35)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %32, %26
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.2, i64 0, i64 0))
br label %47
40: ; preds = %32
%41 = call i32 @strcpy(i8* %36, i8* %1)
br label %49
42: ; preds = %26
%43 = call i32 @strcpy(i8* %30, i8* %18)
%44 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %49
45: ; preds = %2
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.2, i64 0, i64 0))
br label %63
47: ; preds = %20, %38
%48 = call i32 @free(i8* %18)
br label %63
49: ; preds = %42, %40
%50 = phi i8* [ %30, %42 ], [ %36, %40 ]
%51 = load i8*, i8** %5
%52 = load i64, i64* %4
%53 = trunc i64 %52 to i32
%54 = call i32 @pi_pack(i8** %6, i32* %3, i8* %51, i32 %53)
%55 = load i8*, i8** %6
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = call i64 @pi_write(i32** %8, i8* %55, i64 %57, i8* %50)
%59 = icmp ne i64 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @free(i8* %18)
%62 = call i32 @free(i8* %50)
br label %63
63: ; preds = %47, %45, %49
%64 = phi i32 [ 1, %45 ], [ %60, %49 ], [ 1, %47 ]
%65 = load i8*, i8** %5
%66 = icmp eq i8* %65, null
br i1 %66, label %69, label %67
67: ; preds = %63
%68 = call i32 @free(i8* %65)
br label %69
69: ; preds = %67, %63
%70 = load i8*, i8** %6
%71 = icmp eq i8* %70, null
br i1 %71, label %74, label %72
72: ; preds = %69
%73 = call i32 @free(i8* %70)
br label %74
74: ; preds = %72, %69
ret i32 %64
}