#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 */
char *calloc(int, int);
int /*<<< orphan*/ printf(char *, unsigned long long, unsigned char);
unsigned long long varint_decode(char *, int, unsigned char *);
int /*<<< orphan*/ varint_encode(unsigned long long, char *, int,
                                 unsigned char *);
int main() {
  unsigned long long number = 23113293191329;
  char *str = calloc(7, sizeof(char));
  unsigned char bts;
  varint_encode(number, str, 7, &bts);
  unsigned long long r = varint_decode(str, 7, &bts);
  printf("RESULT: %lld\nBYTES: %hhu\n", r, bts);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x15057ba158a1,%rax
mov    %rax,-0x10(%rbp)
mov    $0x7,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x7,%edx
lea    -0x19(%rbp),%rcx
call   1030 <varint_encode@plt>
mov    -0x18(%rbp),%rdi
mov    $0x7,%esi
lea    -0x19(%rbp),%rdx
call   1040 <varint_decode@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe59(%rip),%rdi
movzbl -0x19(%rbp),%edx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x7,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
movabs $0x15057ba158a1,%rdi
lea    0x7(%rsp),%r14
mov    %rax,%rsi
mov    $0x7,%edx
mov    %r14,%rcx
call   1030 <varint_encode@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    %r14,%rdx
call   1040 <varint_decode@plt>
movzbl 0x7(%rsp),%edx
lea    0xe6f(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"RESULT: %lld\0ABYTES: %hhu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i64
store i32 0, i32* %1
store i64 23113293191329, i64* %2
%6 = call i8* @calloc(i32 7, i32 1)
store i8* %6, i8** %3
%7 = load i64, i64* %2
%8 = load i8*, i8** %3
%9 = call i32 @varint_encode(i64 %7, i8* %8, i32 7, i8* %4)
%10 = load i8*, i8** %3
%11 = call i64 @varint_decode(i8* %10, i32 7, i8* %4)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = load i8, i8* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %12, i8 zeroext %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"RESULT: %lld\0ABYTES: %hhu\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call dereferenceable_or_null(7) i8* @calloc(i32 7, i32 1)
%3 = call i32 @varint_encode(i64 23113293191329, i8* %2, i32 7, i8* %1)
%4 = call i64 @varint_decode(i8* %2, i32 7, i8* %1)
%5 = load i8, i8* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %4, i8 zeroext %5)
ret i32 0
}