#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 *myrealloc(char *, int);
char *strcpy(char *, char *);
int strlen(char *);
char *realloc_strcpy(char **dest, char *src) {
  char *new = (dest ? *dest : NULL);
  new = myrealloc(new, (strlen(src) + 1) * sizeof(char));
  if (dest)
    *dest = new;
  return strcpy(new, src);
}


x86 assembly (clang, -O0):
<realloc_strcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115b <realloc_strcpy+0x2b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1166 <realloc_strcpy+0x36>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    1166 <realloc_strcpy+0x36>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <myrealloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ad <realloc_strcpy+0x7d>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_strcpy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1145 <realloc_strcpy+0x15>
mov    (%rbx),%r15
jmp    1148 <realloc_strcpy+0x18>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r15,%rdi
call   1050 <myrealloc@plt>
test   %rbx,%rbx
je     1163 <realloc_strcpy+0x33>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define i8* @realloc_strcpy(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8**, i8*** %3
%7 = icmp ne i8** %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
br label %12
11: ; preds = %2
br label %12
12: ; preds = %11, %8
%13 = phi i8* [ %10, %8 ], [ null, %11 ]
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i8* @myrealloc(i8* %14, i32 %20)
store i8* %21, i8** %5
%22 = load i8**, i8*** %3
%23 = icmp ne i8** %22, null
br i1 %23, label %24, label %27
24: ; preds = %12
%25 = load i8*, i8** %5
%26 = load i8**, i8*** %3
store i8* %25, i8** %26
br label %27
27: ; preds = %24, %12
%28 = load i8*, i8** %5
%29 = load i8*, i8** %4
%30 = call i8* @strcpy(i8* %28, i8* %29)
ret i8* %30
}

LLVM IR (-O2):
define i8* @realloc_strcpy(i8** %0, i8* %1) {
%3 = icmp eq i8** %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = load i8*, i8** %0
br label %6
6: ; preds = %2, %4
%7 = phi i8* [ %5, %4 ], [ null, %2 ]
%8 = tail call i32 @strlen(i8* %1)
%9 = add nsw i32 %8, 1
%10 = tail call i8* @myrealloc(i8* %7, i32 %9)
br i1 %3, label %12, label %11
11: ; preds = %6
store i8* %10, i8** %0
br label %12
12: ; preds = %11, %6
%13 = tail call i8* @strcpy(i8* dereferenceable(1) %10, i8* dereferenceable(1) %1)
ret i8* %10
}