#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__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *pchar_copy(char const *);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
char *pchar_concat(const char *s1, const char *s2) {
  if (!s1 || strlen(s1) < 1)
    return pchar_copy(s2);
  if (!s2 || strlen(s2) < 1)
    return pchar_copy(s1);
  int slen1 = strlen(s1), slen2 = strlen(s2);
  int slen = slen1 + slen2;
  char *newstr = (char *)malloc(slen + 1);
  memset(newstr, 0, slen + 1);
  memcpy(newstr, s1, slen1);
  strcat(newstr, s2);
  return newstr;
}


x86 assembly (clang, -O0):
<pchar_concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118d <pchar_concat+0x2d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    119f <pchar_concat+0x3f>
mov    -0x18(%rbp),%rdi
call   1070 <pchar_copy@plt>
mov    %rax,-0x8(%rbp)
jmp    1234 <pchar_concat+0xd4>
cmpq   $0x0,-0x18(%rbp)
je     11bc <pchar_concat+0x5c>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    11ce <pchar_concat+0x6e>
mov    -0x10(%rbp),%rdi
call   1070 <pchar_copy@plt>
mov    %rax,-0x8(%rbp)
jmp    1234 <pchar_concat+0xd4>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pchar_concat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11e5 <pchar_concat+0x85>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    11e5 <pchar_concat+0x85>
test   %r14,%r14
je     11ea <pchar_concat+0x8a>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11ea <pchar_concat+0x8a>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%r12d
add    $0x1,%r12d
mov    %r12d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
jmp    11ed <pchar_concat+0x8d>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <pchar_copy@plt>

LLVM IR (-O0):
define i8* @pchar_concat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %12, %2
%17 = load i8*, i8** %5
%18 = call i8* @pchar_copy(i8* %17)
store i8* %18, i8** %3
br label %53
19: ; preds = %12
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %22, %19
%27 = load i8*, i8** %4
%28 = call i8* @pchar_copy(i8* %27)
store i8* %28, i8** %3
br label %53
29: ; preds = %22
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %6
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
store i32 %33, i32* %7
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = add nsw i32 %34, %35
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = call i32 @memset(i8* %41, i32 0, i32 %43)
%45 = load i8*, i8** %9
%46 = load i8*, i8** %4
%47 = load i32, i32* %6
%48 = call i32 @memcpy(i8* %45, i8* %46, i32 %47)
%49 = load i8*, i8** %9
%50 = load i8*, i8** %5
%51 = call i32 @strcat(i8* %49, i8* %50)
%52 = load i8*, i8** %9
store i8* %52, i8** %3
br label %53
53: ; preds = %29, %26, %16
%54 = load i8*, i8** %3
ret i8* %54
}

LLVM IR (-O2):
define i8* @pchar_concat(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 = icmp slt i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %4, %2
%8 = tail call i8* @pchar_copy(i8* %1)
br label %26
9: ; preds = %4
%10 = icmp eq i8* %1, null
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = tail call i32 @strlen(i8* %1)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %11, %9
%15 = tail call i8* @pchar_copy(i8* %0)
br label %26
16: ; preds = %11
%17 = tail call i32 @strlen(i8* %0)
%18 = tail call i32 @strlen(i8* %1)
%19 = add i32 %17, 1
%20 = add i32 %19, %18
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 @memset(i8* %22, i32 0, i32 %20)
%24 = tail call i32 @memcpy(i8* %22, i8* %0, i32 %17)
%25 = tail call i32 @strcat(i8* %22, i8* %1)
br label %26
26: ; preds = %16, %14, %7
%27 = phi i8* [ %8, %7 ], [ %15, %14 ], [ %22, %16 ]
ret i8* %27
}