#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 */
unsigned int signedToUnsignedInt(int);
int BEserializeMultiByteInt(int i, char *c) {
  unsigned int ui = signedToUnsignedInt(i);
  if ((ui & 0xffffff80U) == 0) {
    c[0] = (char)(ui & 0x0000007fU);
    return 1;
  }
  c[0] = (char)((ui & 0x0000007fU) | 0x80U);
  if ((ui & 0xffffc000U) == 0) {
    c[1] = (char)((ui >> 7) & 0x0000007fU);
    return 2;
  }
  c[1] = (char)(((ui >> 7) & 0x0000007fU) | 0x80U);
  if ((ui & 0xffe00000U) == 0) {
    c[2] = (char)((ui >> 14) & 0x0000007fU);
    return 3;
  }
  c[2] = (char)(((ui >> 14) & 0x0000007fU) | 0x80U);
  if ((ui & 0xf0000000U) == 0) {
    c[3] = (char)((ui >> 21) & 0x0000007fU);
    return 4;
  }
  c[3] = (char)(((ui >> 21) & 0x0000007fU) | 0x80U);
  c[4] = (char)((ui >> 28) & 0x0000007fU);
  return 5;
}


x86 assembly (clang, -O0):
<BEserializeMultiByteInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <signedToUnsignedInt@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xffffff80,%eax
cmp    $0x0,%eax
jne    1153 <BEserializeMultiByteInt+0x43>
mov    -0x14(%rbp),%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1251 <BEserializeMultiByteInt+0x141>
mov    -0x14(%rbp),%eax
and    $0x7f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
and    $0xffffc000,%eax
cmp    $0x0,%eax
jne    1195 <BEserializeMultiByteInt+0x85>
mov    -0x14(%rbp),%eax
shr    $0x7,%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x2,-0x4(%rbp)
jmp    1251 <BEserializeMultiByteInt+0x141>
mov    -0x14(%rbp),%eax
shr    $0x7,%eax
and    $0x7f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x14(%rbp),%eax
and    $0xffe00000,%eax
cmp    $0x0,%eax
jne    11db <BEserializeMultiByteInt+0xcb>
mov    -0x14(%rbp),%eax
shr    $0xe,%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
movl   $0x3,-0x4(%rbp)
jmp    1251 <BEserializeMultiByteInt+0x141>
mov    -0x14(%rbp),%eax
shr    $0xe,%eax
and    $0x7f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x14(%rbp),%eax
and    $0xf0000000,%eax
cmp    $0x0,%eax
jne    1221 <BEserializeMultiByteInt+0x111>
mov    -0x14(%rbp),%eax
shr    $0x15,%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
movl   $0x4,-0x4(%rbp)
jmp    1251 <BEserializeMultiByteInt+0x141>
mov    -0x14(%rbp),%eax
shr    $0x15,%eax
and    $0x7f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x14(%rbp),%eax
shr    $0x1c,%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
movl   $0x5,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BEserializeMultiByteInt>:
push   %rbx
mov    %rsi,%rbx
call   1030 <signedToUnsignedInt@plt>
cmp    $0x7f,%eax
ja     1127 <BEserializeMultiByteInt+0x17>
mov    %al,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret
mov    %eax,%ecx
or     $0x80,%cl
mov    %cl,(%rbx)
mov    %eax,%ecx
shr    $0x7,%ecx
cmp    $0x3fff,%eax
ja     1144 <BEserializeMultiByteInt+0x34>
mov    %cl,0x1(%rbx)
mov    $0x2,%eax
pop    %rbx
ret
or     $0x80,%cl
mov    %cl,0x1(%rbx)
mov    %eax,%ecx
shr    $0xe,%ecx
cmp    $0x1fffff,%eax
ja     1160 <BEserializeMultiByteInt+0x50>
mov    %cl,0x2(%rbx)
mov    $0x3,%eax
pop    %rbx
ret
or     $0x80,%cl
mov    %cl,0x2(%rbx)
mov    %eax,%ecx
shr    $0x15,%ecx
cmp    $0xfffffff,%eax
ja     117c <BEserializeMultiByteInt+0x6c>
mov    %cl,0x3(%rbx)
mov    $0x4,%eax
pop    %rbx
ret
or     $0x80,%cl
mov    %cl,0x3(%rbx)
shr    $0x1c,%eax
mov    %al,0x4(%rbx)
mov    $0x5,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @BEserializeMultiByteInt(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = call i32 @signedToUnsignedInt(i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = and i32 %9, -128
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* %6
%14 = and i32 %13, 127
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 %15, i8* %17
store i32 1, i32* %3
br label %85
18: ; preds = %2
%19 = load i32, i32* %6
%20 = and i32 %19, 127
%21 = or i32 %20, 128
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 %22, i8* %24
%25 = load i32, i32* %6
%26 = and i32 %25, -16384
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %18
%29 = load i32, i32* %6
%30 = lshr i32 %29, 7
%31 = and i32 %30, 127
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 %32, i8* %34
store i32 2, i32* %3
br label %85
35: ; preds = %18
%36 = load i32, i32* %6
%37 = lshr i32 %36, 7
%38 = and i32 %37, 127
%39 = or i32 %38, 128
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8 %40, i8* %42
%43 = load i32, i32* %6
%44 = and i32 %43, -2097152
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %35
%47 = load i32, i32* %6
%48 = lshr i32 %47, 14
%49 = and i32 %48, 127
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i64 2
store i8 %50, i8* %52
store i32 3, i32* %3
br label %85
53: ; preds = %35
%54 = load i32, i32* %6
%55 = lshr i32 %54, 14
%56 = and i32 %55, 127
%57 = or i32 %56, 128
%58 = trunc i32 %57 to i8
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 2
store i8 %58, i8* %60
%61 = load i32, i32* %6
%62 = and i32 %61, -268435456
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %53
%65 = load i32, i32* %6
%66 = lshr i32 %65, 21
%67 = and i32 %66, 127
%68 = trunc i32 %67 to i8
%69 = load i8*, i8** %5
%70 = getelementptr inbounds i8, i8* %69, i64 3
store i8 %68, i8* %70
store i32 4, i32* %3
br label %85
71: ; preds = %53
%72 = load i32, i32* %6
%73 = lshr i32 %72, 21
%74 = and i32 %73, 127
%75 = or i32 %74, 128
%76 = trunc i32 %75 to i8
%77 = load i8*, i8** %5
%78 = getelementptr inbounds i8, i8* %77, i64 3
store i8 %76, i8* %78
%79 = load i32, i32* %6
%80 = lshr i32 %79, 28
%81 = and i32 %80, 127
%82 = trunc i32 %81 to i8
%83 = load i8*, i8** %5
%84 = getelementptr inbounds i8, i8* %83, i64 4
store i8 %82, i8* %84
store i32 5, i32* %3
br label %85
85: ; preds = %71, %64, %46, %28, %12
%86 = load i32, i32* %3
ret i32 %86
}

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