#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 strlen(char const *);
int /*<<< orphan*/ syserr(char *, char *, char *);
char *strconc(const char *s1, const char *s2) {
  int n1, n2, nreq;
  char *result;
  n1 = strlen(s1);
  n2 = strlen(s2);
  nreq = n1 + n2 + 1;
  result = (char *)malloc(sizeof(char) * nreq);
  if (!result)
    syserr("strconc", "new char []", "space for string");
  memcpy(&result[0], s1, n1);
  memcpy(&result[n1], s2, n2);
  result[n1 + n2] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<strconc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ac <strconc+0x6c>
lea    0xe67(%rip),%rdi
lea    0xe68(%rip),%rsi
lea    0xe6d(%rip),%rdx
call   1040 <syserr@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strconc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %eax,%ebp
add    %r13d,%ebp
lea    (%r12,%r13,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1197 <strconc+0x57>
lea    0xe7c(%rip),%rdi
lea    0xe7d(%rip),%rsi
lea    0xe82(%rip),%rdx
call   1040 <syserr@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1050 <memcpy@plt>
movslq %r13d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"strconc\00"
@.str.1 = [12 x i8] c"new char []\00"
@.str.2 = [17 x i8] c"space for string\00"
define i8* @strconc(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = add nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @syserr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = tail call i32 @memcpy(i8* %8, i8* %0, i32 %3)
%14 = sext i32 %3 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
%16 = tail call i32 @memcpy(i8* %15, i8* %1, i32 %4)
%17 = sext i32 %5 to i64
%18 = getelementptr inbounds i8, i8* %8, i64 %17
store i8 0, i8* %18
ret i8* %8
}