#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*/ arr;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ check_ok(int /*<<< orphan*/);
int /*<<< orphan*/ colcomp_compress_float(float *, unsigned int, void **,
                                          size_t *, char **);
int /*<<< orphan*/ colcomp_decompress_float(void *, size_t, char *, float **,
                                            unsigned int *);
int /*<<< orphan*/ free(float *);
scalar_t__ memcmp(float *, float *, int);
int /*<<< orphan*/ printf(char *, unsigned int, int, size_t, char *);
int rand();
void colcomp_test_float(void) {
  unsigned nb_items = rand() % 5;
  float arr[nb_items];
  for (unsigned i = 0; i < nb_items; i++) {
    arr[i] = rand() % 100 - 50;
  }
  void *comp;
  size_t comp_sz;
  char *op;
  check_ok(colcomp_compress_float(arr, nb_items, &comp, &comp_sz, &op));
  printf("Compressed %u "
         "float"
         " (%zu bytes) into %zu bytes using %s\n",
         nb_items, sizeof(arr), comp_sz, op);
  float *out;
  unsigned nb_items_out;
  check_ok(colcomp_decompress_float(comp, comp_sz, op, &out, &nb_items_out));
  assert(nb_items_out == nb_items);
  assert(0 == memcmp(out, arr, sizeof(arr)));
  free(comp);
  free(out);
}


x86 assembly (clang, -O0):
<colcomp_test_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    121e <colcomp_test_float+0x9e>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x50(%rbp),%rax
sub    $0x32,%edx
cvtsi2ss %edx,%xmm0
mov    -0x1c(%rbp),%ecx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e2 <colcomp_test_float+0x62>
mov    -0x50(%rbp),%rdi
mov    -0x4(%rbp),%esi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1090 <colcomp_compress_float@plt>
mov    %eax,%edi
call   1040 <check_ok@plt>
mov    -0x58(%rbp),%rax
mov    -0x4(%rbp),%esi
shl    $0x2,%rax
mov    %eax,%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xda7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1060 <colcomp_decompress_float@plt>
mov    %eax,%edi
call   1040 <check_ok@plt>
mov    -0x44(%rbp),%eax
cmp    -0x4(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rax
mov    -0x40(%rbp),%rdi
shl    $0x2,%rax
mov    %eax,%edx
call   1070 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colcomp_test_float>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%r12
imul   $0x66666667,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r12d
lea    0xf(,%r12,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
test   %r12d,%r12d
je     120d <colcomp_test_float+0x8d>
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0xffffffce,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11d0 <colcomp_test_float+0x50>
lea    -0x48(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x38(%rbp),%r8
mov    %r14,%rdi
mov    %r12d,%esi
call   1090 <colcomp_compress_float@plt>
mov    %eax,%edi
call   1040 <check_ok@plt>
lea    0x0(,%r12,4),%r15d
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xdbe(%rip),%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1060 <colcomp_decompress_float@plt>
mov    %eax,%edi
call   1040 <check_ok@plt>
xor    %edi,%edi
cmp    %r12d,-0x24(%rbp)
sete   %dil
call   1080 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1070 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Compressed %u float (%zu bytes) into %zu bytes using %s\0A\00"
define void @colcomp_test_float() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca float*
%9 = alloca i32
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 5
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %2
%15 = alloca float, i64 %13
store i64 %13, i64* %3
store i32 0, i32* %4
br label %16
16: ; preds = %28, %0
%17 = load i32, i32* %4
%18 = load i32, i32* %1
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 100
%23 = sub nsw i32 %22, 50
%24 = sitofp i32 %23 to float
%25 = load i32, i32* %4
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds float, float* %15, i64 %26
store float %24, float* %27
br label %28
28: ; preds = %20
%29 = load i32, i32* %4
%30 = add i32 %29, 1
store i32 %30, i32* %4
br label %16
31: ; preds = %16
%32 = load i32, i32* %1
%33 = call i32 @colcomp_compress_float(float* %15, i32 %32, i8** %5, i64* %6, i8** %7)
%34 = call i32 @check_ok(i32 %33)
%35 = load i32, i32* %1
%36 = mul nuw i64 4, %13
%37 = trunc i64 %36 to i32
%38 = load i64, i64* %6
%39 = load i8*, i8** %7
%40 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %37, i64 %38, i8* %39)
%41 = load i8*, i8** %5
%42 = load i64, i64* %6
%43 = load i8*, i8** %7
%44 = call i32 @colcomp_decompress_float(i8* %41, i64 %42, i8* %43, float** %8, i32* %9)
%45 = call i32 @check_ok(i32 %44)
%46 = load i32, i32* %9
%47 = load i32, i32* %1
%48 = icmp eq i32 %46, %47
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = load float*, float** %8
%52 = mul nuw i64 4, %13
%53 = trunc i64 %52 to i32
%54 = call i64 @memcmp(float* %51, float* %15, i32 %53)
%55 = icmp eq i64 0, %54
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = load i8*, i8** %5
%59 = bitcast i8* %58 to float*
%60 = call i32 @free(float* %59)
%61 = load float*, float** %8
%62 = call i32 @free(float* %61)
%63 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
@.str = [57 x i8] c"Compressed %u float (%zu bytes) into %zu bytes using %s\0A\00"
define void @colcomp_test_float() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
%4 = alloca float*
%5 = alloca i32
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 5
%8 = zext i32 %7 to i64
%9 = alloca float, i64 %8
%10 = icmp eq i32 %7, 0
br i1 %10, label %11, label %42
11: ; preds = %42, %0
%12 = bitcast i8** %1 to i8*
%13 = bitcast i64* %2 to i8*
%14 = bitcast i8** %3 to i8*
%15 = call i32 @colcomp_compress_float(float* %9, i32 %7, i8** %1, i64* %2, i8** %3)
%16 = call i32 @check_ok(i32 %15)
%17 = shl nsw i32 %7, 2
%18 = load i64, i64* %2
%19 = load i8*, i8** %3
%20 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %17, i64 %18, i8* %19)
%21 = bitcast float** %4 to i8*
%22 = bitcast i32* %5 to i8*
%23 = load i8*, i8** %1
%24 = load i64, i64* %2
%25 = load i8*, i8** %3
%26 = call i32 @colcomp_decompress_float(i8* %23, i64 %24, i8* %25, float** %4, i32* %5)
%27 = call i32 @check_ok(i32 %26)
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, %7
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load float*, float** %4
%33 = call i64 @memcmp(float* %32, float* %9, i32 %17)
%34 = icmp eq i64 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = bitcast i8** %1 to float**
%38 = load float*, float** %37
%39 = call i32 @free(float* %38)
%40 = load float*, float** %4
%41 = call i32 @free(float* %40)
ret void
42: ; preds = %0, %42
%43 = phi i64 [ %49, %42 ], [ 0, %0 ]
%44 = tail call i32 (...) @rand()
%45 = srem i32 %44, 100
%46 = add nsw i32 %45, -50
%47 = sitofp i32 %46 to float
%48 = getelementptr inbounds float, float* %9, i64 %43
store float %47, float* %48
%49 = add nuw nsw i64 %43, 1
%50 = icmp eq i64 %49, %8
br i1 %50, label %11, label %42
}