#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 scalar_t__ int64_t;

/* Variables and functions */
int sqliterkParseVarint64(unsigned char const *, int, int *, scalar_t__ *);
int sqliterkParseVarint(const unsigned char *data, int offset, int *length,
                        int *value) {
  if (!value) {
    return 2;
  }
  int64_t out;
  int rc = sqliterkParseVarint64(data, offset, length, &out);
  if (rc != 0) {
    return rc;
  }
  *value = (int)out;
  return 0;
}


x86 assembly (clang, -O0):
<sqliterkParseVarint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    113e <sqliterkParseVarint+0x2e>
movl   $0x2,-0x4(%rbp)
jmp    117d <sqliterkParseVarint+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1030 <sqliterkParseVarint64@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     116a <sqliterkParseVarint+0x5a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117d <sqliterkParseVarint+0x6d>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqliterkParseVarint>:
test   %rcx,%rcx
je     1137 <sqliterkParseVarint+0x27>
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
lea    0x8(%rsp),%rcx
call   1030 <sqliterkParseVarint64@plt>
test   %eax,%eax
jne    1131 <sqliterkParseVarint+0x21>
mov    0x8(%rsp),%ecx
mov    %ecx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x2,%eax
ret

LLVM IR (-O0):
define i32 @sqliterkParseVarint(i8* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%12 = load i32*, i32** %9
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %4
store i32 2, i32* %5
br label %28
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = load i32*, i32** %8
%19 = call i32 @sqliterkParseVarint64(i8* %16, i32 %17, i32* %18, i64* %10)
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = load i32, i32* %11
store i32 %23, i32* %5
br label %28
24: ; preds = %15
%25 = load i64, i64* %10
%26 = trunc i64 %25 to i32
%27 = load i32*, i32** %9
store i32 %26, i32* %27
store i32 0, i32* %5
br label %28
28: ; preds = %24, %22, %14
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
define i32 @sqliterkParseVarint(i8* %0, i32 %1, i32* %2, i32* writeonly %3) {
%5 = alloca i64
%6 = icmp eq i32* %3, null
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = bitcast i64* %5 to i8*
%9 = call i32 @sqliterkParseVarint64(i8* %0, i32 %1, i32* %2, i64* %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i64, i64* %5
%13 = trunc i64 %12 to i32
store i32 %13, i32* %3
br label %14
14: ; preds = %7, %11
br label %15
15: ; preds = %4, %14
%16 = phi i32 [ %9, %14 ], [ 2, %4 ]
ret i32 %16
}