#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*/ free(unsigned char *);
int huffman_compress(unsigned char const *, unsigned char **, int);
int send(int, char *, int, int);
int send_comp(int s, const unsigned char *data, int size, int flags) {
  unsigned char *compressed;
  int size_comp;
  if ((size_comp = huffman_compress(data, &compressed, size)) < 0)
    return -1;
  if (send(s, (char *)&size_comp, sizeof(int), flags) != sizeof(int))
    return -1;
  if (send(s, (char *)compressed, size_comp, flags) != size_comp)
    return -1;
  free(compressed);
  return 0;
}


x86 assembly (clang, -O0):
<send_comp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1050 <huffman_compress@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    116d <send_comp+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <send_comp+0xa0>
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    -0x18(%rbp),%ecx
mov    $0x4,%edx
call   1040 <send@plt>
cltq
cmp    $0x4,%rax
je     1199 <send_comp+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <send_comp+0xa0>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <send@plt>
cmp    -0x24(%rbp),%eax
je     11c0 <send_comp+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <send_comp+0xa0>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_comp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rsi,%rax
mov    %edi,%ebp
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <huffman_compress@plt>
mov    %eax,0x4(%rsp)
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1198 <send_comp+0x68>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
mov    %r14d,%ecx
call   1040 <send@plt>
cmp    $0x4,%eax
jne    1198 <send_comp+0x68>
mov    0x8(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %ebp,%edi
mov    %r14d,%ecx
call   1040 <send@plt>
cmp    0x4(%rsp),%eax
jne    1198 <send_comp+0x68>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send_comp(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i8*, i8** %7
%13 = load i32, i32* %8
%14 = call i32 @huffman_compress(i8* %12, i8** %10, i32 %13)
store i32 %14, i32* %11
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %37
17: ; preds = %4
%18 = load i32, i32* %6
%19 = bitcast i32* %11 to i8*
%20 = load i32, i32* %9
%21 = call i32 @send(i32 %18, i8* %19, i32 4, i32 %20)
%22 = sext i32 %21 to i64
%23 = icmp ne i64 %22, 4
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -1, i32* %5
br label %37
25: ; preds = %17
%26 = load i32, i32* %6
%27 = load i8*, i8** %10
%28 = load i32, i32* %11
%29 = load i32, i32* %9
%30 = call i32 @send(i32 %26, i8* %27, i32 %28, i32 %29)
%31 = load i32, i32* %11
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %25
store i32 -1, i32* %5
br label %37
34: ; preds = %25
%35 = load i8*, i8** %10
%36 = call i32 @free(i8* %35)
store i32 0, i32* %5
br label %37
37: ; preds = %34, %33, %24, %16
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @send_comp(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = bitcast i8** %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 @huffman_compress(i8* %1, i8** %5, i32 %2)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %4
%12 = call i32 @send(i32 %0, i8* %8, i32 4, i32 %3)
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i32 @send(i32 %0, i8* %15, i32 %16, i32 %3)
%18 = load i32, i32* %6
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %14, %11, %4, %20
%24 = phi i32 [ 0, %20 ], [ -1, %4 ], [ -1, %11 ], [ -1, %14 ]
ret i32 %24
}