#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 write_raw_byte(char, void *, int);
int write_raw_varint64(unsigned long long value, void *_buffer, int offset) {
  while (1) {
    if ((value & ~0x7FL) == 0) {
      offset = write_raw_byte((char)value, _buffer, offset);
      return offset;
    } else {
      offset = write_raw_byte((char)((value & 0x7F) | 0x80), _buffer, offset);
      value = value >> 7;
    }
  }
  return offset;
}


x86 assembly (clang, -O0):
<write_raw_varint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
and    $0xffffffffffffff80,%rax
cmp    $0x0,%rax
jne    1154 <write_raw_varint64+0x44>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl %al,%edi
call   1030 <write_raw_byte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%rax
and    $0x7f,%rax
or     $0x80,%rax
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl %al,%edi
call   1030 <write_raw_byte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x7,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <write_raw_varint64+0x13>

x86 assembly (clang, -O2):
<write_raw_varint64>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%eax
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x80,%rdi
jae    112b <write_raw_varint64+0x1b>
mov    %r15,%rbx
jmp    1153 <write_raw_varint64+0x43>
mov    %r15,%rbx
xchg   %ax,%ax
mov    %r15d,%ecx
or     $0x80,%cl
movsbl %cl,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write_raw_byte@plt>
shr    $0x7,%rbx
cmp    $0x4000,%r15
mov    %rbx,%r15
jae    1130 <write_raw_varint64+0x20>
movsbl %bl,%edi
mov    %r14,%rsi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <write_raw_byte@plt>

LLVM IR (-O0):
define i32 @write_raw_varint64(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %7
7: ; preds = %3, %28
%8 = load i64, i64* %4
%9 = and i64 %8, -128
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i64, i64* %4
%13 = trunc i64 %12 to i8
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = call i32 @write_raw_byte(i8 signext %13, i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
ret i32 %17
18: ; preds = %7
%19 = load i64, i64* %4
%20 = and i64 %19, 127
%21 = or i64 %20, 128
%22 = trunc i64 %21 to i8
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = call i32 @write_raw_byte(i8 signext %22, i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = load i64, i64* %4
%27 = lshr i64 %26, 7
store i64 %27, i64* %4
br label %28
28: ; preds = %18
br label %7
}

LLVM IR (-O2):
define i32 @write_raw_varint64(i64 %0, i8* %1, i32 %2) {
%4 = icmp ult i64 %0, 128
br i1 %4, label %5, label %10
5: ; preds = %10, %3
%6 = phi i64 [ %0, %3 ], [ %16, %10 ]
%7 = phi i32 [ %2, %3 ], [ %15, %10 ]
%8 = trunc i64 %6 to i8
%9 = tail call i32 @write_raw_byte(i8 signext %8, i8* %1, i32 %7)
ret i32 %9
10: ; preds = %3, %10
%11 = phi i32 [ %15, %10 ], [ %2, %3 ]
%12 = phi i64 [ %16, %10 ], [ %0, %3 ]
%13 = trunc i64 %12 to i8
%14 = or i8 %13, -128
%15 = tail call i32 @write_raw_byte(i8 signext %14, i8* %1, i32 %11)
%16 = lshr i64 %12, 7
%17 = icmp ult i64 %12, 16384
br i1 %17, label %5, label %10
}