#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__ uint8_t;
typedef int uint64_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int _pbcV_encode32(int /*<<< orphan*/, scalar_t__ *);
int _pbcV_encode(uint64_t number, uint8_t buffer[10]) {
  if ((number & 0xffffffff) == number) {
    return _pbcV_encode32((uint32_t)number, buffer);
  }
  int i = 0;
  do {
    buffer[i] = (uint8_t)(number | 0x80);
    number >>= 7;
    ++i;
  } while (number >= 0x80);
  buffer[i] = (uint8_t)number;
  return i + 1;
}


x86 assembly (clang, -O0):
<_pbcV_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
and    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    1142 <_pbcV_encode+0x32>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <_pbcV_encode32@plt>
mov    %eax,-0x4(%rbp)
jmp    1198 <_pbcV_encode+0x88>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
or     $0x80,%eax
movslq %eax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
sar    $0x7,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1149 <_pbcV_encode+0x39>
movslq -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pbcV_encode>:
jmp    1030 <_pbcV_encode32@plt>

LLVM IR (-O0):
define i32 @_pbcV_encode(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i32
store i32 %0, i32* %4
store i64* %1, i64** %5
%7 = load i32, i32* %4
%8 = and i32 %7, -1
%9 = load i32, i32* %4
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i64*, i64** %5
%14 = call i32 @_pbcV_encode32(i32 %12, i64* %13)
store i32 %14, i32* %3
br label %40
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %28, %15
%17 = load i32, i32* %4
%18 = or i32 %17, 128
%19 = sext i32 %18 to i64
%20 = load i64*, i64** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i64, i64* %20, i64 %22
store i64 %19, i64* %23
%24 = load i32, i32* %4
%25 = ashr i32 %24, 7
store i32 %25, i32* %4
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %28
28: ; preds = %16
%29 = load i32, i32* %4
%30 = icmp sge i32 %29, 128
br i1 %30, label %16, label %31
31: ; preds = %28
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = load i64*, i64** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i64, i64* %34, i64 %36
store i64 %33, i64* %37
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %40
40: ; preds = %31, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @_pbcV_encode(i32 %0, i64* %1) {
%3 = tail call i32 @_pbcV_encode32(i32 %0, i64* %1)
ret i32 %3
}