#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(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
char *greeting(char const *suffix) {
  char *res = (char *)malloc(strlen("Hello World! ") + strlen(suffix) + 1);
  if (res == NULL)
    return NULL;
  res[0] = '\0';
  strcat(res, "Hello World! ");
  strcat(res, suffix);
  return res;
}


x86 assembly (clang, -O0):
<greeting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1181 <greeting+0x51>
movq   $0x0,-0x8(%rbp)
jmp    11ad <greeting+0x7d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<greeting>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0xe(%rax),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     116c <greeting+0x3c>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xea9(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
jmp    116e <greeting+0x3e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Hello World! \00"
define i8* @greeting(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i64 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %5, %7
%9 = add nsw i64 %8, 1
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i8* null, i8** %2
br label %24
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 0, i8* %17
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = load i8*, i8** %4
store i8* %23, i8** %2
br label %24
24: ; preds = %15, %14
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [14 x i8] c"Hello World! \00"
define i8* @greeting(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 14
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %10, label %7
7: ; preds = %1
store i8 0, i8* %5
%8 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strcat(i8* %5, i8* %0)
br label %10
10: ; preds = %1, %7
%11 = phi i8* [ %5, %7 ], [ null, %1 ]
ret i8* %11
}