#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
char *string_append(const char *a, const char *b) {
  int size_a = strlen(a);
  int size_b = strlen(b);
  int combined_length = sizeof(char) * (size_a + size_b + 1);
  char *combined = malloc(combined_length);
  memset(combined, 0, combined_length);
  strcat(combined, a);
  strcat(combined, b);
  return combined;
}


x86 assembly (clang, -O0):
<string_append>:
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
cltq
shl    $0x0,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_append>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @string_append(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
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = load i32, i32* %7
%24 = call i32 @memset(i8* %22, i32 0, i32 %23)
%25 = load i8*, i8** %8
%26 = load i8*, i8** %3
%27 = call i32 @strcat(i8* %25, i8* %26)
%28 = load i8*, i8** %8
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %28, i8* %29)
%31 = load i8*, i8** %8
ret i8* %31
}

LLVM IR (-O2):
define i8* @string_append(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 @memset(i8* %7, i32 0, i32 %6)
%9 = tail call i32 @strcat(i8* %7, i8* %0)
%10 = tail call i32 @strcat(i8* %7, i8* %1)
ret i8* %7
}