#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(char *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *realloc(char *, size_t);
int strlen(char *);
char *str_store(char *dest, char *src) {
  size_t d_size = (dest ? strlen(dest) : 0);
  size_t s_size = strlen(src) + 1;
  char *_ = realloc(dest, d_size + s_size);
  if (_)
    memcpy(_ + d_size, src, s_size);
  else
    free(dest);
  return (_);
}


x86 assembly (clang, -O0):
<str_store>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116c <str_store+0x2c>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
jmp    1176 <str_store+0x36>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1176 <str_store+0x36>
mov    -0x2c(%rbp),%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x20(%rbp),%rsi
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cb <str_store+0x8b>
mov    -0x28(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
jmp    11d4 <str_store+0x94>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_store>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
je     1161 <str_store+0x21>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r13
jmp    1164 <str_store+0x24>
xor    %r13d,%r13d
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
lea    (%rbx,%r13,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1060 <realloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     119e <str_store+0x5e>
add    $0x1,%rbx
mov    %r12,%rdi
add    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
jmp    11a6 <str_store+0x66>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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