#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*/ memcpy(char *, char *, int);
int strlen(char *);
char *addCharToString(char *s1, char c) {
  char *result = malloc(strlen(s1) + 1 + 1);
  memcpy(result, s1, strlen(s1));
  result[strlen(s1)] = c;
  result[strlen(s1) + 1] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<addCharToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x9(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addCharToString>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
mov    %r14b,0x0(%rbp,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%rbp,1)
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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