#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 */
int /*<<< orphan*/ tassert(int);
unsigned long long varint_decode(char *, int, unsigned char *);
void decode_test() {
  char str[] = {0x90, 0xD7, 0x99, 0xDB, 0x82, 0xB2,
                0xF0, 0x01, 0xEE, 0xEE, 0xEE};
  unsigned char bts = 0;
  unsigned long long res = 0;
  res = varint_decode(str, 11, &bts);
  tassert(bts == 8);
  tassert(res == 1057249877715856);
  char str2[] = {0x98, 0x12};
  res = varint_decode(str2, 2, NULL);
  tassert(res == 2328);
}


x86 assembly (clang, -O0):
<decode_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xb(%rbp)
mov    0xece(%rip),%ax
mov    %ax,-0x3(%rbp)
mov    0xec6(%rip),%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0xb(%rbp),%rdi
mov    $0xb,%esi
lea    -0xc(%rbp),%rdx
call   1040 <varint_decode@plt>
mov    %rax,-0x18(%rbp)
movzbl -0xc(%rbp),%eax
cmp    $0x8,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <tassert@plt>
movabs $0x3c1902b666b90,%rax
cmp    %rax,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <tassert@plt>
mov    0xe6c(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    -0x1a(%rbp),%rdi
mov    $0x2,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <varint_decode@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x918,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <tassert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_test>:
push   %rbx
sub    $0x20,%rsp
movabs $0x1f0b282db99d790,%rax
b2 f0 01
mov    %rax,0x10(%rsp)
movl   $0xeeeeee01,0x17(%rsp)
ee
movb   $0x0,0xd(%rsp)
lea    0x10(%rsp),%rdi
lea    0xd(%rsp),%rdx
mov    $0xb,%esi
call   1040 <varint_decode@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmpb   $0x8,0xd(%rsp)
sete   %dil
call   1030 <tassert@plt>
movabs $0x3c1902b666b90,%rax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1030 <tassert@plt>
movw   $0x1298,0xe(%rsp)
lea    0xe(%rsp),%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <varint_decode@plt>
xor    %edi,%edi
cmp    $0x918,%rax
sete   %dil
call   1030 <tassert@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.decode_test.str = [11 x i8] c"\90\D7\99\DB\82\B2\F0\01\EE\EE\EE"
@__const.decode_test.str2 = [2 x i8] c"\98\12"
define void @decode_test() {
%1 = alloca [11 x i8]
%2 = alloca i8
%3 = alloca i64
%4 = alloca [2 x i8]
%5 = bitcast [11 x i8]* %1 to i8*
store i8 0, i8* %2
store i64 0, i64* %3
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%7 = call i64 @varint_decode(i8* %6, i32 11, i8* %2)
store i64 %7, i64* %3
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = icmp eq i32 %9, 8
%11 = zext i1 %10 to i32
%12 = call i32 @tassert(i32 %11)
%13 = load i64, i64* %3
%14 = icmp eq i64 %13, 1057249877715856
%15 = zext i1 %14 to i32
%16 = call i32 @tassert(i32 %15)
%17 = bitcast [2 x i8]* %4 to i8*
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%19 = call i64 @varint_decode(i8* %18, i32 2, i8* null)
store i64 %19, i64* %3
%20 = load i64, i64* %3
%21 = icmp eq i64 %20, 2328
%22 = zext i1 %21 to i32
%23 = call i32 @tassert(i32 %22)
ret void
}

LLVM IR (-O2):
@__const.decode_test.str = [11 x i8] c"\90\D7\99\DB\82\B2\F0\01\EE\EE\EE"
define void @decode_test() {
%1 = alloca [11 x i8]
%2 = alloca i8
%3 = alloca i16
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
%5 = call i64 @varint_decode(i8* %4, i32 11, i8* %2)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 8
%8 = zext i1 %7 to i32
%9 = call i32 @tassert(i32 %8)
%10 = icmp eq i64 %5, 1057249877715856
%11 = zext i1 %10 to i32
%12 = call i32 @tassert(i32 %11)
%13 = bitcast i16* %3 to i8*
store i16 4760, i16* %3
%14 = call i64 @varint_decode(i8* %13, i32 2, i8* null)
%15 = icmp eq i64 %14, 2328
%16 = zext i1 %15 to i32
%17 = call i32 @tassert(i32 %16)
ret void
}