#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 */
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
scalar_t__ yh_c_buffer_malloc(int);
char *test_hello(const char *name) {
  const char *hello = " -> hello";
  char *result = (char *)yh_c_buffer_malloc(
      sizeof(char) * (strlen(name) + strlen(hello)) + 1);
  strcpy(result, name);
  strcat(result, hello);
  return result;
}


x86 assembly (clang, -O0):
<test_hello>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <yh_c_buffer_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_hello>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xea6(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x1,%edi
call   1050 <yh_c_buffer_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c" -> hello\00"
define i8* @test_hello(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %6, %8
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = add i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @yh_c_buffer_malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i8*, i8** %2
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %4
%20 = load i8*, i8** %3
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %4
ret i8* %22
}

LLVM IR (-O2):
@.str = [10 x i8] c" -> hello\00"
define i8* @test_hello(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = add i32 %2, 1
%5 = add i32 %4, %3
%6 = tail call i64 @yh_c_buffer_malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @strcpy(i8* %7, i8* %0)
%9 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
ret i8* %7
}