#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*/ free(unsigned int *);
int /*<<< orphan*/ memcpy(unsigned int *, unsigned int *, unsigned int);
unsigned int *realloc(unsigned int *, size_t);
unsigned int *append_to_unicode_string(unsigned int *unicode_string,
                                       unsigned int *appendix) {
  size_t new_length;
  unsigned int *new_string;
  if (unicode_string == NULL) {
    new_string = appendix;
  } else {
    new_length = unicode_string[0] + appendix[0];
    new_string =
        realloc(unicode_string, (new_length + 1) * sizeof(*unicode_string));
    if (new_string == NULL) {
      free(unicode_string);
    } else {
      memcpy(new_string + unicode_string[0] + 1, appendix + 1,
             appendix[0] * sizeof(*unicode_string));
      new_string[0] = new_length;
    }
    free(appendix);
  }
  return new_string;
}


x86 assembly (clang, -O0):
<append_to_unicode_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1158 <append_to_unicode_string+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11df <append_to_unicode_string+0xaf>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,%eax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
shl    $0x2,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <append_to_unicode_string+0x6c>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    11d6 <append_to_unicode_string+0xa6>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_to_unicode_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     117c <append_to_unicode_string+0x4c>
mov    %rdi,%rbx
mov    (%r14),%r12d
add    (%rdi),%r12d
lea    0x4(,%r12,4),%rsi
call   1050 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1181 <append_to_unicode_string+0x51>
mov    (%rbx),%eax
lea    (%r15,%rax,4),%rdi
add    $0x4,%rdi
lea    0x4(%r14),%rsi
mov    (%r14),%edx
shl    $0x2,%edx
call   1040 <memcpy@plt>
mov    %r12d,(%r15)
jmp    1189 <append_to_unicode_string+0x59>
mov    %r14,%r15
jmp    1191 <append_to_unicode_string+0x61>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32* @append_to_unicode_string(i32* %0, i32* %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %26, label %4
4: ; preds = %2
%5 = load i32, i32* %0
%6 = load i32, i32* %1
%7 = add i32 %6, %5
%8 = zext i32 %7 to i64
%9 = shl nuw nsw i64 %8, 2
%10 = add nuw nsw i64 %9, 4
%11 = tail call i32* @realloc(i32* %0, i64 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 @free(i32* %0)
br label %24
15: ; preds = %4
%16 = load i32, i32* %0
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %11, i64 %17
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = getelementptr inbounds i32, i32* %1, i64 1
%21 = load i32, i32* %1
%22 = shl i32 %21, 2
%23 = tail call i32 @memcpy(i32* %19, i32* %20, i32 %22)
store i32 %7, i32* %11
br label %24
24: ; preds = %15, %13
%25 = tail call i32 @free(i32* %1)
br label %26
26: ; preds = %2, %24
%27 = phi i32* [ %11, %24 ], [ %1, %2 ]
ret i32* %27
}