#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned int EOF;
unsigned int fputc(unsigned int, int /*<<< orphan*/ *);
int varintlen(unsigned int);
unsigned int fputvb(unsigned int value, FILE *stream) {
  int i;
  int len = varintlen(value);
  unsigned int result;
  for (i = 0; i < len; i++) {
    result = fputc(((value >> (7 * (len - i - 1))) & 0x7F) |
                       ((i < len - 1) ? 0x80 : 0),
                   stream);
    if (result == EOF) {
      return EOF;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<fputvb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <varintlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ba <fputvb+0x9a>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
sub    $0x1,%eax
imul   $0x7,%eax,%ecx
shr    %cl,%edi
and    $0x7f,%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
xor    %eax,%eax
mov    $0x80,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
or     %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%eax
jne    11a7 <fputvb+0x87>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c0 <fputvb+0xa0>
jmp    11ac <fputvb+0x8c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <fputvb+0x21>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputvb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
call   1030 <varintlen@plt>
test   %eax,%eax
jle    1195 <fputvb+0x75>
lea    -0x1(%rax),%r13d
lea    0x0(,%rax,8),%ebx
sub    %eax,%ebx
add    $0xfffffff9,%ebx
xor    %ebp,%ebp
mov    0x2e95(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%eax
mov    %ebx,%ecx
shr    %cl,%eax
and    $0x7f,%eax
xor    %edi,%edi
cmp    %r13d,%ebp
setl   %dil
shl    $0x7,%edi
or     %eax,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
cmp    (%r12),%eax
je     1195 <fputvb+0x75>
lea    0x1(%rbp),%ecx
add    $0xfffffff9,%ebx
cmp    %ebp,%r13d
mov    %ecx,%ebp
jne    1160 <fputvb+0x40>
jmp    1195 <fputvb+0x75>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @fputvb(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = load i32, i32* %4
%10 = call i32 @varintlen(i32 %9)
store i32 %10, i32* %7
store i32 0, i32* %6
br label %11
11: ; preds = %39, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %42
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = sub nsw i32 %17, %18
%20 = sub nsw i32 %19, 1
%21 = mul nsw i32 7, %20
%22 = lshr i32 %16, %21
%23 = and i32 %22, 127
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = icmp slt i32 %24, %26
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 128, i32 0
%30 = or i32 %23, %29
%31 = load i32*, i32** %5
%32 = call i32 @fputc(i32 %30, i32* %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %15
%37 = load i32, i32* @EOF
store i32 %37, i32* %3
br label %44
38: ; preds = %15
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %11
42: ; preds = %11
%43 = load i32, i32* %8
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %36
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @fputvb(i32 %0, i32* nocapture %1) {
%3 = tail call i32 @varintlen(i32 %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %23
5: ; preds = %2
%6 = add nsw i32 %3, -1
br label %7
7: ; preds = %7, %5
%8 = phi i32 [ 0, %5 ], [ %20, %7 ]
%9 = xor i32 %8, -1
%10 = add i32 %3, %9
%11 = mul nsw i32 %10, 7
%12 = lshr i32 %0, %11
%13 = and i32 %12, 127
%14 = icmp slt i32 %8, %6
%15 = select i1 %14, i32 128, i32 0
%16 = or i32 %13, %15
%17 = tail call i32 @fputc(i32 %16, i32* %1)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
%20 = add nuw nsw i32 %8, 1
%21 = icmp eq i32 %20, %3
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %7
23: ; preds = %7, %2
%24 = phi i32 [ undef, %2 ], [ %17, %7 ]
ret i32 %24
}