#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 redislitePutVarint(unsigned char *, int);
int redislitePutVarint32(unsigned char *p, int v) {
  if ((v & ~0x7f) == 0) {
    p[0] = v;
    return 1;
  }
  if ((v & ~0x3fff) == 0) {
    p[0] = (int)((v >> 7) | 0x80);
    p[1] = (int)(v & 0x7f);
    return 2;
  }
  return redislitePutVarint(p, v);
}


x86 assembly (clang, -O0):
<redislitePutVarint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xffffff80,%eax
cmp    $0x0,%eax
jne    1145 <redislitePutVarint32+0x35>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1193 <redislitePutVarint32+0x83>
mov    -0x14(%rbp),%eax
and    $0xffffc000,%eax
cmp    $0x0,%eax
jne    1184 <redislitePutVarint32+0x74>
mov    -0x14(%rbp),%eax
sar    $0x7,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x2,-0x4(%rbp)
jmp    1193 <redislitePutVarint32+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <redislitePutVarint@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redislitePutVarint32>:
cmp    $0x7f,%esi
ja     111e <redislitePutVarint32+0xe>
mov    %sil,(%rdi)
mov    $0x1,%eax
ret
cmp    $0x3fff,%esi
ja     113d <redislitePutVarint32+0x2d>
mov    %esi,%eax
shr    $0x7,%eax
or     $0x80,%al
mov    %al,(%rdi)
and    $0x7f,%sil
mov    %sil,0x1(%rdi)
mov    $0x2,%eax
ret
jmp    1030 <redislitePutVarint@plt>

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

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