#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 uint32_t;

/* Variables and functions */
int _pbcV_encode32(uint32_t number, uint8_t buffer[10]) {
  if (number < 0x80) {
    buffer[0] = (uint8_t)number;
    return 1;
  }
  buffer[0] = (uint8_t)(number | 0x80);
  if (number < 0x4000) {
    buffer[1] = (uint8_t)(number >> 7);
    return 2;
  }
  buffer[1] = (uint8_t)((number >> 7) | 0x80);
  if (number < 0x200000) {
    buffer[2] = (uint8_t)(number >> 14);
    return 3;
  }
  buffer[2] = (uint8_t)((number >> 14) | 0x80);
  if (number < 0x10000000) {
    buffer[3] = (uint8_t)(number >> 21);
    return 4;
  }
  buffer[3] = (uint8_t)((number >> 21) | 0x80);
  buffer[4] = (uint8_t)(number >> 28);
  return 5;
}


x86 assembly (clang, -O0):
<_pbcV_encode32>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    112f <_pbcV_encode32+0x2f>
movslq -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1219 <_pbcV_encode32+0x119>
mov    -0x8(%rbp),%eax
or     $0x80,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x4000,-0x8(%rbp)
jge    116b <_pbcV_encode32+0x6b>
mov    -0x8(%rbp),%eax
sar    $0x7,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
movl   $0x2,-0x4(%rbp)
jmp    1219 <_pbcV_encode32+0x119>
mov    -0x8(%rbp),%eax
sar    $0x7,%eax
or     $0x80,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
cmpl   $0x200000,-0x8(%rbp)
jge    11ab <_pbcV_encode32+0xab>
mov    -0x8(%rbp),%eax
sar    $0xe,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
movl   $0x3,-0x4(%rbp)
jmp    1219 <_pbcV_encode32+0x119>
mov    -0x8(%rbp),%eax
sar    $0xe,%eax
or     $0x80,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
cmpl   $0x10000000,-0x8(%rbp)
jge    11eb <_pbcV_encode32+0xeb>
mov    -0x8(%rbp),%eax
sar    $0x15,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
movl   $0x4,-0x4(%rbp)
jmp    1219 <_pbcV_encode32+0x119>
mov    -0x8(%rbp),%eax
sar    $0x15,%eax
or     $0x80,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x8(%rbp),%eax
sar    $0x1c,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x20(%rax)
movl   $0x5,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pbcV_encode32>:
cmp    $0x7f,%edi
jg     1111 <_pbcV_encode32+0x11>
movslq %edi,%rax
mov    %rax,(%rsi)
mov    $0x1,%eax
ret
mov    %edi,%eax
or     $0x80,%eax
cltq
mov    %rax,(%rsi)
mov    %edi,%eax
shr    $0x7,%eax
cmp    $0x3fff,%edi
ja     1136 <_pbcV_encode32+0x36>
mov    %eax,%eax
mov    %rax,0x8(%rsi)
mov    $0x2,%eax
ret
or     $0x80,%eax
mov    %rax,0x8(%rsi)
mov    %edi,%eax
shr    $0xe,%eax
cmp    $0x1fffff,%edi
ja     1158 <_pbcV_encode32+0x58>
mov    %eax,%eax
mov    %rax,0x10(%rsi)
mov    $0x3,%eax
ret
or     $0x80,%eax
mov    %rax,0x10(%rsi)
mov    %edi,%eax
shr    $0x15,%eax
cmp    $0xfffffff,%edi
ja     117a <_pbcV_encode32+0x7a>
mov    %eax,%eax
mov    %rax,0x18(%rsi)
mov    $0x4,%eax
ret
or     $0x80,%eax
mov    %rax,0x18(%rsi)
shr    $0x1c,%edi
mov    %rdi,0x20(%rsi)
mov    $0x5,%eax
ret

