#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
char *concatestrings(char *s1, char *s2) {
  char *result = malloc(strlen(s1) + strlen(s2) + 1);
  memcpy(result, s1, strlen(s1));
  memcpy(result + strlen(s1), s2, strlen(s2) + 1);
  result[strlen(s1) + strlen(s2) + 1] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<concatestrings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x54(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
mov    -0x20(%rbp),%rax
add    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concatestrings>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %r15,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
cltq
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @concatestrings(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %7, %9
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @memcpy(i8* %13, i8* %14, i32 %16)
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8*, i8** %4
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %25, 1
%27 = call i32 @memcpy(i8* %22, i8* %23, i32 %26)
%28 = load i8*, i8** %5
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %30, %32
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %28, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
define i8* @concatestrings(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %3, 1
%6 = add i32 %5, %4
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i32 @memcpy(i8* %7, i8* %0, i32 %8)
%10 = tail call i32 @strlen(i8* %0)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = tail call i32 @strlen(i8* %1)
%14 = add nsw i32 %13, 1
%15 = tail call i32 @memcpy(i8* %12, i8* %1, i32 %14)
%16 = tail call i32 @strlen(i8* %0)
%17 = tail call i32 @strlen(i8* %1)
%18 = add i32 %16, 1
%19 = add i32 %18, %17
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %7, i64 %20
store i8 0, i8* %21
ret i8* %7
}