#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 */
void unpack_integer(const unsigned char *s, unsigned long int *value,
                    size_t *i) {
  if (s[*i] <= 0x7F) {
    *value = s[*i] - 1;
    (*i)++;
  } else {
    unsigned long int val;
    size_t j;
    j = *i + 1;
    unpack_integer(s, &val, &j);
    *value = ((s[*i] - 1) % 0x7F) + (0x7F * val);
    *i = j;
  }
}


x86 assembly (clang, -O0):
<unpack_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jg     116b <unpack_integer+0x5b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
movzbl (%rax,%rcx,1),%eax
sub    $0x1,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11c2 <unpack_integer+0xb2>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <unpack_integer@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
movzbl (%rax,%rcx,1),%eax
sub    $0x1,%eax
mov    $0x7f,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
imul   $0x7f,-0x20(%rbp),%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_integer>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    (%rdx),%rax
movzbl (%rdi,%rax,1),%ecx
test   %cl,%cl
js     1137 <unpack_integer+0x27>
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%r14)
addq   $0x1,(%r15)
jmp    11a3 <unpack_integer+0x93>
mov    %rdi,%rbx
add    $0x1,%rax
mov    %rax,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <unpack_integer@plt>
mov    (%r15),%rax
movzbl (%rbx,%rax,1),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
imul   $0xffff8103,%ecx,%ecx
shr    $0x10,%ecx
add    %eax,%ecx
add    $0xffffffff,%ecx
movzwl %cx,%ecx
movswl %cx,%edx
shr    $0xf,%ecx
sar    $0x6,%edx
add    %ecx,%edx
mov    %edx,%ecx
shl    $0x7,%ecx
sub    %ecx,%edx
add    %edx,%eax
add    $0xffffffff,%eax
movswq %ax,%rax
mov    0x8(%rsp),%rcx
mov    %rcx,%rdx
shl    $0x7,%rdx
sub    %rcx,%rdx
add    %rax,%rdx
mov    %rdx,(%r14)
mov    (%rsp),%rax
mov    %rax,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @unpack_integer(i8* %0, i64* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%9 = load i8*, i8** %4
%10 = load i64*, i64** %6
%11 = load i64, i64* %10
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp sle i32 %14, 127
br i1 %15, label %16, label %29
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = load i64*, i64** %6
%19 = load i64, i64* %18
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = load i64*, i64** %5
store i64 %24, i64* %25
%26 = load i64*, i64** %6
%27 = load i64, i64* %26
%28 = add i64 %27, 1
store i64 %28, i64* %26
br label %49
29: ; preds = %3
%30 = load i64*, i64** %6
%31 = load i64, i64* %30
%32 = add i64 %31, 1
store i64 %32, i64* %8
%33 = load i8*, i8** %4
%34 = load i8*, i8** %4
%35 = load i64*, i64** %6
%36 = load i64, i64* %35
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = sub nsw i32 %39, 1
%41 = srem i32 %40, 127
%42 = sext i32 %41 to i64
%43 = load i64, i64* %7
%44 = mul i64 127, %43
%45 = add i64 %42, %44
%46 = load i64*, i64** %5
store i64 %45, i64* %46
%47 = load i64, i64* %8
%48 = load i64*, i64** %6
store i64 %47, i64* %48
br label %49
49: ; preds = %29, %16
ret void
}

LLVM IR (-O2):
define void @unpack_integer(i8* nocapture %0, i64* nocapture writeonly %1, i64* nocapture %2) {
%4 = alloca i64
%5 = alloca i64
%6 = load i64, i64* %2
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp sgt i8 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = zext i8 %8 to i64
%12 = add nsw i64 %11, -1
store i64 %12, i64* %1
%13 = load i64, i64* %2
%14 = add i64 %13, 1
store i64 %14, i64* %2
br label %30
15: ; preds = %3
%16 = bitcast i64* %4 to i8*
%17 = bitcast i64* %5 to i8*
%18 = add i64 %6, 1
store i64 %18, i64* %5
%19 = load i64, i64* %2
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i16
%23 = add nsw i16 %22, -1
%24 = srem i16 %23, 127
%25 = sext i16 %24 to i64
%26 = load i64, i64* %4
%27 = mul i64 %26, 127
%28 = add i64 %27, %25
store i64 %28, i64* %1
%29 = load i64, i64* %5
store i64 %29, i64* %2
br label %30
30: ; preds = %15, %10
ret void
}