#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*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
unsigned long os_zlib_compress(char *, char *, unsigned long, unsigned long);
unsigned long os_zlib_uncompress(char *, char *, unsigned long, unsigned long);
int /*<<< orphan*/ printf(char *, ...);
unsigned long strlen(char *);
int main(int argc, char **argv) {
  unsigned long int ret, srcsize, dstsize = 2010;
  char dst[2048];
  char dst2[2048];
  memset(dst, 0, 2048);
  memset(dst2, 0, 2048);
  if (argc < 2) {
    printf("%s: string\n", argv[0]);
    exit(1);
  }
  srcsize = strlen(argv[1]);
  if (srcsize > 2000) {
    printf("%s: string too large\n", argv[0]);
    exit(1);
  }
  if ((ret = os_zlib_compress(argv[1], dst, srcsize, dstsize))) {
    printf("Compressed, from %lu->%lu\n", srcsize, ret);
  } else {
    printf("FAILED compressing.\n");
    exit(1);
  }
  srcsize = ret;
  if ((ret = os_zlib_uncompress(dst, dst2, srcsize, dstsize))) {
    printf("Uncompressed ok. String: '%s', size %lu->%lu\n", dst2, srcsize,
           ret);
  } else {
    printf("FAILED uncompressing.\n");
    exit(1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x7da,-0x28(%rbp)
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11d0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x7d0,-0x20(%rbp)
jbe    120e <main+0xae>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x830(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1070 <os_zlib_compress@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1253 <main+0xf3>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126b <main+0x10b>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x830(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <os_zlib_uncompress@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12be <main+0x15e>
lea    -0x1030(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d6 <main+0x176>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x800(%rsp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
cmp    $0x1,%ebx
jle    1243 <main+0xd3>
mov    0x8(%r14),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x7d1,%rax
jae    124f <main+0xdf>
mov    %rax,%rbx
lea    0x800(%rsp),%rsi
mov    $0x7da,%ecx
mov    %r15,%rdi
mov    %rax,%rdx
call   1080 <os_zlib_compress@plt>
test   %rax,%rax
je     126a <main+0xfa>
mov    %rax,%r14
lea    0xe2f(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x800(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x7da,%ecx
mov    %r14,%rdx
call   1050 <os_zlib_uncompress@plt>
test   %rax,%rax
je     1273 <main+0x103>
lea    0xe19(%rip),%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r14),%rsi
lea    0xdb3(%rip),%rdi
jmp    1259 <main+0xe9>
mov    (%r14),%rsi
lea    0xdb3(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdfa(%rip),%rdi
jmp    127a <main+0x10a>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%s: string\0A\00"
@.str.1 = [22 x i8] c"%s: string too large\0A\00"
@.str.2 = [27 x i8] c"Compressed, from %lu->%lu\0A\00"
@.str.3 = [21 x i8] c"FAILED compressing.\0A\00"
@.str.4 = [46 x i8] c"Uncompressed ok. String: '%s', size %lu->%lu\0A\00"
@.str.5 = [23 x i8] c"FAILED uncompressing.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca [2048 x i8]
%10 = alloca [2048 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 2010, i64* %8
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 2048)
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 2048)
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strlen(i8* %26)
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = icmp ugt i64 %28, 2000
br i1 %29, label %30, label %36
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %23
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%41 = load i64, i64* %7
%42 = load i64, i64* %8
%43 = call i64 @os_zlib_compress(i8* %39, i8* %40, i64 %41, i64 %42)
store i64 %43, i64* %6
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %36
%46 = load i64, i64* %7
%47 = load i64, i64* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %46, i64 %47)
br label %52
49: ; preds = %36
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %45
%53 = load i64, i64* %6
store i64 %53, i64* %7
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%56 = load i64, i64* %7
%57 = load i64, i64* %8
%58 = call i64 @os_zlib_uncompress(i8* %54, i8* %55, i64 %56, i64 %57)
store i64 %58, i64* %6
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %52
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%62 = load i64, i64* %7
%63 = load i64, i64* %6
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %61, i64 %62, i64 %63)
br label %68
65: ; preds = %52
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %60
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s: string\0A\00"
@.str.1 = [22 x i8] c"%s: string too large\0A\00"
@.str.2 = [27 x i8] c"Compressed, from %lu->%lu\0A\00"
@.str.4 = [46 x i8] c"Uncompressed ok. String: '%s', size %lu->%lu\0A\00"
@str = [20 x i8] c"FAILED compressing.\00"
@str.6 = [22 x i8] c"FAILED uncompressing.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i32 0, i32 2048)
%8 = call i32 @memset(i8* %6, i32 0, i32 2048)
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strlen(i8* dereferenceable(1) %16)
%18 = icmp ugt i64 %17, 2000
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = call i64 @os_zlib_compress(i8* %16, i8* %5, i64 %17, i64 2010)
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %17, i64 %24)
%28 = call i64 @os_zlib_uncompress(i8* %5, i8* %6, i64 %24, i64 2010)
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %33
30: ; preds = %23
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %6, i64 %24, i64 %28)
ret i32 0
35: ; preds = %26
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
}