#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) {
  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    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdx
mov    (%rdx),%ecx
add    $0x1,%ecx
mov    %ecx,(%rdx)
mov    %ecx,%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 i8*, i8** %3
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = add i32 %8, 1
store i32 %9, i32* %7
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = call i64 @calloc(i32 1, i32* %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = load i8*, i8** %3
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = add i32 %22, 1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8*, i8** %3
%27 = load i32*, i32** %4
%28 = load i32, i32* %27
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @memcpy(i8* %19, i8* %25, i8 zeroext %31)
%33 = load i32*, i32** %4
%34 = load i32, i32* %33
%35 = load i8*, i8** %3
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = add i32 %34, %41
%43 = add i32 %42, 1
%44 = load i32*, i32** %4
store i32 %43, i32* %44
%45 = load i8*, i8** %5
ret i8* %45
}

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
}