void foo(char **x) {
  char *p = __builtin_malloc(64);
  char *q = __builtin_malloc(64);
  __builtin_strcat(q, "abcde");
  __builtin_strcat(p, "ab");
  p[1] = q[3];
  __builtin_strcat(p, q);
  x[0] = p;
  x[1] = q;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x40,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x40,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    0x3(%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x40,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0x40,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
movl   $0x64636261,(%rbx,%rax,1)
movw   $0x65,0x4(%rbx,%rax,1)
mov    %r15,%rdi
call   1030 <strlen@plt>
movw   $0x6261,(%r15,%rax,1)
movb   $0x0,0x2(%r15,%rax,1)
mov    0x3(%rbx),%al
mov    %al,0x1(%r15)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
mov    %r15,(%r14)
mov    %rbx,0x8(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"abcde\00"
@.str.1 = [3 x i8] c"ab\00"
define void @foo(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
store i8** %0, i8*** %2
%5 = call i8* @malloc(i64 64)
store i8* %5, i8** %3
%6 = call i8* @malloc(i64 64)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i8* @strcat(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = call i8* @strcat(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 3
%13 = load i8, i8* %12
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %13, i8* %15
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = call i8* @strcat(i8* %16, i8* %17)
%19 = load i8*, i8** %3
%20 = load i8**, i8*** %2
%21 = getelementptr inbounds i8*, i8** %20, i64 0
store i8* %19, i8** %21
%22 = load i8*, i8** %4
%23 = load i8**, i8*** %2
%24 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* %22, i8** %24
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"abcde\00"
@.str.1 = [3 x i8] c"ab\00"
define void @foo(i8** nocapture writeonly %0) {
%2 = tail call dereferenceable_or_null(64) i8* @malloc(i64 64)
%3 = tail call dereferenceable_or_null(64) i8* @malloc(i64 64)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = getelementptr i8, i8* %3, i64 %4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) %5, i8* align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 6, i1 false)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = getelementptr i8, i8* %2, i64 %6
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %7, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 3, i1 false)
%8 = getelementptr inbounds i8, i8* %3, i64 3
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %9, i8* %10
%11 = tail call i8* @strcat(i8* dereferenceable(1) %2, i8* dereferenceable(1) %3)
store i8* %2, i8** %0
%12 = getelementptr inbounds i8*, i8** %0, i64 1
store i8* %3, i8** %12
ret void
}