#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*/ memcpy(char *, char const *, int);
int strlen(char const *);
void exm_str_append(char *buf, const char *str) {
  if (!str)
    return;
  if (!*buf)
    memcpy(buf, str, strlen(str) + 1);
  else {
    size_t l1;
    l1 = strlen(buf);
    buf[l1] = ' ';
    memcpy(buf + l1 + 1, str, strlen(str) + 1);
  }
}


x86 assembly (clang, -O0):
<exm_str_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1140 <exm_str_append+0x20>
jmp    11cb <exm_str_append+0xab>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    117d <exm_str_append+0x5d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
jmp    11cb <exm_str_append+0xab>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exm_str_append>:
test   %rsi,%rsi
je     1166 <exm_str_append+0x46>
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1149 <exm_str_append+0x29>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x20,(%rbx,%rax,1)
add    %rax,%rbx
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <memcpy@plt>
ret

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

LLVM IR (-O2):
define void @exm_str_append(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 32, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 1
br label %12
12: ; preds = %4, %7
%13 = phi i8* [ %11, %7 ], [ %0, %4 ]
%14 = tail call i32 @strlen(i8* %1)
%15 = add nsw i32 %14, 1
%16 = tail call i32 @memcpy(i8* %13, i8* %1, i32 %15)
br label %17
17: ; preds = %12, %2
ret void
}