#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 /*<<< orphan*/ array;

/* Variables and functions */
scalar_t__ calloc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned char);
unsigned char *decode_string(unsigned char *array, unsigned int *pointer) {
  *pointer = *pointer + 1;
  unsigned char *string = (unsigned char *)calloc(1, (array[*pointer]) + 1);
  memcpy(string, &array[*pointer + 1], array[*pointer]);
  *pointer = *pointer + array[*pointer] + 1;
  return string;
}


x86 assembly (clang, -O0):
<decode_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
movzbl (%rax,%rcx,1),%eax
add    $0x1,%eax
movslq %eax,%rsi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,%eax
add    %rax,%rsi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
mov    (%rax,%rcx,1),%al
movzbl %al,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdx
mov    (%rdx),%edx
movzbl (%rax,%rdx,1),%eax
add    %eax,%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):
<decode_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%eax
add    $0x1,%eax
mov    %eax,(%rsi)
movzbl (%rdi,%rax,1),%esi
add    $0x1,%rsi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,%r15
mov    (%rbx),%eax
lea    0x1(%rax),%esi
add    %r14,%rsi
movzbl (%r14,%rax,1),%edx
mov    %r15,%rdi
call   1040 <memcpy@plt>
mov    (%rbx),%eax
movzbl (%r14,%rax,1),%ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%rbx)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @decode_string(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = load i32, i32* %6
%8 = add i32 %7, 1
%9 = load i32*, i32** %4
store i32 %8, i32* %9
%10 = load i8*, i8** %3
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = call i64 @calloc(i32 1, i32* %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = add i32 %25, 1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
%29 = load i8*, i8** %3
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @memcpy(i8* %22, i8* %28, i8 zeroext %34)
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = load i8*, i8** %3
%39 = load i32*, i32** %4
%40 = load i32, i32* %39
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = add i32 %37, %44
%46 = add i32 %45, 1
%47 = load i32*, i32** %4
store i32 %46, i32* %47
%48 = load i8*, i8** %5
ret i8* %48
}

LLVM IR (-O2):
define i8* @decode_string(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = add i32 %3, 1
store i32 %4, i32* %1
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = zext i8 %7 to i64
%9 = add nuw nsw i64 %8, 1
%10 = inttoptr i64 %9 to i32*
%11 = tail call i64 @calloc(i32 1, i32* %10)
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* %1
%14 = add i32 %13, 1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = zext i32 %13 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = tail call i32 @memcpy(i8* %12, i8* %16, i8 zeroext %19)
%21 = load i32, i32* %1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = add i32 %21, 1
%27 = add i32 %26, %25
store i32 %27, i32* %1
ret i8* %12
}