#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 uint64_t;

/* Variables and functions */
int ss_leb128read(char *src, uint64_t *value) {
  unsigned char *start = (unsigned char *)src;
  int lsh = 0;
  *value = 0;
  do {
    *value |= ((uint64_t)(*(unsigned char *)src & 0x7F)) << lsh;
    lsh += 7;
  } while (*((unsigned char *)src++) >= 128);
  return (unsigned char *)src - start;
}


x86 assembly (clang, -O0):
<ss_leb128read>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
mov    -0x1c(%rbp),%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%eax
cmp    $0x80,%eax
jge    1125 <ss_leb128read+0x25>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ss_leb128read>:
movl   $0x0,(%rsi)
xor    %eax,%eax
xor    %r8d,%r8d
xor    %ecx,%ecx
nopl   (%rax)
movzbl (%rdi,%rax,1),%edx
and    $0x7f,%edx
shl    %cl,%edx
or     %edx,%r8d
mov    %r8d,(%rsi)
add    $0x7,%ecx
cmpb   $0x0,(%rdi,%rax,1)
lea    0x1(%rax),%rax
js     1110 <ss_leb128read+0x10>
ret

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

LLVM IR (-O2):
define i32 @ss_leb128read(i8* %0, i32* nocapture %1) {
store i32 0, i32* %1
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 0, %2 ], [ %11, %3 ]
%5 = phi i8* [ %0, %2 ], [ %13, %3 ]
%6 = phi i32 [ 0, %2 ], [ %12, %3 ]
%7 = load i8, i8* %5
%8 = and i8 %7, 127
%9 = zext i8 %8 to i32
%10 = shl i32 %9, %6
%11 = or i32 %10, %4
store i32 %11, i32* %1
%12 = add nuw nsw i32 %6, 7
%13 = getelementptr inbounds i8, i8* %5, i64 1
%14 = load i8, i8* %5
%15 = icmp slt i8 %14, 0
br i1 %15, label %3, label %16
16: ; preds = %3
%17 = ptrtoint i8* %13 to i64
%18 = ptrtoint i8* %0 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
ret i32 %20
}