#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*/ bswap4(unsigned char *);
int /*<<< orphan*/ compress(unsigned char *, unsigned long *, unsigned char *,
                            long);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int compress_buffer(unsigned char *input, unsigned char *output, long insize) {
  unsigned long output_size = insize + 1000;
  unsigned long output_offset;
  output_offset = 2 * sizeof(long);
  memcpy(output, (unsigned char *)&insize, sizeof(long));
  bswap4(output);
  compress(output + output_offset, &output_size, input, insize);
  memcpy(output + sizeof(long), (unsigned char *)&output_size, sizeof(long));
  bswap4(output + sizeof(long));
  return output_size + output_offset;
}


x86 assembly (clang, -O0):
<compress_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x3e8,%rax
mov    %rax,-0x20(%rbp)
movq   $0x10,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <bswap4@plt>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rsi
call   1030 <compress@plt>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1050 <bswap4@plt>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_buffer>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rdx,0x8(%rsp)
add    $0x3e8,%rdx
mov    %rdx,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1050 <bswap4@plt>
lea    0x10(%rbx),%rdi
mov    0x8(%rsp),%rcx
mov    %rsp,%r15
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <compress@plt>
add    $0x8,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1050 <bswap4@plt>
mov    (%rsp),%eax
add    $0x10,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @compress_buffer(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = add nsw i64 %9, 1000
store i64 %10, i64* %7
store i64 16, i64* %8
%11 = load i8*, i8** %5
%12 = bitcast i64* %6 to i8*
%13 = call i32 @memcpy(i8* %11, i8* %12, i32 8)
%14 = load i8*, i8** %5
%15 = call i32 @bswap4(i8* %14)
%16 = load i8*, i8** %5
%17 = load i64, i64* %8
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8*, i8** %4
%20 = load i64, i64* %6
%21 = call i32 @compress(i8* %18, i64* %7, i8* %19, i64 %20)
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 8
%24 = bitcast i64* %7 to i8*
%25 = call i32 @memcpy(i8* %23, i8* %24, i32 8)
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = call i32 @bswap4(i8* %27)
%29 = load i64, i64* %7
%30 = load i64, i64* %8
%31 = add i64 %29, %30
%32 = trunc i64 %31 to i32
ret i32 %32
}

LLVM IR (-O2):
define i32 @compress_buffer(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
store i64 %2, i64* %4
%6 = bitcast i64* %5 to i8*
%7 = add nsw i64 %2, 1000
store i64 %7, i64* %5
%8 = bitcast i64* %4 to i8*
%9 = call i32 @memcpy(i8* %1, i8* %8, i32 8)
%10 = call i32 @bswap4(i8* %1)
%11 = getelementptr inbounds i8, i8* %1, i64 16
%12 = load i64, i64* %4
%13 = call i32 @compress(i8* %11, i64* %5, i8* %0, i64 %12)
%14 = getelementptr inbounds i8, i8* %1, i64 8
%15 = call i32 @memcpy(i8* %14, i8* %6, i32 8)
%16 = call i32 @bswap4(i8* %14)
%17 = load i64, i64* %5
%18 = trunc i64 %17 to i32
%19 = add i32 %18, 16
ret i32 %19
}