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


x86 assembly (clang, -O0):
<pl_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <pl_cat+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1183 <pl_cat+0x33>
movq   $0x0,-0x8(%rbp)
jmp    120e <pl_cat+0xbe>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <pl_cat+0x72>
jmp    11fd <pl_cat+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <pl_cpy@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e3 <pl_cat+0x93>
jmp    11fd <pl_cat+0xad>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120e <pl_cat+0xbe>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_cat>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     11ba <pl_cat+0x6a>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ba <pl_cat+0x6a>
mov    %rdi,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11b1 <pl_cat+0x61>
mov    %r15,%rdi
mov    %rax,%rsi
call   1060 <pl_cpy@plt>
test   %rax,%rax
je     11b1 <pl_cat+0x61>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    11ba <pl_cat+0x6a>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @pl_cat(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** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i8* null, i8** %3
br label %40
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = load i8*, i8** %4
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %15, %17
%19 = add nsw i64 %18, 1
%20 = call i64 @calloc(i64 %19, i32 1)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %13
br label %37
25: ; preds = %13
%26 = load i8*, i8** %4
%27 = load i8*, i8** %6
%28 = call i8* @pl_cpy(i8* %26, i8* %27)
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %25
br label %37
32: ; preds = %25
%33 = load i8*, i8** %6
%34 = load i8*, i8** %5
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i8*, i8** %6
store i8* %36, i8** %3
br label %40
37: ; preds = %31, %24
%38 = load i8*, i8** %6
%39 = call i32 @free(i8* %38)
store i8* null, i8** %3
br label %40
40: ; preds = %37, %32, %12
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
define i8* @pl_cat(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = add i64 %7, 1
%10 = add i64 %9, %8
%11 = tail call i64 @calloc(i64 %10, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %6
%14 = inttoptr i64 %11 to i8*
%15 = tail call i8* @pl_cpy(i8* %0, i8* %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @strcat(i8* %15, i8* %1)
br label %21
19: ; preds = %13, %6
%20 = tail call i32 @free(i8* null)
br label %21
21: ; preds = %17, %19, %2
%22 = phi i8* [ null, %2 ], [ null, %19 ], [ %15, %17 ]
ret i8* %22
}