#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 *strdup(char *);
size_t strlen(char *);
char *stringConcat(char *str1, char *str2) {
  char ret[strlen(str1) + strlen(str2)];
  int i, j;
  for (i = 0; i < strlen(str1); ++i)
    ret[i] = str1[i];
  for (j = 0; j < strlen(str2); ++j)
    ret[i + j] = str2[j];
  ret[strlen(str1) + strlen(str2)] = '\0';
  return strdup(ret);
}


x86 assembly (clang, -O0):
<stringConcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,%rdx
mov    %rcx,%rax
add    %rdx,%rax
mov    %rsp,%rsi
mov    %rsi,-0x18(%rbp)
lea    0xf(%rcx,%rdx,1),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jae    11c0 <stringConcat+0xa0>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117b <stringConcat+0x5b>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jae    1211 <stringConcat+0xf1>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x28(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c7 <stringConcat+0xa7>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
movb   $0x0,(%rdi,%rax,1)
call   1040 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringConcat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
add    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
test   %r12,%r12
je     1183 <stringConcat+0x53>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    %r12d,%edi
jmp    1185 <stringConcat+0x55>
xor    %edi,%edi
add    %r15,%r12
test   %r15,%r15
je     119b <stringConcat+0x6b>
add    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%rbx,%r12,1)
mov    %rbx,%rdi
call   1050 <strdup@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @stringConcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
%13 = add i64 %10, %12
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i8, i64 %13
store i64 %13, i64* %6
store i32 0, i32* %7
br label %16
16: ; preds = %31, %2
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = icmp ult i64 %18, %20
br i1 %21, label %22, label %34
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %15, i64 %29
store i8 %27, i8* %30
br label %31
31: ; preds = %22
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %16
34: ; preds = %16
store i32 0, i32* %8
br label %35
35: ; preds = %52, %34
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = load i8*, i8** %4
%39 = call i64 @strlen(i8* %38)
%40 = icmp ult i64 %37, %39
br i1 %40, label %41, label %55
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = add nsw i32 %47, %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %15, i64 %50
store i8 %46, i8* %51
br label %52
52: ; preds = %41
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %35
55: ; preds = %35
%56 = load i8*, i8** %3
%57 = call i64 @strlen(i8* %56)
%58 = load i8*, i8** %4
%59 = call i64 @strlen(i8* %58)
%60 = add i64 %57, %59
%61 = getelementptr inbounds i8, i8* %15, i64 %60
store i8 0, i8* %61
%62 = call i8* @strdup(i8* %15)
%63 = load i8*, i8** %5
ret i8* %62
}

LLVM IR (-O2):
define noalias i8* @stringConcat(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %4, %3
%6 = alloca i8, i64 %5
%7 = icmp eq i64 %3, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = and i64 %3, 4294967295
br label %10
10: ; preds = %8, %2
%11 = phi i64 [ 0, %2 ], [ %9, %8 ]
%12 = icmp eq i64 %4, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = getelementptr i8, i8* %6, i64 %11
br label %15
15: ; preds = %13, %10
%16 = getelementptr inbounds i8, i8* %6, i64 %5
store i8 0, i8* %16
%17 = call i8* @strdup(i8* %6)
ret i8* %17
}