#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 *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void str_append_start(char *orig, char *new) {
  char temp[255 + 1];
  int lo = strlen(orig), ln = strlen(new);
  if (ln + lo > 255)
    return;
  memcpy(temp, new, ln);
  memcpy(temp + ln, orig, lo);
  temp[lo + ln] = '\0';
  strcpy(orig, temp);
}


x86 assembly (clang, -O0):
<str_append_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x114(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x118(%rbp)
mov    -0x118(%rbp),%eax
add    -0x114(%rbp),%eax
cmp    $0xff,%eax
jle    117d <str_append_start+0x4d>
jmp    11d9 <str_append_start+0xa9>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x118(%rbp),%edx
call   1050 <memcpy@plt>
lea    -0x110(%rbp),%rdi
movslq -0x118(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x114(%rbp),%eax
add    -0x118(%rbp),%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_append_start>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    (%rbx,%r15,1),%ebp
cmp    $0xff,%ebp
jg     1199 <str_append_start+0x69>
mov    %rsp,%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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