#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 */
char *realloc(char *, int);
char *deserializeString(void **buffer) {
  char *str = NULL;
  int i = 0;
  do {
    str = realloc(str, (i + 1) * sizeof(char));
    str[i++] = *(char *)*buffer;
    *buffer += sizeof(char);
  } while (*(char *)*buffer != '\0');
  *buffer += sizeof(char);
  str = realloc(str, (i + 1) * sizeof(char));
  str[i] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<deserializeString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    112b <deserializeString+0x1b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deserializeString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
nopl   0x0(%rax)
mov    %rbx,%r15
add    $0x1,%rbx
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <realloc@plt>
mov    (%r14),%rcx
movzbl (%rcx),%ecx
mov    %cl,(%rax,%r15,1)
mov    (%r14),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%r14)
cmpb   $0x0,0x1(%rcx)
jne    1120 <deserializeString+0x10>
mov    %ebx,%r15d
add    $0x2,%rcx
mov    %rcx,(%r14)
add    $0x1,%ebx
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <realloc@plt>
movb   $0x0,(%rax,%r15,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @deserializeString(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i32
store i8** %0, i8*** %2
store i8* null, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %24, %1
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i8* @realloc(i8* %6, i32 %11)
store i8* %12, i8** %3
%13 = load i8**, i8*** %2
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 %15, i8* %20
%21 = load i8**, i8*** %2
%22 = load i8*, i8** %21
%23 = getelementptr i8, i8* %22, i64 1
store i8* %23, i8** %21
br label %24
24: ; preds = %5
%25 = load i8**, i8*** %2
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %5, label %30
30: ; preds = %24
%31 = load i8**, i8*** %2
%32 = load i8*, i8** %31
%33 = getelementptr i8, i8* %32, i64 1
store i8* %33, i8** %31
%34 = load i8*, i8** %3
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = trunc i64 %38 to i32
%40 = call i8* @realloc(i8* %34, i32 %39)
store i8* %40, i8** %3
%41 = load i8*, i8** %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
define i8* @deserializeString(i8** nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %5, %2 ], [ 0, %1 ]
%4 = phi i8* [ %7, %2 ], [ null, %1 ]
%5 = add nuw i64 %3, 1
%6 = trunc i64 %5 to i32
%7 = tail call i8* @realloc(i8* %4, i32 %6)
%8 = load i8*, i8** %0
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %7, i64 %3
store i8 %9, i8* %10
%11 = load i8*, i8** %0
%12 = getelementptr i8, i8* %11, i64 1
store i8* %12, i8** %0
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %2
15: ; preds = %2
%16 = trunc i64 %3 to i32
%17 = and i64 %5, 4294967295
%18 = getelementptr i8, i8* %11, i64 2
store i8* %18, i8** %0
%19 = add nuw nsw i32 %16, 2
%20 = tail call i8* @realloc(i8* %7, i32 %19)
%21 = getelementptr inbounds i8, i8* %20, i64 %17
store i8 0, i8* %21
ret i8* %20
}