#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 /*<<< orphan*/ memmove(char *, char *, unsigned int);
unsigned int unpack_int(char **);
char *unpack_str(char **cur) {
  unsigned int len;
  len = unpack_int(cur);
  memmove((*cur) - 1, (*cur), len);
  (*cur) += len;
  (*cur)[-1] = '\0';
  return (*cur) - len - 1;
}


x86 assembly (clang, -O0):
<unpack_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <unpack_int@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    $0xffffffffffffffff,%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memmove@plt>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    %edx,%edx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,-0x1(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_str>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <unpack_int@plt>
mov    %eax,%ebp
mov    (%rbx),%rsi
lea    -0x1(%rsi),%rdi
mov    %eax,%edx
call   1030 <memmove@plt>
mov    (%rbx),%rcx
mov    %ebp,%eax
lea    (%rcx,%rax,1),%rdx
mov    %rdx,(%rbx)
movb   $0x0,-0x1(%rcx,%rax,1)
not    %rax
add    (%rbx),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @unpack_str(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
%4 = load i8**, i8*** %2
%5 = call i32 @unpack_int(i8** %4)
store i32 %5, i32* %3
%6 = load i8**, i8*** %2
%7 = load i8*, i8** %6
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = load i8**, i8*** %2
%10 = load i8*, i8** %9
%11 = load i32, i32* %3
%12 = call i32 @memmove(i8* %8, i8* %10, i32 %11)
%13 = load i32, i32* %3
%14 = load i8**, i8*** %2
%15 = load i8*, i8** %14
%16 = zext i32 %13 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %14
%18 = load i8**, i8*** %2
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8 0, i8* %20
%21 = load i8**, i8*** %2
%22 = load i8*, i8** %21
%23 = load i32, i32* %3
%24 = zext i32 %23 to i64
%25 = sub i64 0, %24
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -1
ret i8* %27
}

LLVM IR (-O2):
define i8* @unpack_str(i8** %0) {
%2 = tail call i32 @unpack_int(i8** %0)
%3 = load i8*, i8** %0
%4 = getelementptr inbounds i8, i8* %3, i64 -1
%5 = tail call i32 @memmove(i8* %4, i8* %3, i32 %2)
%6 = load i8*, i8** %0
%7 = zext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %6, i64 %7
store i8* %8, i8** %0
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 0, i8* %9
%10 = load i8*, i8** %0
%11 = sub nsw i64 0, %7
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
ret i8* %13
}