#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 /*<<< orphan*/ memcpy(int *, char const *, int);
int get_length_encode_number(const char *buf, int *length) {
  int tmp = 0;
  uint64_t data = 0;
  *length = 0;
  tmp = *buf++;
  if (tmp < 0xFB) {
    data = tmp;
    *length = 1;
  } else {
    if (tmp == 0xFC) {
      tmp = 2;
    } else if (tmp == 0xFD) {
      tmp = 3;
    } else if (tmp == 0xFE) {
      tmp = 8;
    }
    memcpy(&data, buf, tmp);
    *length = tmp + 1;
  }
  return data;
}


x86 assembly (clang, -O0):
<get_length_encode_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xfb,-0x14(%rbp)
jge    116f <get_length_encode_number+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11db <get_length_encode_number+0xcb>
cmpl   $0xfc,-0x14(%rbp)
jne    1188 <get_length_encode_number+0x78>
movl   $0x2,-0x14(%rbp)
jmp    11bf <get_length_encode_number+0xaf>
cmpl   $0xfd,-0x14(%rbp)
jne    11a1 <get_length_encode_number+0x91>
movl   $0x3,-0x14(%rbp)
jmp    11ba <get_length_encode_number+0xaa>
cmpl   $0xfe,-0x14(%rbp)
jne    11b5 <get_length_encode_number+0xa5>
movl   $0x8,-0x14(%rbp)
jmp    11ba <get_length_encode_number+0xaa>
jmp    11bf <get_length_encode_number+0xaf>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x18(%rbp),%rdi
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_length_encode_number>:
movl   $0x0,(%rsi)
movsbl (%rdi),%eax
movl   $0x1,(%rsi)
ret

LLVM IR (-O0):
define i32 @get_length_encode_number(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
store i32 0, i32* %6
%7 = load i32*, i32** %4
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %3
%10 = load i8, i8* %8
%11 = sext i8 %10 to i32
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 251
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* %5
store i32 %15, i32* %6
%16 = load i32*, i32** %4
store i32 1, i32* %16
br label %38
17: ; preds = %2
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 252
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 2, i32* %5
br label %31
21: ; preds = %17
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 253
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 3, i32* %5
br label %30
25: ; preds = %21
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 254
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 8, i32* %5
br label %29
29: ; preds = %28, %25
br label %30
30: ; preds = %29, %24
br label %31
31: ; preds = %30, %20
%32 = load i8*, i8** %3
%33 = load i32, i32* %5
%34 = call i32 @memcpy(i32* %6, i8* %32, i32 %33)
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
%37 = load i32*, i32** %4
store i32 %36, i32* %37
br label %38
38: ; preds = %31, %14
%39 = load i32, i32* %6
ret i32 %39
}

LLVM IR (-O2):
define i32 @get_length_encode_number(i8* nocapture %0, i32* nocapture writeonly %1) {
store i32 0, i32* %1
%3 = load i8, i8* %0
store i32 1, i32* %1
%4 = sext i8 %3 to i32
ret i32 %4
}