#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(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *sappend(const char *left, const char *right, const int right_len) {
  size_t ls = strlen(left);
  size_t rs = (size_t)right_len;
  char *ss = (char *)malloc(ls + rs + 1);
  memcpy(ss, left, ls);
  memcpy(ss + ls, right, rs);
  ss[ls + rs] = '\0';
  return ss;
}


x86 assembly (clang, -O0):
<sappend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define i8* @sappend(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = sext i32 %2 to i64
%6 = add i64 %4, %5
%7 = add i64 %6, 1
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @memcpy(i8* %9, i8* %0, i64 %4)
%11 = getelementptr inbounds i8, i8* %9, i64 %4
%12 = tail call i32 @memcpy(i8* %11, i8* %1, i64 %5)
%13 = getelementptr inbounds i8, i8* %9, i64 %6
store i8 0, i8* %13
ret i8* %9
}