#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 uint32_t;
struct xmi_ctx {
  int dummy;
};
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ write1(struct xmi_ctx *, int);
int PutVLQ(struct xmi_ctx *ctx, uint32_t value) {
  int32_t buffer;
  int i = 1, j;
  buffer = value & 0x7F;
  while (value >>= 7) {
    buffer <<= 8;
    buffer |= ((value & 0x7F) | 0x80);
    i++;
  }
  for (j = 0; j < i; j++) {
    write1(ctx, buffer & 0xFF);
    buffer >>= 8;
  }
  return (i);
}


x86 assembly (clang, -O0):
<PutVLQ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x7,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1169 <PutVLQ+0x59>
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
or     $0x80,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <PutVLQ+0x1f>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a5 <PutVLQ+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
and    $0xff,%esi
call   1030 <write1@plt>
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1170 <PutVLQ+0x60>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PutVLQ>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%eax
and    $0x7f,%eax
mov    $0x1,%r15d
cmp    $0x80,%esi
jae    1131 <PutVLQ+0x21>
mov    %eax,%ebx
jmp    1161 <PutVLQ+0x51>
mov    $0x1,%r15d
mov    %esi,%ecx
nopl   0x0(%rax)
sar    $0x7,%ecx
shl    $0x8,%eax
movzbl %cl,%ebx
or     %eax,%ebx
or     $0x80,%ebx
add    $0x1,%r15d
mov    %ebx,%eax
cmp    $0x4000,%esi
mov    %ecx,%esi
jae    1140 <PutVLQ+0x30>
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl %bl,%esi
mov    %r14,%rdi
call   1030 <write1@plt>
sar    $0x8,%ebx
add    $0xffffffff,%ebp
jne    1170 <PutVLQ+0x60>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.xmi_ctx = type { i32 }
define i32 @PutVLQ(%struct.xmi_ctx* %0, i32 %1) {
%3 = alloca %struct.xmi_ctx*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.xmi_ctx* %0, %struct.xmi_ctx** %3
store i32 %1, i32* %4
store i32 1, i32* %6
%8 = load i32, i32* %4
%9 = and i32 %8, 127
store i32 %9, i32* %5
br label %10
10: ; preds = %14, %2
%11 = load i32, i32* %4
%12 = ashr i32 %11, 7
store i32 %12, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %5
%16 = shl i32 %15, 8
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = and i32 %17, 127
%19 = or i32 %18, 128
%20 = load i32, i32* %5
%21 = or i32 %20, %19
store i32 %21, i32* %5
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %10
24: ; preds = %10
store i32 0, i32* %7
br label %25
25: ; preds = %36, %24
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load %struct.xmi_ctx*, %struct.xmi_ctx** %3
%31 = load i32, i32* %5
%32 = and i32 %31, 255
%33 = call i32 @write1(%struct.xmi_ctx* %30, i32 %32)
%34 = load i32, i32* %5
%35 = ashr i32 %34, 8
store i32 %35, i32* %5
br label %36
36: ; preds = %29
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %25
39: ; preds = %25
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
%struct.xmi_ctx = type { i32 }
define i32 @PutVLQ(%struct.xmi_ctx* %0, i32 %1) {
%3 = and i32 %1, 127
%4 = icmp ult i32 %1, 128
br i1 %4, label %5, label %8
5: ; preds = %8, %2
%6 = phi i32 [ %3, %2 ], [ %16, %8 ]
%7 = phi i32 [ 1, %2 ], [ %17, %8 ]
br label %19
8: ; preds = %2, %8
%9 = phi i32 [ %12, %8 ], [ %1, %2 ]
%10 = phi i32 [ %17, %8 ], [ 1, %2 ]
%11 = phi i32 [ %16, %8 ], [ %3, %2 ]
%12 = ashr i32 %9, 7
%13 = shl i32 %11, 8
%14 = and i32 %12, 127
%15 = or i32 %14, %13
%16 = or i32 %15, 128
%17 = add nuw nsw i32 %10, 1
%18 = icmp ult i32 %9, 16384
br i1 %18, label %5, label %8
19: ; preds = %5, %19
%20 = phi i32 [ 0, %5 ], [ %25, %19 ]
%21 = phi i32 [ %6, %5 ], [ %24, %19 ]
%22 = and i32 %21, 255
%23 = tail call i32 @write1(%struct.xmi_ctx* %0, i32 %22)
%24 = ashr i32 %21, 8
%25 = add nuw i32 %20, 1
%26 = icmp eq i32 %25, %7
br i1 %26, label %27, label %19
27: ; preds = %19
ret i32 %7
}