#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 *calloc(scalar_t__, int);
char *strcpy(char *, char *);
scalar_t__ strlen(char *);
char *pl_cpy(char *source, char *destination) {
  char *ret_val = destination;
  if (source == NULL) {
    goto error_exit;
  }
  if (destination == NULL) {
    ret_val = calloc(strlen(source) + 1, sizeof(char));
    if (ret_val == NULL) {
      goto error_exit;
    }
  }
  ret_val = strcpy(ret_val, source);
  return ret_val;
error_exit:
  return NULL;
}


x86 assembly (clang, -O0):
<pl_cpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <pl_cpy+0x28>
jmp    11b4 <pl_cpy+0x84>
cmpq   $0x0,-0x18(%rbp)
jne    1196 <pl_cpy+0x66>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <pl_cpy+0x61>
jmp    11b4 <pl_cpy+0x84>
jmp    1196 <pl_cpy+0x66>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <pl_cpy+0x8c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_cpy>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116f <pl_cpy+0x3f>
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
jne    1162 <pl_cpy+0x32>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116f <pl_cpy+0x3f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    1171 <pl_cpy+0x41>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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