char *add_strings(s1, s2)
char *s1, *s2;
{
  char *buf_start, *buf_cp;
  int len1, len2;
  len1 = strlen(s1);
  len2 = strlen(s2);
  buf_start = safe_malloc(len1 + len2 + 1);
  strcpy(buf_start, s1);
  buf_cp = buf_start + len1;
  strcpy(buf_cp, s2);
  return buf_start;
}


x86 assembly (clang, -O0):
<add_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
add    -0x28(%rbp),%edi
add    $0x1,%edi
mov    $0x0,%al
call   1040 <safe_malloc@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_strings>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r12,%rax,1),%edi
add    $0x1,%edi
xor    %eax,%eax
call   1040 <safe_malloc@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
movslq %r12d,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @add_strings(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%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 = trunc i64 %10 to i32
store i32 %11, i32* %7
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %8
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = add nsw i32 %15, %16
%18 = add nsw i32 %17, 1
%19 = call i32 (i32, ...) bitcast (i32 (...)* @safe_malloc to i32 (i32, ...)*)(i32 %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = call i8* @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = load i8*, i8** %4
%31 = call i8* @strcpy(i8* %29, i8* %30)
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
define i8* @add_strings(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = trunc i64 %5 to i32
%7 = add i32 %4, 1
%8 = add i32 %7, %6
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @safe_malloc to i32 (i32, ...)*)(i32 %8)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = tail call i8* @strcpy(i8* dereferenceable(1) %11, i8* dereferenceable(1) %0)
%13 = shl i64 %3, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = tail call i8* @strcpy(i8* dereferenceable(1) %15, i8* dereferenceable(1) %1)
ret i8* %11
}