#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(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *KSRM16162742943295_br_strcat(const char *str1, const char *str2) {
  char *result;
  size_t len1, len2;
  if (str1 == ((char *)0))
    str1 = "";
  if (str2 == ((char *)0))
    str2 = "";
  len1 = strlen(str1);
  len2 = strlen(str2);
  result = (char *)malloc(len1 + len2 + 1);
  if (result) {
    memcpy(result, str1, len1);
    memcpy(result + len1, str2, len2);
    result[len1 + len2] = '\0';
  }
  return result;
}


x86 assembly (clang, -O0):
<KSRM16162742943295_br_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1156 <KSRM16162742943295_br_strcat+0x26>
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <KSRM16162742943295_br_strcat+0x3c>
lea    0xe98(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11dc <KSRM16162742943295_br_strcat+0xac>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KSRM16162742943295_br_strcat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
test   %rdi,%rdi
lea    0xeb8(%rip),%rax
cmove  %rax,%r13
mov    %rsi,%r14
test   %rsi,%rsi
cmove  %rax,%r14
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
lea    (%rax,%r15,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11aa <KSRM16162742943295_br_strcat+0x7a>
mov    %r12,%rbp
add    %r15,%rbp
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
add    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @KSRM16162742943295_br_strcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %11
11: ; preds = %10, %2
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
br label %15
15: ; preds = %14, %11
%16 = load i8*, i8** %3
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %6
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %7
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = add i64 %20, %21
%23 = add i64 %22, 1
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %44
28: ; preds = %15
%29 = load i8*, i8** %5
%30 = load i8*, i8** %3
%31 = load i64, i64* %6
%32 = call i32 @memcpy(i8* %29, i8* %30, i64 %31)
%33 = load i8*, i8** %5
%34 = load i64, i64* %6
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8*, i8** %4
%37 = load i64, i64* %7
%38 = call i32 @memcpy(i8* %35, i8* %36, i64 %37)
%39 = load i8*, i8** %5
%40 = load i64, i64* %6
%41 = load i64, i64* %7
%42 = add i64 %40, %41
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %28, %15
%45 = load i8*, i8** %5
ret i8* %45
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @KSRM16162742943295_br_strcat(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%5 = icmp eq i8* %1, null
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%7 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%9 = add i64 %8, %7
%10 = add i64 %9, 1
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = tail call i32 @memcpy(i8* %12, i8* %4, i64 %7)
%16 = getelementptr inbounds i8, i8* %12, i64 %7
%17 = tail call i32 @memcpy(i8* %16, i8* %6, i64 %8)
%18 = getelementptr inbounds i8, i8* %12, i64 %9
store i8 0, i8* %18
br label %19
19: ; preds = %14, %2
ret i8* %12
}