#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 uint8_t;
typedef int uint64_t;

/* Variables and functions */
int ss_leb128write(char *dest, uint64_t value) {
  int size = 0;
  do {
    uint8_t byte = value & 0x7F;
    value >>= 7;
    if (value != 0)
      byte |= 0x80;
    ((unsigned char *)dest)[size++] = byte;
  } while (value != 0);
  return size;
}


x86 assembly (clang, -O0):
<ss_leb128write>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x7,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1139 <ss_leb128write+0x39>
mov    -0x14(%rbp),%eax
or     $0x80,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x0,-0xc(%rbp)
jne    1112 <ss_leb128write+0x12>
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ss_leb128write>:
xor    %eax,%eax
mov    %esi,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
sar    $0x7,%ecx
mov    %esi,%r8d
or     $0x80,%r8b
mov    %esi,%edx
and    $0x7f,%dl
cmp    $0x80,%esi
movzbl %dl,%r9d
movzbl %r8b,%edx
cmovb  %r9d,%edx
mov    %dl,(%rdi,%rax,1)
add    $0x1,%rax
cmp    $0x7f,%esi
mov    %ecx,%esi
ja     1110 <ss_leb128write+0x10>
ret

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

LLVM IR (-O2):
define i32 @ss_leb128write(i8* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ %12, %3 ], [ 0, %2 ]
%5 = phi i32 [ %7, %3 ], [ %1, %2 ]
%6 = and i32 %5, 127
%7 = ashr i32 %5, 7
%8 = icmp ult i32 %5, 128
%9 = or i32 %5, 128
%10 = select i1 %8, i32 %6, i32 %9
%11 = trunc i32 %10 to i8
%12 = add nuw i64 %4, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 %11, i8* %13
br i1 %8, label %14, label %3
14: ; preds = %3
%15 = trunc i64 %12 to i32
ret i32 %15
}