#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 Z_OK;
int compress2(unsigned char *, unsigned long *, unsigned char *,
              int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  unsigned char dest[32];
  unsigned long destLen = 31;
  int retval, i;
  int level;
  char *endptr;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s: <compression-level> <string>\n", argv[0]);
    return 1;
  }
  level = strtol(argv[1], &endptr, 10);
  if (endptr == argv[1] || level < 0 || level > 9) {
    fprintf(stderr, "Invalid compression level\n");
    return 1;
  }
  retval = compress2(dest, &destLen, (unsigned char *)argv[2], strlen(argv[2]),
                     level);
  if (retval != Z_OK) {
    fprintf(stderr, "Error calling zlib compress2 function: %d\n", retval);
    return 1;
  }
  for (i = 0; i < destLen; i++)
    printf("\\x%02hhx", dest[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1f,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a2 <main+0x52>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x176>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x50(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x44(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
je     11e1 <main+0x91>
cmpl   $0x0,-0x44(%rbp)
jl     11e1 <main+0x91>
cmpl   $0x9,-0x44(%rbp)
jle    1204 <main+0xb4>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x176>
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
mov    -0x44(%rbp),%r8d
lea    -0x38(%rbp),%rsi
call   1070 <compress2@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2da7(%rip),%rcx
cmp    (%rcx),%eax
je     1277 <main+0x127>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x176>
movl   $0x0,-0x40(%rbp)
movslq -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    12b1 <main+0x161>
movslq -0x40(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    127e <main+0x12e>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
movq   $0x1f,(%rsp)
cmp    $0x3,%edi
jne    1217 <main+0xb7>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rax
cmp    0x8(%rbx),%rax
je     1233 <main+0xd3>
test   %ebp,%ebp
js     1233 <main+0xd3>
cmp    $0xa,%ebp
jge    1233 <main+0xd3>
mov    0x10(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %ebp,%r8d
call   1080 <compress2@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
jne    124c <main+0xec>
cmpq   $0x0,(%rsp)
je     1209 <main+0xa9>
lea    0xe86(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rbp,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,(%rsp)
ja     11f0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
jmp    126a <main+0x10a>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdd6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1265 <main+0x105>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1265 <main+0x105>
mov    0x2d85(%rip),%rcx
mov    (%rcx),%edi
lea    0xde8(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: %s: <compression-level> <string>\0A\00"
@.str.1 = [27 x i8] c"Invalid compression level\0A\00"
@Z_OK = global i32 0
@.str.2 = [43 x i8] c"Error calling zlib compress2 function: %d\0A\00"
@.str.3 = [9 x i8] c"\\x%02hhx\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 31, i64* %7
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 1, i32* %3
br label %75
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strtol(i8* %23, i8** %11, i32 10)
store i32 %24, i32* %10
%25 = load i8*, i8** %11
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = icmp eq i8* %25, %28
br i1 %29, label %36, label %30
30: ; preds = %20
%31 = load i32, i32* %10
%32 = icmp slt i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* %10
%35 = icmp sgt i32 %34, 9
br i1 %35, label %36, label %39
36: ; preds = %33, %30, %20
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %75
39: ; preds = %33
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @strlen(i8* %46)
%48 = load i32, i32* %10
%49 = call i32 @compress2(i8* %40, i64* %7, i8* %43, i32 %47, i32 %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = load i32, i32* @Z_OK
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %39
%54 = load i32, i32* @stderr
%55 = load i32, i32* %8
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %55)
store i32 1, i32* %3
br label %75
57: ; preds = %39
store i32 0, i32* %9
br label %58
58: ; preds = %70, %57
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = load i64, i64* %7
%62 = icmp ult i64 %60, %61
br i1 %62, label %63, label %73
63: ; preds = %58
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %63
%71 = load i32, i32* %9
%72 = add nsw i32 %71, 1
store i32 %72, i32* %9
br label %58
73: ; preds = %58
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %75
75: ; preds = %73, %53, %36, %14
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: %s: <compression-level> <string>\0A\00"
@.str.1 = [27 x i8] c"Invalid compression level\0A\00"
@Z_OK = global i32 0
@.str.2 = [43 x i8] c"Error calling zlib compress2 function: %d\0A\00"
@.str.3 = [9 x i8] c"\\x%02hhx\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i8]
%4 = alloca i64
%5 = alloca i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = bitcast i64* %4 to i8*
store i64 31, i64* %4
%8 = bitcast i8** %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %52
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strtol(i8* %16, i8** %5, i32 10)
%18 = load i8*, i8** %5
%19 = load i8*, i8** %15
%20 = icmp eq i8* %18, %19
%21 = icmp slt i32 %17, 0
%22 = select i1 %20, i1 true, i1 %21
%23 = icmp sgt i32 %17, 9
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %25, label %28
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %52
28: ; preds = %14
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32 @strlen(i8* %30)
%32 = call i32 @compress2(i8* %6, i64* %4, i8* %30, i32 %31, i32 %17)
%33 = load i32, i32* @Z_OK
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i64, i64* %4
%37 = icmp eq i64 %36, 0
br i1 %37, label %50, label %41
38: ; preds = %28
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %52
41: ; preds = %35, %41
%42 = phi i64 [ %47, %41 ], [ 0, %35 ]
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = add nuw i64 %42, 1
%48 = load i64, i64* %4
%49 = icmp ugt i64 %48, %47
br i1 %49, label %41, label %50
50: ; preds = %41, %35
%51 = call i32 @putchar(i32 10)
br label %52
52: ; preds = %50, %38, %25, %10
%53 = phi i32 [ 1, %10 ], [ 1, %25 ], [ 1, %38 ], [ 0, %50 ]
ret i32 %53
}