#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*/ tassert(int);
int /*<<< orphan*/ varint_encode(unsigned long long, char *, int,
                                 unsigned char *);
void encode_test() {
  unsigned long long number = 23113293191329;
  char *str = calloc(7, sizeof(char));
  unsigned char bts;
  varint_encode(number, str, 7, &bts);
  tassert(bts == 7);
  tassert((unsigned char)(*(str++)) == 0xA1);
  tassert((unsigned char)(*(str++)) == 0xB1);
  tassert((unsigned char)(*(str++)) == 0x85);
  tassert((unsigned char)(*(str++)) == 0xDD);
  tassert((unsigned char)(*(str++)) == 0xD7);
  tassert((unsigned char)(*(str++)) == 0xA0);
  tassert((unsigned char)(*str) == 0x05);
  number = 353938623;
  str = calloc(5, sizeof(char));
  varint_encode(number, str, 5, &bts);
  tassert(bts == 5);
  tassert((unsigned char)(*(str++)) == 0xBF);
  tassert((unsigned char)(*(str++)) == 0xD9);
  tassert((unsigned char)(*(str++)) == 0xE2);
  tassert((unsigned char)(*(str++)) == 0xA8);
  tassert((unsigned char)(*str) == 0x01);
  number = 2142;
  str = calloc(2, sizeof(char));
  varint_encode(number, str, 2, NULL);
  tassert((unsigned char)(*(str++)) == 0xDE);
  tassert((unsigned char)(*str) == 0x10);
}


