#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 */
unsigned int Strings_Length(char *, unsigned int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
void Strings_Append(char *source_, unsigned int _source_high, char *destination,
                    unsigned int _destination_high) {
  unsigned int i;
  unsigned int j;
  unsigned int sh;
  unsigned int dh;
  char source[_source_high + 1];
  memcpy(source, source_, _source_high + 1);
  j = Strings_Length((char *)destination, _destination_high);
  dh = _destination_high;
  sh = Strings_Length((char *)source, _source_high);
  i = 0;
  while ((i < sh) && (j <= dh)) {
    destination[j] = source[i];
    i += 1;
    j += 1;
  }
  if (j <= dh) {
    destination[j] = (char)000;
  }
}


x86 assembly (clang, -O0):
<Strings_Append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <Strings_Length@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%esi
call   1040 <Strings_Length@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
cmp    -0x28(%rbp),%ecx
mov    %al,-0x49(%rbp)
jae    11b6 <Strings_Append+0x96>
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
setbe  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11c6 <Strings_Append+0xa6>
jmp    11f1 <Strings_Append+0xd1>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <Strings_Append+0x79>
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
ja     1208 <Strings_Append+0xe8>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strings_Append>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%rsi
lea    0x1(%r13),%edx
mov    %rsp,%r12
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
call   1030 <memcpy@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <Strings_Length@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %r13d,%esi
call   1040 <Strings_Length@plt>
cmp    %ebx,%r15d
setbe  %cl
test   %eax,%eax
je     11be <Strings_Append+0x9e>
cmp    %ebx,%r15d
ja     11be <Strings_Append+0x9e>
mov    %eax,%r8d
mov    %r15d,%edx
mov    $0x1,%eax
nopl   0x0(%rax,%rax,1)
mov    %rax,%rsi
lea    (%rdx,%rax,1),%edi
add    %edx,%eax
add    $0xffffffff,%eax
movzbl -0x1(%r12,%rsi,1),%ecx
mov    %cl,(%r14,%rax,1)
cmp    %ebx,%edi
setbe  %cl
lea    0x1(%rsi),%rax
cmp    %r8,%rsi
jae    11b7 <Strings_Append+0x97>
cmp    %ebx,%edi
jbe    1190 <Strings_Append+0x70>
add    %eax,%r15d
add    $0xffffffff,%r15d
test   %cl,%cl
je     11ca <Strings_Append+0xaa>
mov    %r15d,%eax
movb   $0x0,(%r14,%rax,1)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @Strings_Append(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%15 = load i32, i32* %6
%16 = add i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %13
%19 = alloca i8, i64 %17
store i64 %17, i64* %14
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = add i32 %21, 1
%23 = call i32 @memcpy(i8* %19, i8* %20, i32 %22)
%24 = load i8*, i8** %7
%25 = load i32, i32* %8
%26 = call i32 @Strings_Length(i8* %24, i32 %25)
store i32 %26, i32* %10
%27 = load i32, i32* %8
store i32 %27, i32* %12
%28 = load i32, i32* %6
%29 = call i32 @Strings_Length(i8* %19, i32 %28)
store i32 %29, i32* %11
store i32 0, i32* %9
br label %30
30: ; preds = %40, %4
%31 = load i32, i32* %9
%32 = load i32, i32* %11
%33 = icmp ult i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* %10
%36 = load i32, i32* %12
%37 = icmp ule i32 %35, %36
br label %38
38: ; preds = %34, %30
%39 = phi i1 [ false, %30 ], [ %37, %34 ]
br i1 %39, label %40, label %53
40: ; preds = %38
%41 = load i32, i32* %9
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %19, i64 %42
%44 = load i8, i8* %43
%45 = load i8*, i8** %7
%46 = load i32, i32* %10
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %44, i8* %48
%49 = load i32, i32* %9
%50 = add i32 %49, 1
store i32 %50, i32* %9
%51 = load i32, i32* %10
%52 = add i32 %51, 1
store i32 %52, i32* %10
br label %30
53: ; preds = %38
%54 = load i32, i32* %10
%55 = load i32, i32* %12
%56 = icmp ule i32 %54, %55
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = load i8*, i8** %7
%59 = load i32, i32* %10
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 0, i8* %61
br label %62
62: ; preds = %57, %53
%63 = load i8*, i8** %13
ret void
}

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