#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__ strlen(char *);
void appendString(char *appendTo, char *appendFrom) {
  int offset = (int)strlen(appendTo);
  int i = 0;
  while (i++ < offset && *appendFrom) {
    *(appendTo++ + offset) = *appendFrom++;
  }
  *(appendTo + offset) = '\0';
}


x86 assembly (clang, -O0):
<appendString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x19(%rbp)
jge    115c <appendString+0x4c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116c <appendString+0x5c>
jmp    1198 <appendString+0x88>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1133 <appendString+0x23>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appendString>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
movslq %eax,%rcx
test   %eax,%eax
jle    1148 <appendString+0x38>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%edx
test   %dl,%dl
je     1148 <appendString+0x38>
add    $0x1,%rbx
mov    %dl,(%r14,%rcx,1)
add    $0x1,%r14
add    $0xffffffff,%eax
jne    1130 <appendString+0x20>
movb   $0x0,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @appendString(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = icmp sgt i32 %4, 0
%6 = shl i64 %3, 32
%7 = ashr exact i64 %6, 32
br i1 %5, label %8, label %20
8: ; preds = %2, %14
%9 = phi i32 [ %18, %14 ], [ 1, %2 ]
%10 = phi i8* [ %16, %14 ], [ %0, %2 ]
%11 = phi i8* [ %15, %14 ], [ %1, %2 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = getelementptr inbounds i8, i8* %10, i64 %7
store i8 %12, i8* %17
%18 = add nuw i32 %9, 1
%19 = icmp eq i32 %9, %4
br i1 %19, label %20, label %8
20: ; preds = %8, %14, %2
%21 = phi i8* [ %0, %2 ], [ %16, %14 ], [ %10, %8 ]
%22 = getelementptr inbounds i8, i8* %21, i64 %7
store i8 0, i8* %22
ret void
}