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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ check_ok(int /*<<< orphan*/);
int /*<<< orphan*/ colcomp_compress_bool(char *, unsigned int, void **,
                                         size_t *, char **);
int /*<<< orphan*/ colcomp_decompress_bool(void *, size_t, char *, char **,
                                           unsigned int *);
scalar_t__ memcmp(char *, char *, unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, int, size_t, char *);
int rand();
void colcomp_test_bool(void) {
  unsigned nb_bits = rand() % 100;
  char s[(nb_bits + 7) / 8];
  for (unsigned i = 0; i < sizeof(s); i++)
    s[i] = rand();
  void *comp;
  size_t comp_sz;
  char *op;
  check_ok(colcomp_compress_bool(s, nb_bits, &comp, &comp_sz, &op));
  printf("Compressed %u bits (%zu bytes) into %zu bytes using %s\n", nb_bits,
         sizeof(s), comp_sz, op);
  char *out;
  unsigned nb_bits_out;
  check_ok(colcomp_decompress_bool(comp, comp_sz, op, &out, &nb_bits_out));
  assert(nb_bits == nb_bits_out);
  assert(0 == memcmp(out, s, nb_bits / 8));
  unsigned nb_bits_last = nb_bits % 8;
  if (nb_bits_last) {
    unsigned mask = (1 << nb_bits_last) - 1;
    assert((s[sizeof(s) - 1] & mask) == (out[sizeof(s) - 1] & mask));
  }
}


x86 assembly (clang, -O0):
<colcomp_test_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
add    $0x7,%edx
shr    $0x3,%edx
mov    %edx,%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
add    $0xf,%edx
mov    %edx,%ecx
and    $0xfffffff0,%ecx
mov    %ecx,%edx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x60(%rbp),%rcx
mov    -0x1c(%rbp),%eax
cmp    %rcx,%rax
jae    1209 <colcomp_test_bool+0x99>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %cl,%dl
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d6 <colcomp_test_bool+0x66>
mov    -0x58(%rbp),%rdi
mov    -0x4(%rbp),%esi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1080 <colcomp_compress_bool@plt>
mov    %eax,%edi
call   1030 <check_ok@plt>
mov    -0x60(%rbp),%rax
mov    -0x4(%rbp),%esi
mov    %eax,%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xdc0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1070 <colcomp_decompress_bool@plt>
mov    %eax,%edi
call   1030 <check_ok@plt>
mov    -0x4(%rbp),%eax
cmp    -0x44(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x58(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%edx
shr    $0x3,%edx
call   1050 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x4(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     12f9 <colcomp_test_bool+0x189>
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rax
mov    -0x48(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    %esi,%ecx
sub    $0x1,%ecx
mov    %ecx,-0x4c(%rbp)
mov    %rdx,%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
and    -0x4c(%rbp),%eax
mov    -0x40(%rbp),%rcx
sub    $0x1,%rdx
movsbl (%rcx,%rdx,1),%ecx
and    -0x4c(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colcomp_test_bool>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
mov    %eax,%r15d
sub    %ecx,%r15d
neg    %ecx
add    %ecx,%eax
add    $0x7,%eax
mov    %rax,%r14
shr    $0x3,%r14
lea    0xf(%r14),%ecx
and    $0xfffffff0,%ecx
mov    %rsp,%r12
sub    %rcx,%r12
mov    %r12,%rsp
cmp    $0x8,%eax
jb     11f4 <colcomp_test_bool+0x84>
cmp    $0x2,%r14d
mov    $0x1,%r13d
cmovae %r14d,%r13d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11e0 <colcomp_test_bool+0x70>
lea    -0x50(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x40(%rbp),%r8
mov    %r12,%rdi
mov    %r15d,%esi
call   1080 <colcomp_compress_bool@plt>
mov    %eax,%edi
call   1030 <check_ok@plt>
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xddf(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1040 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1070 <colcomp_decompress_bool@plt>
mov    %eax,%edi
call   1030 <check_ok@plt>
xor    %edi,%edi
cmp    -0x2c(%rbp),%r15d
sete   %dil
call   1060 <assert@plt>
mov    -0x38(%rbp),%rdi
mov    %r15d,%edx
shr    $0x3,%edx
mov    %r12,%rsi
call   1050 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
and    $0x7,%r15d
je     12ab <colcomp_test_bool+0x13b>
mov    $0xffffffff,%eax
mov    %r15d,%ecx
shl    %cl,%eax
not    %eax
mov    -0x38(%rbp),%rcx
mov    -0x1(%rcx,%r14,1),%cl
xor    -0x1(%r12,%r14,1),%cl
movzbl %cl,%ecx
xor    %edi,%edi
test   %eax,%ecx
sete   %dil
call   1060 <assert@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Compressed %u bits (%zu bytes) into %zu bytes using %s\0A\00"
define void @colcomp_test_bool() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 100
store i32 %13, i32* %1
%14 = load i32, i32* %1
%15 = add i32 %14, 7
%16 = udiv i32 %15, 8
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %2
%19 = alloca i8, i64 %17
store i64 %17, i64* %3
store i32 0, i32* %4
br label %20
20: ; preds = %30, %0
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = icmp ult i64 %22, %17
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = call i32 (...) @rand()
%26 = trunc i32 %25 to i8
%27 = load i32, i32* %4
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %19, i64 %28
store i8 %26, i8* %29
br label %30
30: ; preds = %24
%31 = load i32, i32* %4
%32 = add i32 %31, 1
store i32 %32, i32* %4
br label %20
33: ; preds = %20
%34 = load i32, i32* %1
%35 = call i32 @colcomp_compress_bool(i8* %19, i32 %34, i8** %5, i64* %6, i8** %7)
%36 = call i32 @check_ok(i32 %35)
%37 = load i32, i32* %1
%38 = trunc i64 %17 to i32
%39 = load i64, i64* %6
%40 = load i8*, i8** %7
%41 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %37, i32 %38, i64 %39, i8* %40)
%42 = load i8*, i8** %5
%43 = load i64, i64* %6
%44 = load i8*, i8** %7
%45 = call i32 @colcomp_decompress_bool(i8* %42, i64 %43, i8* %44, i8** %8, i32* %9)
%46 = call i32 @check_ok(i32 %45)
%47 = load i32, i32* %1
%48 = load i32, i32* %9
%49 = icmp eq i32 %47, %48
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load i8*, i8** %8
%53 = load i32, i32* %1
%54 = udiv i32 %53, 8
%55 = call i64 @memcmp(i8* %52, i8* %19, i32 %54)
%56 = icmp eq i64 0, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load i32, i32* %1
%60 = urem i32 %59, 8
store i32 %60, i32* %10
%61 = load i32, i32* %10
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %83
63: ; preds = %33
%64 = load i32, i32* %10
%65 = shl i32 1, %64
%66 = sub nsw i32 %65, 1
store i32 %66, i32* %11
%67 = sub i64 %17, 1
%68 = getelementptr inbounds i8, i8* %19, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = load i32, i32* %11
%72 = and i32 %70, %71
%73 = load i8*, i8** %8
%74 = sub i64 %17, 1
%75 = getelementptr inbounds i8, i8* %73, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = load i32, i32* %11
%79 = and i32 %77, %78
%80 = icmp eq i32 %72, %79
%81 = zext i1 %80 to i32
%82 = call i32 @assert(i32 %81)
br label %83
83: ; preds = %63, %33
%84 = load i8*, i8** %2
ret void
}

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