#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 _read_int(char **);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *_read_string_len(char **pptr, int *len) {
  char *string = NULL;
  *len = _read_int(pptr);
  string = malloc(*len + 1);
  memcpy(string, *pptr, *len);
  string[*len] = '\0';
  *pptr += *len;
  return string;
}


x86 assembly (clang, -O0):
<_read_string_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <_read_int@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_read_string_len>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <_read_int@plt>
mov    %eax,%r12d
mov    %eax,(%r14)
lea    0x1(%r12),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
call   1030 <memcpy@plt>
movslq (%r14),%rax
movb   $0x0,(%rbx,%rax,1)
add    %rax,(%r15)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @_read_string_len(i8** %0, i32* nocapture %1) {
%3 = tail call i32 @_read_int(i8** %0)
store i32 %3, i32* %1
%4 = add nsw i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = load i8*, i8** %0
%7 = tail call i32 @memcpy(i8* %5, i8* %6, i32 %3)
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 0, i8* %10
%11 = load i8*, i8** %0
%12 = getelementptr inbounds i8, i8* %11, i64 %9
store i8* %12, i8** %0
ret i8* %5
}