#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*/ assert(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char const *);
char *xrealloc(char *, int);
char *strprepend(char **dest, const char *src) {
  assert(dest != NULL && src != NULL);
  *dest = xrealloc(*dest, strlen(*dest) + strlen(src) + 1);
  memmove(*dest + strlen(src), *dest, strlen(*dest) + 1);
  memcpy(*dest, src, strlen(src));
  return *dest;
}


x86 assembly (clang, -O0):
<strprepend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     117b <strprepend+0x2b>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%rdi
add    %eax,%esi
add    $0x1,%esi
call   1040 <xrealloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1070 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strprepend>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    0x0(%r13),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%esi
add    $0x1,%esi
mov    %r15,%rdi
call   1040 <xrealloc@plt>
mov    %rax,%r15
mov    %rax,0x0(%r13)
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %r15,%rbx
mov    0x0(%r13),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <memmove@plt>
mov    0x0(%r13),%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    0x0(%r13),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strprepend(i8** %0, i8* %1) {
%3 = icmp ne i8** %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i8*, i8** %0
%9 = tail call i32 @strlen(i8* %8)
%10 = tail call i32 @strlen(i8* %1)
%11 = add i32 %9, 1
%12 = add i32 %11, %10
%13 = tail call i8* @xrealloc(i8* %8, i32 %12)
store i8* %13, i8** %0
%14 = tail call i32 @strlen(i8* %1)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8*, i8** %0
%18 = tail call i32 @strlen(i8* %17)
%19 = add nsw i32 %18, 1
%20 = tail call i32 @memmove(i8* %16, i8* %17, i32 %19)
%21 = load i8*, i8** %0
%22 = tail call i32 @strlen(i8* %1)
%23 = tail call i32 @memcpy(i8* %21, i8* %1, i32 %22)
%24 = load i8*, i8** %0
ret i8* %24
}