x86 assembly (clang, -O0):
<encode_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movabs $0x15057ba158a1,%rax
mov    %rax,-0x8(%rbp)
mov    $0x7,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x7,%edx
lea    -0x11(%rbp),%rcx
call   1030 <varint_encode@plt>
movzbl -0x11(%rbp),%eax
cmp    $0x7,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xa1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xb1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0x85,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xdd,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xd7,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xa0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
movq   $0x1518acbf,-0x8(%rbp)
15
mov    $0x5,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x5,%edx
lea    -0x11(%rbp),%rcx
call   1030 <varint_encode@plt>
movzbl -0x11(%rbp),%eax
cmp    $0x5,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xbf,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xd9,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xe2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xa8,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
movq   $0x85e,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <varint_encode@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
cmp    $0xde,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x10,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <tassert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_test>:
push   %r14
push   %rbx
push   %rax
mov    $0x7,%edi
mov    $0x1,%esi
call   1050 <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>
xor    %edi,%edi
cmpb   $0x7,0x7(%rsp)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xa1,(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xb1,0x1(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0x85,0x2(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xdd,0x3(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xd7,0x4(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xa0,0x5(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0x5,0x6(%rbx)
sete   %dil
call   1040 <tassert@plt>
mov    $0x5,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    $0x1518acbf,%edi
mov    %rax,%rsi
mov    $0x5,%edx
mov    %r14,%rcx
call   1030 <varint_encode@plt>
xor    %edi,%edi
cmpb   $0x5,0x7(%rsp)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xbf,(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xd9,0x1(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xe2,0x2(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0xa8,0x3(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0x1,0x4(%rbx)
sete   %dil
call   1040 <tassert@plt>
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    $0x85e,%edi
mov    %rax,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1030 <varint_encode@plt>
xor    %edi,%edi
cmpb   $0xde,(%rbx)
sete   %dil
call   1040 <tassert@plt>
xor    %edi,%edi
cmpb   $0x10,0x1(%rbx)
sete   %dil
call   1040 <tassert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @encode_test() {
%1 = alloca i64
%2 = alloca i8*
%3 = alloca i8
store i64 23113293191329, i64* %1
%4 = call i8* @calloc(i32 7, i32 1)
store i8* %4, i8** %2
%5 = load i64, i64* %1
%6 = load i8*, i8** %2
%7 = call i32 @varint_encode(i64 %5, i8* %6, i32 7, i8* %3)
%8 = load i8, i8* %3
%9 = zext i8 %8 to i32
%10 = icmp eq i32 %9, 7
%11 = zext i1 %10 to i32
%12 = call i32 @tassert(i32 %11)
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %2
%15 = load i8, i8* %13
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 161
%18 = zext i1 %17 to i32
%19 = call i32 @tassert(i32 %18)
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %2
%22 = load i8, i8* %20
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 177
%25 = zext i1 %24 to i32
%26 = call i32 @tassert(i32 %25)
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
%29 = load i8, i8* %27
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 133
%32 = zext i1 %31 to i32
%33 = call i32 @tassert(i32 %32)
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %2
%36 = load i8, i8* %34
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 221
%39 = zext i1 %38 to i32
%40 = call i32 @tassert(i32 %39)
%41 = load i8*, i8** %2
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %2
%43 = load i8, i8* %41
%44 = zext i8 %43 to i32
%45 = icmp eq i32 %44, 215
%46 = zext i1 %45 to i32
%47 = call i32 @tassert(i32 %46)
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %2
%50 = load i8, i8* %48
%51 = zext i8 %50 to i32
%52 = icmp eq i32 %51, 160
%53 = zext i1 %52 to i32
%54 = call i32 @tassert(i32 %53)
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 5
%59 = zext i1 %58 to i32
%60 = call i32 @tassert(i32 %59)
store i64 353938623, i64* %1
%61 = call i8* @calloc(i32 5, i32 1)
store i8* %61, i8** %2
%62 = load i64, i64* %1
%63 = load i8*, i8** %2
%64 = call i32 @varint_encode(i64 %62, i8* %63, i32 5, i8* %3)
%65 = load i8, i8* %3
%66 = zext i8 %65 to i32
%67 = icmp eq i32 %66, 5
%68 = zext i1 %67 to i32
%69 = call i32 @tassert(i32 %68)
%70 = load i8*, i8** %2
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %2
%72 = load i8, i8* %70
%73 = zext i8 %72 to i32
%74 = icmp eq i32 %73, 191
%75 = zext i1 %74 to i32
%76 = call i32 @tassert(i32 %75)
%77 = load i8*, i8** %2
%78 = getelementptr inbounds i8, i8* %77, i32 1
store i8* %78, i8** %2
%79 = load i8, i8* %77
%80 = zext i8 %79 to i32
%81 = icmp eq i32 %80, 217
%82 = zext i1 %81 to i32
%83 = call i32 @tassert(i32 %82)
%84 = load i8*, i8** %2
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %2
%86 = load i8, i8* %84
%87 = zext i8 %86 to i32
%88 = icmp eq i32 %87, 226
%89 = zext i1 %88 to i32
%90 = call i32 @tassert(i32 %89)
%91 = load i8*, i8** %2
%92 = getelementptr inbounds i8, i8* %91, i32 1
store i8* %92, i8** %2
%93 = load i8, i8* %91
%94 = zext i8 %93 to i32
%95 = icmp eq i32 %94, 168
%96 = zext i1 %95 to i32
%97 = call i32 @tassert(i32 %96)
%98 = load i8*, i8** %2
%99 = load i8, i8* %98
%100 = zext i8 %99 to i32
%101 = icmp eq i32 %100, 1
%102 = zext i1 %101 to i32
%103 = call i32 @tassert(i32 %102)
store i64 2142, i64* %1
%104 = call i8* @calloc(i32 2, i32 1)
store i8* %104, i8** %2
%105 = load i64, i64* %1
%106 = load i8*, i8** %2
%107 = call i32 @varint_encode(i64 %105, i8* %106, i32 2, i8* null)
%108 = load i8*, i8** %2
%109 = getelementptr inbounds i8, i8* %108, i32 1
store i8* %109, i8** %2
%110 = load i8, i8* %108
%111 = zext i8 %110 to i32
%112 = icmp eq i32 %111, 222
%113 = zext i1 %112 to i32
%114 = call i32 @tassert(i32 %113)
%115 = load i8*, i8** %2
%116 = load i8, i8* %115
%117 = zext i8 %116 to i32
%118 = icmp eq i32 %117, 16
%119 = zext i1 %118 to i32
%120 = call i32 @tassert(i32 %119)
ret void
}

LLVM IR (-O2):
define void @encode_test() {
%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 = load i8, i8* %1
%5 = icmp eq i8 %4, 7
%6 = zext i1 %5 to i32
%7 = call i32 @tassert(i32 %6)
%8 = getelementptr inbounds i8, i8* %2, i64 1
%9 = load i8, i8* %2
%10 = icmp eq i8 %9, -95
%11 = zext i1 %10 to i32
%12 = call i32 @tassert(i32 %11)
%13 = getelementptr inbounds i8, i8* %2, i64 2
%14 = load i8, i8* %8
%15 = icmp eq i8 %14, -79
%16 = zext i1 %15 to i32
%17 = call i32 @tassert(i32 %16)
%18 = getelementptr inbounds i8, i8* %2, i64 3
%19 = load i8, i8* %13
%20 = icmp eq i8 %19, -123
%21 = zext i1 %20 to i32
%22 = call i32 @tassert(i32 %21)
%23 = getelementptr inbounds i8, i8* %2, i64 4
%24 = load i8, i8* %18
%25 = icmp eq i8 %24, -35
%26 = zext i1 %25 to i32
%27 = call i32 @tassert(i32 %26)
%28 = getelementptr inbounds i8, i8* %2, i64 5
%29 = load i8, i8* %23
%30 = icmp eq i8 %29, -41
%31 = zext i1 %30 to i32
%32 = call i32 @tassert(i32 %31)
%33 = getelementptr inbounds i8, i8* %2, i64 6
%34 = load i8, i8* %28
%35 = icmp eq i8 %34, -96
%36 = zext i1 %35 to i32
%37 = call i32 @tassert(i32 %36)
%38 = load i8, i8* %33
%39 = icmp eq i8 %38, 5
%40 = zext i1 %39 to i32
%41 = call i32 @tassert(i32 %40)
%42 = call dereferenceable_or_null(5) i8* @calloc(i32 5, i32 1)
%43 = call i32 @varint_encode(i64 353938623, i8* %42, i32 5, i8* %1)
%44 = load i8, i8* %1
%45 = icmp eq i8 %44, 5
%46 = zext i1 %45 to i32
%47 = call i32 @tassert(i32 %46)
%48 = getelementptr inbounds i8, i8* %42, i64 1
%49 = load i8, i8* %42
%50 = icmp eq i8 %49, -65
%51 = zext i1 %50 to i32
%52 = call i32 @tassert(i32 %51)
%53 = getelementptr inbounds i8, i8* %42, i64 2
%54 = load i8, i8* %48
%55 = icmp eq i8 %54, -39
%56 = zext i1 %55 to i32
%57 = call i32 @tassert(i32 %56)
%58 = getelementptr inbounds i8, i8* %42, i64 3
%59 = load i8, i8* %53
%60 = icmp eq i8 %59, -30
%61 = zext i1 %60 to i32
%62 = call i32 @tassert(i32 %61)
%63 = getelementptr inbounds i8, i8* %42, i64 4
%64 = load i8, i8* %58
%65 = icmp eq i8 %64, -88
%66 = zext i1 %65 to i32
%67 = call i32 @tassert(i32 %66)
%68 = load i8, i8* %63
%69 = icmp eq i8 %68, 1
%70 = zext i1 %69 to i32
%71 = call i32 @tassert(i32 %70)
%72 = call dereferenceable_or_null(2) i8* @calloc(i32 2, i32 1)
%73 = call i32 @varint_encode(i64 2142, i8* %72, i32 2, i8* null)
%74 = getelementptr inbounds i8, i8* %72, i64 1
%75 = load i8, i8* %72
%76 = icmp eq i8 %75, -34
%77 = zext i1 %76 to i32
%78 = call i32 @tassert(i32 %77)
%79 = load i8, i8* %74
%80 = icmp eq i8 %79, 16
%81 = zext i1 %80 to i32
%82 = call i32 @tassert(i32 %81)
ret void
}