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


x86 assembly (clang, -O0):
<Strings_Replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x40(%rbp),%rdi
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%esi
call   1040 <Strings_Length@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <Strings_Length@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
cmp    -0x24(%rbp),%ecx
mov    %al,-0x41(%rbp)
jae    11b4 <Strings_Replace+0x94>
mov    -0x10(%rbp),%eax
cmp    -0x28(%rbp),%eax
setb   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11c4 <Strings_Replace+0xa4>
jmp    11ef <Strings_Replace+0xcf>
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1197 <Strings_Replace+0x77>
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1206 <Strings_Replace+0xe6>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strings_Replace>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %rcx,%r13
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rsi
lea    0x1(%r14),%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    %r12,%rdi
mov    %r14d,%esi
call   1040 <Strings_Length@plt>
mov    %eax,%r14d
mov    %r13,-0x38(%rbp)
mov    %r13,%rdi
mov    %r15d,-0x2c(%rbp)
mov    %r15d,%esi
call   1040 <Strings_Length@plt>
test   %r14d,%r14d
je     11f8 <Strings_Replace+0xd8>
mov    %eax,%r13d
cmp    %ebx,%eax
jbe    11f8 <Strings_Replace+0xd8>
mov    %r14,%rax
mov    %ebx,%r15d
mov    -0x38(%rbp),%rcx
lea    (%rcx,%r15,1),%rdi
add    $0xffffffff,%eax
not    %ebx
add    %r13d,%ebx
cmp    %eax,%ebx
cmovae %eax,%ebx
test   %eax,%eax
cmove  %eax,%ebx
add    $0x1,%rbx
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
mov    %r13d,%eax
mov    %r14d,%ecx
mov    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%rsi),%rdx
cmp    %rcx,%rsi
jae    11e4 <Strings_Replace+0xc4>
add    %r15,%rsi
cmp    %rax,%rsi
mov    %rdx,%rsi
jb     11d0 <Strings_Replace+0xb0>
lea    (%r15,%rdx,1),%ebx
add    $0xffffffff,%ebx
mov    -0x38(%rbp),%r14
mov    -0x2c(%rbp),%eax
cmp    %eax,%ebx
jb     1203 <Strings_Replace+0xe3>
jmp    120a <Strings_Replace+0xea>
mov    -0x2c(%rbp),%eax
mov    -0x38(%rbp),%r14
cmp    %eax,%ebx
jae    120a <Strings_Replace+0xea>
mov    %ebx,%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_Replace(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%16 = load i32, i32* %7
%17 = add i32 %16, 1
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %14
%20 = alloca i8, i64 %18
store i64 %18, i64* %15
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = add i32 %22, 1
%24 = call i32 @memcpy(i8* %20, i8* %21, i32 %23)
store i32 0, i32* %11
%25 = load i32, i32* %7
%26 = call i32 @Strings_Length(i8* %20, i32 %25)
store i32 %26, i32* %12
%27 = load i8*, i8** %9
%28 = load i32, i32* %10
%29 = call i32 @Strings_Length(i8* %27, i32 %28)
store i32 %29, i32* %13
br label %30
30: ; preds = %40, %5
%31 = load i32, i32* %11
%32 = load i32, i32* %12
%33 = icmp ult i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* %8
%36 = load i32, i32* %13
%37 = icmp ult 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* %11
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %20, i64 %42
%44 = load i8, i8* %43
%45 = load i8*, i8** %9
%46 = load i32, i32* %8
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %44, i8* %48
%49 = load i32, i32* %11
%50 = add i32 %49, 1
store i32 %50, i32* %11
%51 = load i32, i32* %8
%52 = add i32 %51, 1
store i32 %52, i32* %8
br label %30
53: ; preds = %38
%54 = load i32, i32* %8
%55 = load i32, i32* %10
%56 = icmp ult i32 %54, %55
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = load i8*, i8** %9
%59 = load i32, i32* %8
%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** %14
ret void
}

LLVM IR (-O2):
define void @Strings_Replace(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = add i32 %1, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = call i32 @memcpy(i8* %8, i8* %0, i32 %6)
%10 = call i32 @Strings_Length(i8* %8, i32 %1)
%11 = call i32 @Strings_Length(i8* %3, i32 %4)
%12 = icmp ne i32 %10, 0
%13 = icmp ugt i32 %11, %2
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %38
15: ; preds = %5
%16 = zext i32 %2 to i64
%17 = getelementptr i8, i8* %3, i64 %16
%18 = add i32 %10, -1
%19 = xor i32 %2, -1
%20 = add i32 %11, %19
%21 = icmp eq i32 %18, 0
%22 = call i32 @llvm.umin.i32(i32 %20, i32 %18)
%23 = select i1 %21, i32 0, i32 %22
%24 = zext i32 %23 to i64
%25 = add nuw nsw i64 %24, 1
%26 = zext i32 %11 to i64
%27 = zext i32 %10 to i64
br label %28
28: ; preds = %15, %28
%29 = phi i64 [ 0, %15 ], [ %31, %28 ]
%30 = phi i64 [ %16, %15 ], [ %32, %28 ]
%31 = add nuw nsw i64 %29, 1
%32 = add nuw nsw i64 %30, 1
%33 = icmp ult i64 %31, %27
%34 = icmp ult i64 %32, %26
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %28, label %36
36: ; preds = %28
%37 = trunc i64 %32 to i32
br label %38
38: ; preds = %36, %5
%39 = phi i32 [ %2, %5 ], [ %37, %36 ]
%40 = icmp ult i32 %39, %4
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = zext i32 %39 to i64
%43 = getelementptr inbounds i8, i8* %3, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %41, %38
ret void
}