#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 uint64_t;
typedef int /*<<< orphan*/ keys;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ golombset_decode(int, unsigned char *, size_t, int *, size_t *);
scalar_t__ golombset_encode(int, int *, size_t const, unsigned char *,
                            size_t *);
scalar_t__ memcmp(int *, int *, int);
int /*<<< orphan*/ printf(char *, size_t const, size_t);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  uint64_t keys[] = {151,  192,  208,  269,  461,  512,  526,  591,  662,
                     806,  831,  866,  890,  997,  1005, 1017, 1134, 1207,
                     1231, 1327, 1378, 1393, 1418, 1525, 1627, 1630};
  const size_t num_keys = sizeof(keys) / sizeof(keys[0]);
  unsigned char buf[1024];
  size_t bufsize = sizeof(buf);
  if (golombset_encode(6, keys, num_keys, buf, &bufsize) != 0) {
    fprintf(stderr, "golombset_encode failed\n");
    return 111;
  }
  printf("encoded %zu entries into %zu bytes\n", num_keys, bufsize);
  uint64_t decoded_keys[num_keys];
  size_t num_decoded_keys = num_keys;
  if (golombset_decode(6, buf, bufsize, decoded_keys, &num_decoded_keys) != 0) {
    fprintf(stderr, "golombset_decode failed\n");
    return 111;
  }
  if (num_decoded_keys != num_keys) {
    fprintf(stderr, "unexpected number of outputs\n");
    return 111;
  }
  if (memcmp(keys, decoded_keys, sizeof(keys[0]) * num_keys) != 0) {
    fprintf(stderr, "output mismatch\n");
    return 111;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x68,%edx
call   1060 <memcpy@plt>
movq   $0x1a,-0x88(%rbp)
movq   $0x400,-0x498(%rbp)
lea    -0x80(%rbp),%rsi
lea    -0x490(%rbp),%rcx
mov    $0x6,%edi
mov    $0x1a,%edx
lea    -0x498(%rbp),%r8
call   1080 <golombset_encode@plt>
cmp    $0x0,%rax
je     11f0 <main+0x90>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x6f,-0x4(%rbp)
jmp    1320 <main+0x1c0>
mov    -0x498(%rbp),%rdx
lea    0xe83(%rip),%rdi
mov    $0x1a,%esi
call   1030 <printf@plt>
mov    %rsp,%rax
mov    %rax,-0x4a0(%rbp)
mov    %rsp,%rcx
add    $0xffffffffffffff90,%rcx
mov    %rcx,-0x4b8(%rbp)
mov    %rcx,%rsp
movq   $0x1a,-0x4a8(%rbp)
lea    -0x490(%rbp),%rsi
mov    -0x498(%rbp),%rdx
mov    $0x6,%edi
lea    -0x4a8(%rbp),%r8
call   1070 <golombset_decode@plt>
cmp    $0x0,%rax
je     1282 <main+0x122>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x6f,-0x4(%rbp)
movl   $0x1,-0x4ac(%rbp)
jmp    1316 <main+0x1b6>
cmpq   $0x1a,-0x4a8(%rbp)
1a
je     12bb <main+0x15b>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x6f,-0x4(%rbp)
movl   $0x1,-0x4ac(%rbp)
jmp    1316 <main+0x1b6>
mov    -0x4b8(%rbp),%rsi
lea    -0x80(%rbp),%rdi
mov    $0x68,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     1305 <main+0x1a5>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x6f,-0x4(%rbp)
movl   $0x1,-0x4ac(%rbp)
jmp    1316 <main+0x1b6>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4ac(%rbp)
mov    -0x4a0(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x480,%rsp
mov    0xefb(%rip),%rax
mov    %rax,-0x30(%rbp)
movaps 0xee0(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xe8f(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
movaps 0xe59(%rip),%xmm0
movaps %xmm0,-0x90(%rbp)
movq   $0x400,-0x18(%rbp)
lea    -0x90(%rbp),%rsi
lea    -0x490(%rbp),%rcx
lea    -0x18(%rbp),%r8
mov    $0x1a,%edx
mov    $0x6,%edi
call   1070 <golombset_encode@plt>
test   %rax,%rax
je     11fb <main+0xab>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x6f,%eax
jmp    1295 <main+0x145>
mov    -0x18(%rbp),%rdx
lea    0xe7b(%rip),%rdi
mov    $0x1a,%esi
call   1030 <printf@plt>
mov    %rsp,%r14
mov    %rsp,%rbx
add    $0xffffffffffffff90,%rbx
mov    %rbx,%rsp
movq   $0x1a,-0x20(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x490(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x6,%edi
mov    %rbx,%rcx
call   1060 <golombset_decode@plt>
test   %rax,%rax
je     124f <main+0xff>
lea    0xe58(%rip),%rsi
jmp    127f <main+0x12f>
cmpq   $0x1a,-0x20(%rbp)
jne    1278 <main+0x128>
lea    -0x90(%rbp),%rdi
mov    %rbx,%rsi
mov    $0x68,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     129e <main+0x14e>
lea    0xe66(%rip),%rsi
jmp    127f <main+0x12f>
lea    0xe3f(%rip),%rsi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   1050 <fprintf@plt>
mov    $0x6f,%eax
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
jmp    1292 <main+0x142>

LLVM IR (-O0):
@__const.main.keys = [26 x i32] [i32 151, i32 192, i32 208, i32 269, i32 461, i32 512, i32 526, i32 591, i32 662, i32 806, i32 831, i32 866, i32 890, i32 997, i32 1005, i32 1017, i32 1134, i32 1207, i32 1231, i32 1327, i32 1378, i32 1393, i32 1418, i32 1525, i32 1627, i32 1630]
@stderr = global i32 0
@.str = [25 x i8] c"golombset_encode failed\0A\00"
@.str.1 = [36 x i8] c"encoded %zu entries into %zu bytes\0A\00"
@.str.2 = [25 x i8] c"golombset_decode failed\0A\00"
@.str.3 = [30 x i8] c"unexpected number of outputs\0A\00"
@.str.4 = [17 x i8] c"output mismatch\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [26 x i32]
%7 = alloca i64
%8 = alloca [1024 x i8]
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [26 x i32]* %6 to i8*
store i64 26, i64* %7
store i64 1024, i64* %9
%14 = getelementptr inbounds [26 x i32], [26 x i32]* %6, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%16 = call i64 @golombset_encode(i32 6, i32* %14, i64 26, i8* %15, i64* %9)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 111, i32* %3
br label %49
21: ; preds = %2
%22 = load i64, i64* %9
%23 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 26, i64 %22)
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %10
%25 = alloca i32, i64 26
store i64 26, i64* %11
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = load i64, i64* %9
%28 = call i64 @golombset_decode(i32 6, i8* %26, i64 %27, i32* %25, i64* %11)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 111, i32* %3
store i32 1, i32* %12
br label %47
33: ; preds = %21
%34 = load i64, i64* %11
%35 = icmp ne i64 %34, 26
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 111, i32* %3
store i32 1, i32* %12
br label %47
39: ; preds = %33
%40 = getelementptr inbounds [26 x i32], [26 x i32]* %6, i64 0, i64 0
%41 = call i64 @memcmp(i32* %40, i32* %25, i32 104)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 111, i32* %3
store i32 1, i32* %12
br label %47
46: ; preds = %39
store i32 0, i32* %3
store i32 1, i32* %12
br label %47
47: ; preds = %46, %43, %36, %30
%48 = load i8*, i8** %10
br label %49
49: ; preds = %47, %18
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@__const.main.keys = [26 x i32] [i32 151, i32 192, i32 208, i32 269, i32 461, i32 512, i32 526, i32 591, i32 662, i32 806, i32 831, i32 866, i32 890, i32 997, i32 1005, i32 1017, i32 1134, i32 1207, i32 1231, i32 1327, i32 1378, i32 1393, i32 1418, i32 1525, i32 1627, i32 1630]
@stderr = global i32 0
@.str = [25 x i8] c"golombset_encode failed\0A\00"
@.str.1 = [36 x i8] c"encoded %zu entries into %zu bytes\0A\00"
@.str.2 = [25 x i8] c"golombset_decode failed\0A\00"
@.str.3 = [30 x i8] c"unexpected number of outputs\0A\00"
@.str.4 = [17 x i8] c"output mismatch\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [26 x i32]
%4 = alloca [1024 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = bitcast [26 x i32]* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast i64* %5 to i8*
store i64 1024, i64* %5
%10 = getelementptr inbounds [26 x i32], [26 x i32]* %3, i64 0, i64 0
%11 = call i64 @golombset_encode(i32 6, i32* %10, i64 26, i8* %8, i64* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %38
16: ; preds = %2
%17 = load i64, i64* %5
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 26, i64 %17)
%19 = call i8* @llvm.stacksave()
%20 = alloca [26 x i32]
%21 = getelementptr inbounds [26 x i32], [26 x i32]* %20, i64 0, i64 0
%22 = bitcast i64* %6 to i8*
store i64 26, i64* %6
%23 = load i64, i64* %5
%24 = call i64 @golombset_decode(i32 6, i8* %8, i64 %23, i32* %21, i64* %6)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %16
%27 = load i64, i64* %6
%28 = icmp eq i64 %27, 26
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i64 @memcmp(i32* %10, i32* %21, i32 104)
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %29, %26, %16
%33 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), %16 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), %26 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), %29 ]
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* %33)
br label %36
36: ; preds = %32, %29
%37 = phi i32 [ 0, %29 ], [ 111, %32 ]
br label %38
38: ; preds = %36, %13
%39 = phi i32 [ 111, %13 ], [ %37, %36 ]
ret i32 %39
}