LLVM IR (-O0):
define i32 @_pbcV_encode32(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
store i32 %0, i32* %4
store i64* %1, i64** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 128
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = load i64*, i64** %5
%12 = getelementptr inbounds i64, i64* %11, i64 0
store i64 %10, i64* %12
store i32 1, i32* %3
br label %69
13: ; preds = %2
%14 = load i32, i32* %4
%15 = or i32 %14, 128
%16 = sext i32 %15 to i64
%17 = load i64*, i64** %5
%18 = getelementptr inbounds i64, i64* %17, i64 0
store i64 %16, i64* %18
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 16384
br i1 %20, label %21, label %27
21: ; preds = %13
%22 = load i32, i32* %4
%23 = ashr i32 %22, 7
%24 = sext i32 %23 to i64
%25 = load i64*, i64** %5
%26 = getelementptr inbounds i64, i64* %25, i64 1
store i64 %24, i64* %26
store i32 2, i32* %3
br label %69
27: ; preds = %13
%28 = load i32, i32* %4
%29 = ashr i32 %28, 7
%30 = or i32 %29, 128
%31 = sext i32 %30 to i64
%32 = load i64*, i64** %5
%33 = getelementptr inbounds i64, i64* %32, i64 1
store i64 %31, i64* %33
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 2097152
br i1 %35, label %36, label %42
36: ; preds = %27
%37 = load i32, i32* %4
%38 = ashr i32 %37, 14
%39 = sext i32 %38 to i64
%40 = load i64*, i64** %5
%41 = getelementptr inbounds i64, i64* %40, i64 2
store i64 %39, i64* %41
store i32 3, i32* %3
br label %69
42: ; preds = %27
%43 = load i32, i32* %4
%44 = ashr i32 %43, 14
%45 = or i32 %44, 128
%46 = sext i32 %45 to i64
%47 = load i64*, i64** %5
%48 = getelementptr inbounds i64, i64* %47, i64 2
store i64 %46, i64* %48
%49 = load i32, i32* %4
%50 = icmp slt i32 %49, 268435456
br i1 %50, label %51, label %57
51: ; preds = %42
%52 = load i32, i32* %4
%53 = ashr i32 %52, 21
%54 = sext i32 %53 to i64
%55 = load i64*, i64** %5
%56 = getelementptr inbounds i64, i64* %55, i64 3
store i64 %54, i64* %56
store i32 4, i32* %3
br label %69
57: ; preds = %42
%58 = load i32, i32* %4
%59 = ashr i32 %58, 21
%60 = or i32 %59, 128
%61 = sext i32 %60 to i64
%62 = load i64*, i64** %5
%63 = getelementptr inbounds i64, i64* %62, i64 3
store i64 %61, i64* %63
%64 = load i32, i32* %4
%65 = ashr i32 %64, 28
%66 = sext i32 %65 to i64
%67 = load i64*, i64** %5
%68 = getelementptr inbounds i64, i64* %67, i64 4
store i64 %66, i64* %68
store i32 5, i32* %3
br label %69
69: ; preds = %57, %51, %36, %21, %8
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
define i32 @_pbcV_encode32(i32 %0, i64* nocapture writeonly %1) {
%3 = icmp slt i32 %0, 128
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = sext i32 %0 to i64
store i64 %5, i64* %1
br label %39
6: ; preds = %2
%7 = or i32 %0, 128
%8 = sext i32 %7 to i64
store i64 %8, i64* %1
%9 = icmp ult i32 %0, 16384
%10 = lshr i32 %0, 7
br i1 %9, label %11, label %14
11: ; preds = %6
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds i64, i64* %1, i64 1
store i64 %12, i64* %13
br label %39
14: ; preds = %6
%15 = or i32 %10, 128
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i64, i64* %1, i64 1
store i64 %16, i64* %17
%18 = icmp ult i32 %0, 2097152
%19 = lshr i32 %0, 14
br i1 %18, label %20, label %23
20: ; preds = %14
%21 = zext i32 %19 to i64
%22 = getelementptr inbounds i64, i64* %1, i64 2
store i64 %21, i64* %22
br label %39
23: ; preds = %14
%24 = or i32 %19, 128
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i64, i64* %1, i64 2
store i64 %25, i64* %26
%27 = icmp ult i32 %0, 268435456
%28 = lshr i32 %0, 21
br i1 %27, label %29, label %32
29: ; preds = %23
%30 = zext i32 %28 to i64
%31 = getelementptr inbounds i64, i64* %1, i64 3
store i64 %30, i64* %31
br label %39
32: ; preds = %23
%33 = or i32 %28, 128
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i64, i64* %1, i64 3
store i64 %34, i64* %35
%36 = lshr i32 %0, 28
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i64, i64* %1, i64 4
store i64 %37, i64* %38
br label %39
39: ; preds = %32, %29, %20, %11, %4
%40 = phi i32 [ 1, %4 ], [ 2, %11 ], [ 3, %20 ], [ 4, %29 ], [ 5, %32 ]
ret i32 %40
}