#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 */
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *realloc(char *, int);
int strlen(char const *);
char *String_Concat(char *string, const char *string_to_append) {
  int len1, len2;
  char *result;
  len1 = strlen(string);
  len2 = strlen(string_to_append);
  if (NULL == (result = realloc(string, (len1 + len2 + 1) * sizeof *result)))
    return (NULL);
  memcpy(result + len1, string_to_append, len2 + 1);
  return result;
}


x86 assembly (clang, -O0):
<String_Concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
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    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1191 <String_Concat+0x61>
movq   $0x0,-0x8(%rbp)
jmp    11b3 <String_Concat+0x83>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<String_Concat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
lea    (%r12,%r15,1),%esi
add    $0x1,%esi
mov    %rbx,%rdi
call   1050 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1180 <String_Concat+0x50>
add    $0x1,%r12d
movslq %r15d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @String_Concat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = add nsw i32 %14, %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* @realloc(i8* %13, i32 %20)
store i8* %21, i8** %8
%22 = icmp eq i8* null, %21
br i1 %22, label %23, label %24
23: ; preds = %2
store i8* null, i8** %3
br label %34
24: ; preds = %2
%25 = load i8*, i8** %8
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
%32 = call i32 @memcpy(i8* %28, i8* %29, i32 %31)
%33 = load i8*, i8** %8
store i8* %33, i8** %3
br label %34
34: ; preds = %24, %23
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
define i8* @String_Concat(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %4, 1
%6 = add i32 %5, %3
%7 = tail call i8* @realloc(i8* %0, i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = tail call i32 @memcpy(i8* %11, i8* %1, i32 %5)
br label %13
13: ; preds = %2, %9
ret i8* %7
}