#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*/ eputc(unsigned int);
void WriteVarLen(unsigned long value) {
  unsigned long buffer;
  buffer = value & 0x7f;
  while ((value >>= 7) > 0) {
    buffer <<= 8;
    buffer |= 0x80;
    buffer += (value & 0x7f);
  }
  while (1) {
    eputc((unsigned)(buffer & 0xff));
    if (buffer & 0x80)
      buffer >>= 8;
    else
      return;
  }
}


x86 assembly (clang, -O0):
<WriteVarLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0x7f,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x7,%rax
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jbe    116d <WriteVarLen+0x5d>
mov    -0x10(%rbp),%rax
shl    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
or     $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0x7f,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1128 <WriteVarLen+0x18>
jmp    1172 <WriteVarLen+0x62>
mov    -0x10(%rbp),%rax
and    $0xff,%rax
mov    %eax,%edi
call   1030 <eputc@plt>
mov    -0x10(%rbp),%rax
and    $0x80,%rax
cmp    $0x0,%rax
je     11a8 <WriteVarLen+0x98>
mov    -0x10(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11ae <WriteVarLen+0x9e>
add    $0x10,%rsp
pop    %rbp
ret
jmp    1172 <WriteVarLen+0x62>

x86 assembly (clang, -O2):
<WriteVarLen>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%eax
and    $0x7f,%eax
cmp    $0x80,%rdi
jae    1127 <WriteVarLen+0x17>
mov    %rax,%rbx
jmp    1154 <WriteVarLen+0x44>
mov    %rdi,%rcx
nopw   0x0(%rax,%rax,1)
shr    $0x7,%rcx
shl    $0x8,%rax
movzbl %cl,%ebx
or     %rax,%rbx
or     $0x80,%rbx
mov    %rbx,%rax
cmp    $0x3fff,%rdi
mov    %rcx,%rdi
ja     1130 <WriteVarLen+0x20>
mov    %rbx,%r14
nopw   0x0(%rax,%rax,1)
movzbl %bl,%edi
call   1030 <eputc@plt>
shr    $0x8,%r14
test   $0x80,%bl
mov    %r14,%rbx
jne    1160 <WriteVarLen+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @WriteVarLen(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = and i64 %4, 127
store i64 %5, i64* %3
br label %6
6: ; preds = %10, %1
%7 = load i64, i64* %2
%8 = lshr i64 %7, 7
store i64 %8, i64* %2
%9 = icmp ugt i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = load i64, i64* %3
%12 = shl i64 %11, 8
store i64 %12, i64* %3
%13 = load i64, i64* %3
%14 = or i64 %13, 128
store i64 %14, i64* %3
%15 = load i64, i64* %2
%16 = and i64 %15, 127
%17 = load i64, i64* %3
%18 = add i64 %17, %16
store i64 %18, i64* %3
br label %6
19: ; preds = %6
br label %20
20: ; preds = %19, %32
%21 = load i64, i64* %3
%22 = and i64 %21, 255
%23 = trunc i64 %22 to i32
%24 = call i32 @eputc(i32 %23)
%25 = load i64, i64* %3
%26 = and i64 %25, 128
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i64, i64* %3
%30 = lshr i64 %29, 8
store i64 %30, i64* %3
br label %32
31: ; preds = %20
ret void
32: ; preds = %28
br label %20
}

LLVM IR (-O2):
define void @WriteVarLen(i64 %0) {
%2 = and i64 %0, 127
%3 = icmp ult i64 %0, 128
br i1 %3, label %13, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %7, %4 ], [ %0, %1 ]
%6 = phi i64 [ %11, %4 ], [ %2, %1 ]
%7 = lshr i64 %5, 7
%8 = shl i64 %6, 8
%9 = and i64 %7, 127
%10 = or i64 %8, %9
%11 = or i64 %10, 128
%12 = icmp ult i64 %5, 16384
br i1 %12, label %13, label %4
13: ; preds = %4, %1
%14 = phi i64 [ %2, %1 ], [ %11, %4 ]
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ %22, %15 ], [ %14, %13 ]
%17 = trunc i64 %16 to i32
%18 = and i32 %17, 255
%19 = tail call i32 @eputc(i32 %18)
%20 = and i64 %16, 128
%21 = icmp eq i64 %20, 0
%22 = lshr i64 %16, 8
br i1 %21, label %23, label %15
23: ; preds = %15
ret void
}