#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 get_length_encode_number(char const *, int *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *get_length_encode_string(const char *buf, int *length) {
  char *string;
  int prefix_num_len;
  int len = get_length_encode_number(buf, &prefix_num_len);
  string = malloc(sizeof(char) * len + 1);
  memset(string, 0, len + 1);
  memcpy(string, buf + prefix_num_len, len);
  *length = prefix_num_len + len + 1;
  return string;
}


x86 assembly (clang, -O0):
<get_length_encode_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <get_length_encode_number@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_length_encode_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xc(%rsp),%rsi
call   1030 <get_length_encode_number@plt>
mov    %eax,%r12d
lea    0x1(%r12),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
movslq 0xc(%rsp),%rsi
add    %r15,%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1050 <memcpy@plt>
add    0xc(%rsp),%ebp
mov    %ebp,(%r14)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @get_length_encode_string(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = call i32 @get_length_encode_number(i8* %8, i32* %6)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = mul i64 1, %11
%13 = add i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
%19 = call i32 @memset(i8* %16, i32 0, i32 %18)
%20 = load i8*, i8** %5
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %7
%26 = call i32 @memcpy(i8* %20, i8* %24, i32 %25)
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = add nsw i32 %27, %28
%30 = add nsw i32 %29, 1
%31 = load i32*, i32** %4
store i32 %30, i32* %31
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
define i8* @get_length_encode_string(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @get_length_encode_number(i8* %0, i32* %3)
%6 = add i32 %5, 1
%7 = call i8* @malloc(i32 %6)
%8 = call i32 @memset(i8* %7, i32 0, i32 %6)
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = call i32 @memcpy(i8* %7, i8* %11, i32 %5)
%13 = load i32, i32* %3
%14 = add i32 %6, %13
store i32 %14, i32* %1
ret i8* %7
}