#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 */
typedef size_t uint8_t;

/* Variables and functions */
size_t stringLength(char *);
void stringAppend(char *string, char *appendage) {
  uint8_t i = 0;
  uint8_t j = stringLength(string);
  while (appendage[i] > 0) {
    string[j++] = appendage[i++];
  }
  string[j] = 0;
}


x86 assembly (clang, -O0):
<stringAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <stringLength@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jle    117b <stringAppend+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1135 <stringAppend+0x25>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringAppend>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <stringLength@plt>
mov    (%rbx),%cl
test   %cl,%cl
jle    1143 <stringAppend+0x33>
add    $0x1,%rbx
nopl   0x0(%rax)
mov    %cl,(%r14,%rax,1)
add    $0x1,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jg     1130 <stringAppend+0x20>
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @stringAppend(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @stringLength(i8* %0)
%4 = load i8, i8* %1
%5 = icmp sgt i8 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %2, %6
%7 = phi i8 [ %14, %6 ], [ %4, %2 ]
%8 = phi i64 [ %11, %6 ], [ %3, %2 ]
%9 = phi i64 [ %10, %6 ], [ 0, %2 ]
%10 = add i64 %9, 1
%11 = add i64 %8, 1
%12 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %7, i8* %12
%13 = getelementptr inbounds i8, i8* %1, i64 %10
%14 = load i8, i8* %13
%15 = icmp sgt i8 %14, 0
br i1 %15, label %6, label %16
16: ; preds = %6, %2
%17 = phi i64 [ %3, %2 ], [ %11, %6 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
ret void
}