#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 int /*<<< orphan*/ updatedString;
typedef int /*<<< orphan*/ offsetArrInd;

/* Variables and functions */
int checkOccurrences(char *, char *);
int isInOrigString(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int stringLength(char *);
int strlen(char *);
void replace(char replace[], char replacement[], char stringOrig[]) {
  char updatedString[32];
  int size = sizeof(updatedString);
  for (int i = 0; i < size; i++) {
    updatedString[i] = '\0';
  }
  char offsetArrInd[8];
  int sizeArrInd = sizeof(offsetArrInd);
  int replaceLength = strlen(replace);
  int replacementLength = strlen(replacement);
  int origLength = strlen(stringOrig);
  if (replaceLength > origLength) {
    printf(
        "Expected [Argv1] length of %d to be less than [Argv3] length of %d \n",
        replaceLength, origLength);
  } else if (origLength > size) {
    printf("Expected [Argv3] length of %d to be less than array size of %d \n",
           origLength, size);
  } else {
    int offset = 0;
    int index = 0;
    int offsetIndex = 0;
    printf("ORIGINAL = ");
    for (int i = 0; i < origLength; i++) {
      printf("%c", stringOrig[i]);
    }
    printf("\n");
    printf("REPLACE = ");
    for (int i = 0; i < replaceLength; i++) {
      printf("%c", replace[i]);
    }
    printf("\n");
    printf("REPLACEMENT = ");
    for (int i = 0; i < replacementLength; i++) {
      printf("%c", replacement[i]);
    }
    printf("\n\n");
    bool isContained = isInOrigString(replace, stringOrig);
    printf("isContained = %s \n", isContained ? "TRUE" : "FALSE");
    int occurrences = checkOccurrences(replace, stringOrig);
    printf("occurrences = %d \n", occurrences);
    int numOccurrences = 0;
    while (offset <= (origLength - replaceLength)) {
      for (int i = 0; i < replaceLength; i++) {
        if (replace[i] == stringOrig[i + offset]) {
          index++;
        } else {
          index = 0;
        }
      }
      if (replaceLength == index) {
        printf("replacementLength = %d \n", replacementLength);
        if (offsetIndex == 0) {
          offsetArrInd[offsetIndex] = offset;
        } else {
          if (numOccurrences < occurrences) {
            if (replaceLength == 2) {
              numOccurrences++;
              offsetArrInd[offsetIndex] =
                  offset + (replacementLength - 1) - numOccurrences;
            } else {
              numOccurrences++;
              offsetArrInd[offsetIndex] = offset + (replacementLength - 1) -
                                          (numOccurrences + replaceLength - 2);
            }
          }
        }
        offsetIndex++;
      }
      offset++;
    }
    int updatedIndex = 0;
    int origIndex = 0;
    while (updatedIndex < size) {
      for (int i = 0; i < sizeArrInd; i++) {
        if (offsetArrInd[i] == updatedIndex) {
          for (int j = 0; j < replacementLength; j++) {
            updatedString[updatedIndex] = replacement[j];
            updatedIndex++;
          }
          for (int j = 0; j < replaceLength; j++) {
            origIndex++;
          }
        }
      }
      updatedString[updatedIndex] = stringOrig[origIndex];
      updatedIndex++;
      origIndex++;
    }
    printf("\n");
    printf("OFFIND = ");
    for (int i = 0; i < offsetIndex; i++) {
      printf("%d ", offsetArrInd[i]);
    }
    int updatedLength = stringLength(updatedString);
    printf("\n");
    printf("UPDATED = ");
    for (int i = 0; i < updatedLength; i++) {
      printf("%c", updatedString[i]);
    }
  }
}


x86 assembly (clang, -O0):
<replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x20,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1198 <replace+0x48>
movslq -0x48(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1175 <replace+0x25>
movl   $0x8,-0x54(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x60(%rbp),%eax
jle    11e8 <replace+0x98>
mov    -0x58(%rbp),%esi
mov    -0x60(%rbp),%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1700 <replace+0x5b0>
mov    -0x60(%rbp),%eax
cmp    -0x44(%rbp),%eax
jle    120d <replace+0xbd>
mov    -0x60(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    16fb <replace+0x5ab>
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x70(%rbp)
mov    -0x70(%rbp),%eax
cmp    -0x60(%rbp),%eax
jge    126b <replace+0x11b>
mov    -0x18(%rbp),%rax
movslq -0x70(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    1237 <replace+0xe7>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    12c2 <replace+0x172>
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    128e <replace+0x13e>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jge    1319 <replace+0x1c9>
mov    -0x10(%rbp),%rax
movslq -0x78(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    12e5 <replace+0x195>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <isInOrigString@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%ecx
lea    0xd89(%rip),%rsi
lea    0xd7d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <checkOccurrences@plt>
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x60(%rbp),%ecx
sub    -0x58(%rbp),%ecx
cmp    %ecx,%eax
jg     14df <replace+0x38f>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    140b <replace+0x2bb>
mov    -0x8(%rbp),%rax
movslq -0x88(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x88(%rbp),%edx
add    -0x64(%rbp),%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    13eb <replace+0x29b>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    13f2 <replace+0x2a2>
movl   $0x0,-0x68(%rbp)
jmp    13f7 <replace+0x2a7>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    13a3 <replace+0x253>
mov    -0x58(%rbp),%eax
cmp    -0x68(%rbp),%eax
jne    14d1 <replace+0x381>
mov    -0x5c(%rbp),%esi
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x6c(%rbp)
jne    1444 <replace+0x2f4>
mov    -0x64(%rbp),%eax
mov    %al,%cl
movslq -0x6c(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
jmp    14c8 <replace+0x378>
mov    -0x84(%rbp),%eax
cmp    -0x80(%rbp),%eax
jge    14c3 <replace+0x373>
cmpl   $0x2,-0x58(%rbp)
jne    148c <replace+0x33c>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
add    %ecx,%eax
sub    -0x84(%rbp),%eax
mov    %al,%cl
movslq -0x6c(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
jmp    14be <replace+0x36e>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
add    %ecx,%eax
mov    -0x84(%rbp),%ecx
add    -0x58(%rbp),%ecx
sub    $0x2,%ecx
sub    %ecx,%eax
mov    %al,%cl
movslq -0x6c(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
jmp    14c3 <replace+0x373>
jmp    14c8 <replace+0x378>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1388 <replace+0x238>
movl   $0x0,-0x8c(%rbp)
movl   $0x0,-0x90(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    161e <replace+0x4ce>
movl   $0x0,-0x94(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    15e2 <replace+0x492>
movslq -0x94(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    -0x8c(%rbp),%eax
jne    15c9 <replace+0x479>
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jge    1588 <replace+0x438>
mov    -0x10(%rbp),%rax
movslq -0x98(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x8c(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    153d <replace+0x3ed>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    15c4 <replace+0x474>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1592 <replace+0x442>
jmp    15c9 <replace+0x479>
jmp    15ce <replace+0x47e>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    150c <replace+0x3bc>
mov    -0x18(%rbp),%rax
movslq -0x90(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x8c(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    14f3 <replace+0x3a3>
lea    0xa8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xac9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    1681 <replace+0x531>
movslq -0xa0(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%esi
lea    0xaa0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    1644 <replace+0x4f4>
lea    -0x40(%rbp),%rdi
call   1070 <stringLength@plt>
mov    %eax,-0xa4(%rbp)
lea    0xa19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xa65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
cmp    -0xa4(%rbp),%eax
jge    16f6 <replace+0x5a6>
movslq -0xa8(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%esi
lea    0x9b7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
jmp    16b6 <replace+0x566>
jmp    16fb <replace+0x5ab>
jmp    1700 <replace+0x5b0>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %rax,0x28(%rsp)
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%edx
cmp    %r13d,%eax
jge    11d7 <replace+0x57>
lea    0xe2e(%rip),%rdi
mov    %r13d,%esi
jmp    11ea <replace+0x6a>
cmp    $0x21,%edx
jl     1202 <replace+0x82>
lea    0xe62(%rip),%rdi
mov    %edx,%esi
mov    $0x20,%edx
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <printf@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
mov    %rdx,%rbx
call   1070 <printf@plt>
mov    %rbx,0x8(%rsp)
test   %ebx,%ebx
jle    1243 <replace+0xc3>
mov    0x8(%rsp),%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r15,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1230 <replace+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%r14d
test   %r13d,%r13d
jle    1283 <replace+0x103>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x0(%rbp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1270 <replace+0xf0>
mov    %r14,0x38(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x28(%rsp),%rax
mov    %eax,%r14d
test   %eax,%eax
jle    12c3 <replace+0x143>
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl (%r12,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    12b0 <replace+0x130>
mov    %r14,0x18(%rsp)
mov    %r12,0x80(%rsp)
lea    0xe1d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <isInOrigString@plt>
test   %eax,%eax
lea    0xdd4(%rip),%rax
lea    0xdc8(%rip),%rsi
cmove  %rax,%rsi
lea    0xdaa(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    %r15,0x48(%rsp)
mov    %r15,%rsi
call   1090 <checkOccurrences@plt>
lea    0xdaa(%rip),%rdi
mov    %eax,0x24(%rsp)
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,0x14(%rsp)
mov    0x8(%rsp),%r8
sub    %r13d,%r8d
mov    $0x0,%r12d
jge    1645 <replace+0x4c5>
mov    %r12d,0x44(%rsp)
xor    %r14d,%r14d
mov    0x14(%rsp),%r13d
test   %r13d,%r13d
mov    0x20(%rsp),%al
mov    %al,(%rsp)
movsbl %al,%eax
mov    %eax,0x38(%rsp)
movsbl 0x1(%rsp),%eax
mov    %eax,0x8(%rsp)
movsbl 0x2(%rsp),%eax
mov    %eax,0x30(%rsp)
movsbl 0x3(%rsp),%eax
mov    %eax,0x24(%rsp)
movsbl 0x4(%rsp),%eax
mov    %eax,0x20(%rsp)
movsbl 0x5(%rsp),%eax
mov    %eax,0x50(%rsp)
movsbl 0x6(%rsp),%eax
mov    %eax,0x5c(%rsp)
movsbl 0x7(%rsp),%eax
mov    %eax,0x58(%rsp)
cmovs  %r14d,%r13d
xor    %ebp,%ebp
mov    0x48(%rsp),%r15
mov    0x80(%rsp),%r12
mov    0x28(%rsp),%rbx
jmp    13e2 <replace+0x262>
nopl   (%rax)
add    %r13d,%r14d
movslq %r14d,%r14
movzbl (%r15,%r14,1),%eax
movslq %ebp,%rcx
mov    %al,0x60(%rsp,%rcx,1)
lea    0x1(%rcx),%ebp
add    $0x1,%r14d
cmp    $0x1f,%ecx
jge    1580 <replace+0x400>
cmp    0x38(%rsp),%ebp
je     1430 <replace+0x2b0>
cmp    0x8(%rsp),%ebp
je     1457 <replace+0x2d7>
cmp    0x30(%rsp),%ebp
je     1482 <replace+0x302>
cmp    0x24(%rsp),%ebp
je     14ad <replace+0x32d>
cmp    0x20(%rsp),%ebp
je     14d8 <replace+0x358>
cmp    0x50(%rsp),%ebp
je     1503 <replace+0x383>
cmp    0x5c(%rsp),%ebp
je     152e <replace+0x3ae>
cmp    0x58(%rsp),%ebp
jne    13c3 <replace+0x243>
jmp    1559 <replace+0x3d9>
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
jle    144e <replace+0x2ce>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
add    %r13d,%r14d
cmp    0x8(%rsp),%ebp
jne    13ee <replace+0x26e>
test   %ebx,%ebx
jle    1475 <replace+0x2f5>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
add    %r13d,%r14d
cmp    0x30(%rsp),%ebp
jne    13f8 <replace+0x278>
test   %ebx,%ebx
jle    14a0 <replace+0x320>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
add    %r13d,%r14d
cmp    0x24(%rsp),%ebp
jne    1402 <replace+0x282>
test   %ebx,%ebx
jle    14cb <replace+0x34b>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
add    %r13d,%r14d
cmp    0x20(%rsp),%ebp
jne    140c <replace+0x28c>
test   %ebx,%ebx
jle    14f6 <replace+0x376>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
add    %r13d,%r14d
cmp    0x50(%rsp),%ebp
jne    1416 <replace+0x296>
test   %ebx,%ebx
jle    1521 <replace+0x3a1>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
add    %r13d,%r14d
cmp    0x5c(%rsp),%ebp
jne    1420 <replace+0x2a0>
test   %ebx,%ebx
jle    154c <replace+0x3cc>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
add    %r13d,%r14d
cmp    0x58(%rsp),%ebp
jne    13c3 <replace+0x243>
test   %ebx,%ebx
jle    13c0 <replace+0x240>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
call   1080 <memcpy@plt>
add    %ebx,%ebp
jmp    13c0 <replace+0x240>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xb65(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x44(%rsp)
jle    15e7 <replace+0x467>
lea    0xb5a(%rip),%rdi
mov    0x38(%rsp),%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x44(%rsp),%eax
cmp    $0x1,%eax
je     15e7 <replace+0x467>
mov    %eax,%ebp
mov    $0x1,%ebx
lea    0xb38(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    15d0 <replace+0x450>
lea    0x60(%rsp),%rdi
call   10a0 <stringLength@plt>
mov    %eax,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xb00(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebx,%ebx
jle    1633 <replace+0x4b3>
mov    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x60(%rsp,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1620 <replace+0x4a0>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x28(%rsp),%rax
add    $0xff,%eax
mov    %rax,0x50(%rsp)
add    $0x1,%r8d
mov    0x38(%rsp),%r14
and    $0xfffffffe,%r14d
mov    0x48(%rsp),%rax
lea    0x1(%rax),%r15
xor    %edi,%edi
mov    $0x1,%esi
xor    %ebx,%ebx
xor    %eax,%eax
mov    %rax,0x30(%rsp)
xor    %r13d,%r13d
xor    %r12d,%r12d
mov    %r8,0x8(%rsp)
jmp    16ae <replace+0x52e>
mov    %ebx,%eax
mov    %bl,0x20(%rsp)
mov    0x8(%rsp),%r8
xor    %edi,%edi
mov    $0x1,%esi
add    $0x1,%r12d
add    $0x1,%rbx
add    $0x1,%r15
cmp    %r8,%rbx
je     1346 <replace+0x1c6>
mov    0x14(%rsp),%eax
test   %eax,%eax
jle    1716 <replace+0x596>
cmp    $0x1,%eax
jne    16c0 <replace+0x540>
xor    %eax,%eax
jmp    16f8 <replace+0x578>
nop
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x0(%rbp,%rax,1),%ecx
movzbl 0x1(%rbp,%rax,1),%edx
add    $0x2,%r13d
cmp    -0x1(%r15,%rax,1),%cl
cmovne %esi,%r13d
cmp    (%r15,%rax,1),%dl
cmovne %edi,%r13d
add    $0x2,%rax
cmp    %rax,%r14
jne    16d0 <replace+0x550>
testb  $0x1,0x38(%rsp)
je     1716 <replace+0x596>
mov    0x0(%rbp,%rax,1),%cl
add    %rbx,%rax
add    $0x1,%r13d
mov    0x48(%rsp),%rdx
cmp    (%rdx,%rax,1),%cl
cmovne %edi,%r13d
cmp    %r13d,0x14(%rsp)
jne    169d <replace+0x51d>
lea    0x9b9(%rip),%rdi
mov    0x28(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r12d,%r12d
je     1687 <replace+0x507>
mov    0x30(%rsp),%rsi
cmp    0x24(%rsp),%esi
jge    168d <replace+0x50d>
lea    0x1(%rsi),%eax
mov    0x14(%rsp),%edx
cmp    $0x2,%edx
jne    1768 <replace+0x5e8>
mov    0x50(%rsp),%rcx
add    %ebx,%ecx
not    %esi
add    %ecx,%esi
movslq %r12d,%rcx
mov    %sil,(%rsp,%rcx,1)
jmp    177e <replace+0x5fe>
not    %esi
mov    0x28(%rsp),%rcx
add    %ebx,%ecx
sub    %edx,%ecx
add    %esi,%ecx
add    $0x1,%cl
movslq %r12d,%rdx
mov    %cl,(%rsp,%rdx,1)
mov    %rax,0x30(%rsp)
jmp    168d <replace+0x50d>

LLVM IR (-O0):
@.str = [69 x i8] c"Expected [Argv1] length of %d to be less than [Argv3] length of %d \0A\00"
@.str.1 = [65 x i8] c"Expected [Argv3] length of %d to be less than array size of %d \0A\00"
@.str.2 = [12 x i8] c"ORIGINAL = \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [11 x i8] c"REPLACE = \00"
@.str.6 = [15 x i8] c"REPLACEMENT = \00"
@.str.7 = [3 x i8] c"\0A\0A\00"
@.str.8 = [19 x i8] c"isContained = %s \0A\00"
@.str.9 = [5 x i8] c"TRUE\00"
@.str.10 = [6 x i8] c"FALSE\00"
@.str.11 = [19 x i8] c"occurrences = %d \0A\00"
@.str.12 = [25 x i8] c"replacementLength = %d \0A\00"
@.str.13 = [10 x i8] c"OFFIND = \00"
@.str.14 = [4 x i8] c"%d \00"
@.str.15 = [11 x i8] c"UPDATED = \00"
define void @replace(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [32 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca [8 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 32, i32* %8
store i32 0, i32* %9
br label %33
33: ; preds = %41, %3
%34 = load i32, i32* %9
%35 = load i32, i32* %8
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %37
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %33
44: ; preds = %33
store i32 8, i32* %11
%45 = load i8*, i8** %4
%46 = call i32 @strlen(i8* %45)
store i32 %46, i32* %12
%47 = load i8*, i8** %5
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %13
%49 = load i8*, i8** %6
%50 = call i32 @strlen(i8* %49)
store i32 %50, i32* %14
%51 = load i32, i32* %12
%52 = load i32, i32* %14
%53 = icmp sgt i32 %51, %52
br i1 %53, label %54, label %58
54: ; preds = %44
%55 = load i32, i32* %12
%56 = load i32, i32* %14
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %55, i32 %56)
br label %332
58: ; preds = %44
%59 = load i32, i32* %14
%60 = load i32, i32* %8
%61 = icmp sgt i32 %59, %60
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = load i32, i32* %14
%64 = load i32, i32* %8
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %63, i32 %64)
br label %331
66: ; preds = %58
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %18
br label %68
68: ; preds = %80, %66
%69 = load i32, i32* %18
%70 = load i32, i32* %14
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %83
72: ; preds = %68
%73 = load i8*, i8** %6
%74 = load i32, i32* %18
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %72
%81 = load i32, i32* %18
%82 = add nsw i32 %81, 1
store i32 %82, i32* %18
br label %68
83: ; preds = %68
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %19
br label %86
86: ; preds = %98, %83
%87 = load i32, i32* %19
%88 = load i32, i32* %12
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %101
90: ; preds = %86
%91 = load i8*, i8** %4
%92 = load i32, i32* %19
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %91, i64 %93
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %96)
br label %98
98: ; preds = %90
%99 = load i32, i32* %19
%100 = add nsw i32 %99, 1
store i32 %100, i32* %19
br label %86
101: ; preds = %86
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %20
br label %104
104: ; preds = %116, %101
%105 = load i32, i32* %20
%106 = load i32, i32* %13
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %119
108: ; preds = %104
%109 = load i8*, i8** %5
%110 = load i32, i32* %20
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %109, i64 %111
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %114)
br label %116
116: ; preds = %108
%117 = load i32, i32* %20
%118 = add nsw i32 %117, 1
store i32 %118, i32* %20
br label %104
119: ; preds = %104
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%121 = load i8*, i8** %4
%122 = load i8*, i8** %6
%123 = call i32 @isInOrigString(i8* %121, i8* %122)
store i32 %123, i32* %21
%124 = load i32, i32* %21
%125 = icmp ne i32 %124, 0
%126 = zext i1 %125 to i64
%127 = select i1 %125, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0)
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %127)
%129 = load i8*, i8** %4
%130 = load i8*, i8** %6
%131 = call i32 @checkOccurrences(i8* %129, i8* %130)
store i32 %131, i32* %22
%132 = load i32, i32* %22
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %132)
store i32 0, i32* %23
br label %134
134: ; preds = %225, %119
%135 = load i32, i32* %15
%136 = load i32, i32* %14
%137 = load i32, i32* %12
%138 = sub nsw i32 %136, %137
%139 = icmp sle i32 %135, %138
br i1 %139, label %140, label %228
140: ; preds = %134
store i32 0, i32* %24
br label %141
141: ; preds = %166, %140
%142 = load i32, i32* %24
%143 = load i32, i32* %12
%144 = icmp slt i32 %142, %143
br i1 %144, label %145, label %169
145: ; preds = %141
%146 = load i8*, i8** %4
%147 = load i32, i32* %24
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds i8, i8* %146, i64 %148
%150 = load i8, i8* %149
%151 = sext i8 %150 to i32
%152 = load i8*, i8** %6
%153 = load i32, i32* %24
%154 = load i32, i32* %15
%155 = add nsw i32 %153, %154
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i8, i8* %152, i64 %156
%158 = load i8, i8* %157
%159 = sext i8 %158 to i32
%160 = icmp eq i32 %151, %159
br i1 %160, label %161, label %164
161: ; preds = %145
%162 = load i32, i32* %16
%163 = add nsw i32 %162, 1
store i32 %163, i32* %16
br label %165
164: ; preds = %145
store i32 0, i32* %16
br label %165
165: ; preds = %164, %161
br label %166
166: ; preds = %165
%167 = load i32, i32* %24
%168 = add nsw i32 %167, 1
store i32 %168, i32* %24
br label %141
169: ; preds = %141
%170 = load i32, i32* %12
%171 = load i32, i32* %16
%172 = icmp eq i32 %170, %171
br i1 %172, label %173, label %225
173: ; preds = %169
%174 = load i32, i32* %13
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 %174)
%176 = load i32, i32* %17
%177 = icmp eq i32 %176, 0
br i1 %177, label %178, label %184
178: ; preds = %173
%179 = load i32, i32* %15
%180 = trunc i32 %179 to i8
%181 = load i32, i32* %17
%182 = sext i32 %181 to i64
%183 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %182
store i8 %180, i8* %183
br label %222
184: ; preds = %173
%185 = load i32, i32* %23
%186 = load i32, i32* %22
%187 = icmp slt i32 %185, %186
br i1 %187, label %188, label %221
188: ; preds = %184
%189 = load i32, i32* %12
%190 = icmp eq i32 %189, 2
br i1 %190, label %191, label %204
191: ; preds = %188
%192 = load i32, i32* %23
%193 = add nsw i32 %192, 1
store i32 %193, i32* %23
%194 = load i32, i32* %15
%195 = load i32, i32* %13
%196 = sub nsw i32 %195, 1
%197 = add nsw i32 %194, %196
%198 = load i32, i32* %23
%199 = sub nsw i32 %197, %198
%200 = trunc i32 %199 to i8
%201 = load i32, i32* %17
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %202
store i8 %200, i8* %203
br label %220
204: ; preds = %188
%205 = load i32, i32* %23
%206 = add nsw i32 %205, 1
store i32 %206, i32* %23
%207 = load i32, i32* %15
%208 = load i32, i32* %13
%209 = sub nsw i32 %208, 1
%210 = add nsw i32 %207, %209
%211 = load i32, i32* %23
%212 = load i32, i32* %12
%213 = add nsw i32 %211, %212
%214 = sub nsw i32 %213, 2
%215 = sub nsw i32 %210, %214
%216 = trunc i32 %215 to i8
%217 = load i32, i32* %17
%218 = sext i32 %217 to i64
%219 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %218
store i8 %216, i8* %219
br label %220
220: ; preds = %204, %191
br label %221
221: ; preds = %220, %184
br label %222
222: ; preds = %221, %178
%223 = load i32, i32* %17
%224 = add nsw i32 %223, 1
store i32 %224, i32* %17
br label %225
225: ; preds = %222, %169
%226 = load i32, i32* %15
%227 = add nsw i32 %226, 1
store i32 %227, i32* %15
br label %134
228: ; preds = %134
store i32 0, i32* %25
store i32 0, i32* %26
br label %229
229: ; preds = %281, %228
%230 = load i32, i32* %25
%231 = load i32, i32* %8
%232 = icmp slt i32 %230, %231
br i1 %232, label %233, label %294
233: ; preds = %229
store i32 0, i32* %27
br label %234
234: ; preds = %278, %233
%235 = load i32, i32* %27
%236 = load i32, i32* %11
%237 = icmp slt i32 %235, %236
br i1 %237, label %238, label %281
238: ; preds = %234
%239 = load i32, i32* %27
%240 = sext i32 %239 to i64
%241 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %240
%242 = load i8, i8* %241
%243 = sext i8 %242 to i32
%244 = load i32, i32* %25
%245 = icmp eq i32 %243, %244
br i1 %245, label %246, label %277
246: ; preds = %238
store i32 0, i32* %28
br label %247
247: ; preds = %262, %246
%248 = load i32, i32* %28
%249 = load i32, i32* %13
%250 = icmp slt i32 %248, %249
br i1 %250, label %251, label %265
251: ; preds = %247
%252 = load i8*, i8** %5
%253 = load i32, i32* %28
%254 = sext i32 %253 to i64
%255 = getelementptr inbounds i8, i8* %252, i64 %254
%256 = load i8, i8* %255
%257 = load i32, i32* %25
%258 = sext i32 %257 to i64
%259 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %258
store i8 %256, i8* %259
%260 = load i32, i32* %25
%261 = add nsw i32 %260, 1
store i32 %261, i32* %25
br label %262
262: ; preds = %251
%263 = load i32, i32* %28
%264 = add nsw i32 %263, 1
store i32 %264, i32* %28
br label %247
265: ; preds = %247
store i32 0, i32* %29
br label %266
266: ; preds = %273, %265
%267 = load i32, i32* %29
%268 = load i32, i32* %12
%269 = icmp slt i32 %267, %268
br i1 %269, label %270, label %276
270: ; preds = %266
%271 = load i32, i32* %26
%272 = add nsw i32 %271, 1
store i32 %272, i32* %26
br label %273
273: ; preds = %270
%274 = load i32, i32* %29
%275 = add nsw i32 %274, 1
store i32 %275, i32* %29
br label %266
276: ; preds = %266
br label %277
277: ; preds = %276, %238
br label %278
278: ; preds = %277
%279 = load i32, i32* %27
%280 = add nsw i32 %279, 1
store i32 %280, i32* %27
br label %234
281: ; preds = %234
%282 = load i8*, i8** %6
%283 = load i32, i32* %26
%284 = sext i32 %283 to i64
%285 = getelementptr inbounds i8, i8* %282, i64 %284
%286 = load i8, i8* %285
%287 = load i32, i32* %25
%288 = sext i32 %287 to i64
%289 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %288
store i8 %286, i8* %289
%290 = load i32, i32* %25
%291 = add nsw i32 %290, 1
store i32 %291, i32* %25
%292 = load i32, i32* %26
%293 = add nsw i32 %292, 1
store i32 %293, i32* %26
br label %229
294: ; preds = %229
%295 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%296 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %30
br label %297
297: ; preds = %308, %294
%298 = load i32, i32* %30
%299 = load i32, i32* %17
%300 = icmp slt i32 %298, %299
br i1 %300, label %301, label %311
301: ; preds = %297
%302 = load i32, i32* %30
%303 = sext i32 %302 to i64
%304 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %303
%305 = load i8, i8* %304
%306 = sext i8 %305 to i32
%307 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 %306)
br label %308
308: ; preds = %301
%309 = load i32, i32* %30
%310 = add nsw i32 %309, 1
store i32 %310, i32* %30
br label %297
311: ; preds = %297
%312 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%313 = call i32 @stringLength(i8* %312)
store i32 %313, i32* %31
%314 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%315 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.15, i64 0, i64 0))
store i32 0, i32* %32
br label %316
316: ; preds = %327, %311
%317 = load i32, i32* %32
%318 = load i32, i32* %31
%319 = icmp slt i32 %317, %318
br i1 %319, label %320, label %330
320: ; preds = %316
%321 = load i32, i32* %32
%322 = sext i32 %321 to i64
%323 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %322
%324 = load i8, i8* %323
%325 = sext i8 %324 to i32
%326 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %325)
br label %327
327: ; preds = %320
%328 = load i32, i32* %32
%329 = add nsw i32 %328, 1
store i32 %329, i32* %32
br label %316
330: ; preds = %316
br label %331
331: ; preds = %330, %62
br label %332
332: ; preds = %331, %54
ret void
}

LLVM IR (-O2):
@.str = [69 x i8] c"Expected [Argv1] length of %d to be less than [Argv3] length of %d \0A\00"
@.str.1 = [65 x i8] c"Expected [Argv3] length of %d to be less than array size of %d \0A\00"
@.str.2 = [12 x i8] c"ORIGINAL = \00"
@.str.5 = [11 x i8] c"REPLACE = \00"
@.str.6 = [15 x i8] c"REPLACEMENT = \00"
@.str.8 = [19 x i8] c"isContained = %s \0A\00"
@.str.9 = [5 x i8] c"TRUE\00"
@.str.10 = [6 x i8] c"FALSE\00"
@.str.11 = [19 x i8] c"occurrences = %d \0A\00"
@.str.12 = [25 x i8] c"replacementLength = %d \0A\00"
@.str.13 = [10 x i8] c"OFFIND = \00"
@.str.14 = [4 x i8] c"%d \00"
@.str.15 = [11 x i8] c"UPDATED = \00"
@str = [2 x i8] c"\0A\00"
define void @replace(i8* %0, i8* %1, i8* %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = alloca [8 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 @strlen(i8* %2)
%12 = icmp slt i32 %11, %9
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11)
br label %347
15: ; preds = %3
%16 = icmp sgt i32 %11, 32
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 32)
br label %347
19: ; preds = %15
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp sgt i32 %11, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = zext i32 %11 to i64
br label %30
24: ; preds = %30, %19
%25 = tail call i32 @putchar(i32 10)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp sgt i32 %9, 0
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = zext i32 %9 to i64
br label %44
30: ; preds = %22, %30
%31 = phi i64 [ 0, %22 ], [ %36, %30 ]
%32 = getelementptr inbounds i8, i8* %2, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = tail call i32 @putchar(i32 %34)
%36 = add nuw nsw i64 %31, 1
%37 = icmp eq i64 %36, %23
br i1 %37, label %24, label %30
38: ; preds = %44, %24
%39 = tail call i32 @putchar(i32 10)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp sgt i32 %10, 0
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = zext i32 %10 to i64
br label %72
44: ; preds = %28, %44
%45 = phi i64 [ 0, %28 ], [ %50, %44 ]
%46 = getelementptr inbounds i8, i8* %0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = tail call i32 @putchar(i32 %48)
%50 = add nuw nsw i64 %45, 1
%51 = icmp eq i64 %50, %29
br i1 %51, label %38, label %44
52: ; preds = %72, %38
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%54 = tail call i32 @isInOrigString(i8* %0, i8* %2)
%55 = icmp eq i32 %54, 0
%56 = select i1 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0)
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %56)
%58 = tail call i32 @checkOccurrences(i8* %0, i8* %2)
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %58)
%60 = icmp slt i32 %11, %9
br i1 %60, label %87, label %61
61: ; preds = %52
%62 = icmp eq i32 %9, 2
%63 = add i32 %10, 255
%64 = add i32 %11, 1
%65 = sub i32 %64, %9
%66 = zext i32 %65 to i64
%67 = zext i32 %9 to i64
%68 = and i64 %67, 1
%69 = icmp eq i32 %9, 1
%70 = and i64 %67, 4294967294
%71 = icmp eq i64 %68, 0
br label %80
72: ; preds = %42, %72
%73 = phi i64 [ 0, %42 ], [ %78, %72 ]
%74 = getelementptr inbounds i8, i8* %1, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = tail call i32 @putchar(i32 %76)
%78 = add nuw nsw i64 %73, 1
%79 = icmp eq i64 %78, %43
br i1 %79, label %52, label %72
80: ; preds = %61, %202
%81 = phi i64 [ 0, %61 ], [ %206, %202 ]
%82 = phi i32 [ 0, %61 ], [ %205, %202 ]
%83 = phi i32 [ 0, %61 ], [ %146, %202 ]
%84 = phi i32 [ 0, %61 ], [ %204, %202 ]
%85 = phi i8 [ undef, %61 ], [ %203, %202 ]
br i1 %27, label %86, label %145
86: ; preds = %80
br i1 %69, label %132, label %148
87: ; preds = %202, %52
%88 = phi i8 [ undef, %52 ], [ %203, %202 ]
%89 = phi i32 [ 0, %52 ], [ %204, %202 ]
store i8 %88, i8* %8
%90 = zext i32 %10 to i64
%91 = add i32 %10, -1
%92 = zext i32 %91 to i64
%93 = add nuw nsw i64 %92, 1
%94 = sext i8 %88 to i32
%95 = trunc i64 %93 to i32
%96 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 1
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = trunc i64 %93 to i32
%100 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = trunc i64 %93 to i32
%104 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 3
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = trunc i64 %93 to i32
%108 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 4
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = trunc i64 %93 to i32
%112 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 5
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = trunc i64 %93 to i32
%116 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 6
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = trunc i64 %93 to i32
%120 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 7
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = trunc i64 %93 to i32
%124 = select i1 %27, i32 %9, i32 0
%125 = select i1 %27, i32 %9, i32 0
%126 = select i1 %27, i32 %9, i32 0
%127 = select i1 %27, i32 %9, i32 0
%128 = select i1 %27, i32 %9, i32 0
%129 = select i1 %27, i32 %9, i32 0
%130 = select i1 %27, i32 %9, i32 0
%131 = select i1 %27, i32 %9, i32 0
br label %208
132: ; preds = %148, %86
%133 = phi i32 [ undef, %86 ], [ %167, %148 ]
%134 = phi i64 [ 0, %86 ], [ %168, %148 ]
%135 = phi i32 [ %83, %86 ], [ %167, %148 ]
br i1 %71, label %145, label %136
136: ; preds = %132
%137 = getelementptr inbounds i8, i8* %0, i64 %134
%138 = load i8, i8* %137
%139 = add nuw nsw i64 %134, %81
%140 = getelementptr inbounds i8, i8* %2, i64 %139
%141 = load i8, i8* %140
%142 = icmp eq i8 %138, %141
%143 = add nsw i32 %135, 1
%144 = select i1 %142, i32 %143, i32 0
br label %145
145: ; preds = %136, %132, %80
%146 = phi i32 [ %83, %80 ], [ %133, %132 ], [ %144, %136 ]
%147 = icmp eq i32 %9, %146
br i1 %147, label %171, label %202
148: ; preds = %86, %148
%149 = phi i64 [ %168, %148 ], [ 0, %86 ]
%150 = phi i32 [ %167, %148 ], [ %83, %86 ]
%151 = phi i64 [ %169, %148 ], [ 0, %86 ]
%152 = getelementptr inbounds i8, i8* %0, i64 %149
%153 = load i8, i8* %152
%154 = add nuw nsw i64 %149, %81
%155 = getelementptr inbounds i8, i8* %2, i64 %154
%156 = load i8, i8* %155
%157 = icmp eq i8 %153, %156
%158 = or i64 %149, 1
%159 = getelementptr inbounds i8, i8* %0, i64 %158
%160 = load i8, i8* %159
%161 = add nuw nsw i64 %158, %81
%162 = getelementptr inbounds i8, i8* %2, i64 %161
%163 = load i8, i8* %162
%164 = icmp eq i8 %160, %163
%165 = add nsw i32 %150, 2
%166 = select i1 %157, i32 %165, i32 1
%167 = select i1 %164, i32 %166, i32 0
%168 = add nuw nsw i64 %149, 2
%169 = add i64 %151, 2
%170 = icmp eq i64 %169, %70
br i1 %170, label %132, label %148
171: ; preds = %145
%172 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 %10)
%173 = icmp eq i32 %84, 0
br i1 %173, label %174, label %176
174: ; preds = %171
%175 = trunc i64 %81 to i8
br label %198
176: ; preds = %171
%177 = icmp slt i32 %82, %58
br i1 %177, label %178, label %198
178: ; preds = %176
%179 = add nsw i32 %82, 1
br i1 %62, label %180, label %188
180: ; preds = %178
%181 = trunc i64 %81 to i32
%182 = add i32 %63, %181
%183 = xor i32 %82, -1
%184 = add i32 %182, %183
%185 = trunc i32 %184 to i8
%186 = sext i32 %84 to i64
%187 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %186
store i8 %185, i8* %187
br label %198
188: ; preds = %178
%189 = xor i32 %82, -1
%190 = trunc i64 %81 to i32
%191 = add i32 %10, %190
%192 = add i32 %191, 1
%193 = sub i32 %192, %9
%194 = add i32 %193, %189
%195 = trunc i32 %194 to i8
%196 = sext i32 %84 to i64
%197 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %196
store i8 %195, i8* %197
br label %198
198: ; preds = %176, %188, %180, %174
%199 = phi i8 [ %175, %174 ], [ %85, %180 ], [ %85, %188 ], [ %85, %176 ]
%200 = phi i32 [ %82, %174 ], [ %179, %180 ], [ %179, %188 ], [ %82, %176 ]
%201 = add nsw i32 %84, 1
br label %202
202: ; preds = %198, %145
%203 = phi i8 [ %199, %198 ], [ %85, %145 ]
%204 = phi i32 [ %201, %198 ], [ %84, %145 ]
%205 = phi i32 [ %200, %198 ], [ %82, %145 ]
%206 = add nuw nsw i64 %81, 1
%207 = icmp eq i64 %206, %66
br i1 %207, label %87, label %80
208: ; preds = %87, %304
%209 = phi i32 [ 0, %87 ], [ %313, %304 ]
%210 = phi i32 [ 0, %87 ], [ %312, %304 ]
%211 = icmp eq i32 %210, %94
br i1 %211, label %212, label %220
212: ; preds = %208
br i1 %41, label %213, label %217
213: ; preds = %212
%214 = sext i32 %210 to i64
%215 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %214
%216 = add i32 %210, %95
br label %217
217: ; preds = %213, %212
%218 = phi i32 [ %210, %212 ], [ %216, %213 ]
%219 = add i32 %209, %124
br label %220
220: ; preds = %217, %208
%221 = phi i32 [ %210, %208 ], [ %218, %217 ]
%222 = phi i32 [ %209, %208 ], [ %219, %217 ]
%223 = icmp eq i32 %221, %98
br i1 %223, label %224, label %232
224: ; preds = %220
br i1 %41, label %225, label %229
225: ; preds = %224
%226 = sext i32 %221 to i64
%227 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %226
%228 = add i32 %221, %99
br label %229
229: ; preds = %225, %224
%230 = phi i32 [ %221, %224 ], [ %228, %225 ]
%231 = add i32 %222, %125
br label %232
232: ; preds = %229, %220
%233 = phi i32 [ %221, %220 ], [ %230, %229 ]
%234 = phi i32 [ %222, %220 ], [ %231, %229 ]
%235 = icmp eq i32 %233, %102
br i1 %235, label %236, label %244
236: ; preds = %232
br i1 %41, label %237, label %241
237: ; preds = %236
%238 = sext i32 %233 to i64
%239 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %238
%240 = add i32 %233, %103
br label %241
241: ; preds = %237, %236
%242 = phi i32 [ %233, %236 ], [ %240, %237 ]
%243 = add i32 %234, %126
br label %244
244: ; preds = %241, %232
%245 = phi i32 [ %233, %232 ], [ %242, %241 ]
%246 = phi i32 [ %234, %232 ], [ %243, %241 ]
%247 = icmp eq i32 %245, %106
br i1 %247, label %248, label %256
248: ; preds = %244
br i1 %41, label %249, label %253
249: ; preds = %248
%250 = sext i32 %245 to i64
%251 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %250
%252 = add i32 %245, %107
br label %253
253: ; preds = %249, %248
%254 = phi i32 [ %245, %248 ], [ %252, %249 ]
%255 = add i32 %246, %127
br label %256
256: ; preds = %253, %244
%257 = phi i32 [ %245, %244 ], [ %254, %253 ]
%258 = phi i32 [ %246, %244 ], [ %255, %253 ]
%259 = icmp eq i32 %257, %110
br i1 %259, label %260, label %268
260: ; preds = %256
br i1 %41, label %261, label %265
261: ; preds = %260
%262 = sext i32 %257 to i64
%263 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %262
%264 = add i32 %257, %111
br label %265
265: ; preds = %261, %260
%266 = phi i32 [ %257, %260 ], [ %264, %261 ]
%267 = add i32 %258, %128
br label %268
268: ; preds = %265, %256
%269 = phi i32 [ %257, %256 ], [ %266, %265 ]
%270 = phi i32 [ %258, %256 ], [ %267, %265 ]
%271 = icmp eq i32 %269, %114
br i1 %271, label %272, label %280
272: ; preds = %268
br i1 %41, label %273, label %277
273: ; preds = %272
%274 = sext i32 %269 to i64
%275 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %274
%276 = add i32 %269, %115
br label %277
277: ; preds = %273, %272
%278 = phi i32 [ %269, %272 ], [ %276, %273 ]
%279 = add i32 %270, %129
br label %280
280: ; preds = %277, %268
%281 = phi i32 [ %269, %268 ], [ %278, %277 ]
%282 = phi i32 [ %270, %268 ], [ %279, %277 ]
%283 = icmp eq i32 %281, %118
br i1 %283, label %284, label %292
284: ; preds = %280
br i1 %41, label %285, label %289
285: ; preds = %284
%286 = sext i32 %281 to i64
%287 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %286
%288 = add i32 %281, %119
br label %289
289: ; preds = %285, %284
%290 = phi i32 [ %281, %284 ], [ %288, %285 ]
%291 = add i32 %282, %130
br label %292
292: ; preds = %289, %280
%293 = phi i32 [ %281, %280 ], [ %290, %289 ]
%294 = phi i32 [ %282, %280 ], [ %291, %289 ]
%295 = icmp eq i32 %293, %122
br i1 %295, label %296, label %304
296: ; preds = %292
br i1 %41, label %297, label %301
297: ; preds = %296
%298 = sext i32 %293 to i64
%299 = getelementptr [32 x i8], [32 x i8]* %4, i64 0, i64 %298
%300 = add i32 %293, %123
br label %301
301: ; preds = %297, %296
%302 = phi i32 [ %293, %296 ], [ %300, %297 ]
%303 = add i32 %294, %131
br label %304
304: ; preds = %301, %292
%305 = phi i32 [ %293, %292 ], [ %302, %301 ]
%306 = phi i32 [ %294, %292 ], [ %303, %301 ]
%307 = sext i32 %306 to i64
%308 = getelementptr inbounds i8, i8* %2, i64 %307
%309 = load i8, i8* %308
%310 = sext i32 %305 to i64
%311 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %310
store i8 %309, i8* %311
%312 = add nsw i32 %305, 1
%313 = add nsw i32 %306, 1
%314 = icmp slt i32 %305, 31
br i1 %314, label %208, label %315
315: ; preds = %304
%316 = tail call i32 @putchar(i32 10)
%317 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
%318 = icmp sgt i32 %89, 0
br i1 %318, label %319, label %324
319: ; preds = %315
%320 = zext i32 %89 to i64
%321 = sext i8 %88 to i32
%322 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 %321)
%323 = icmp eq i32 %89, 1
br i1 %323, label %324, label %331
324: ; preds = %331, %319, %315
%325 = call i32 @stringLength(i8* %7)
%326 = call i32 @putchar(i32 10)
%327 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.15, i64 0, i64 0))
%328 = icmp sgt i32 %325, 0
br i1 %328, label %329, label %347
329: ; preds = %324
%330 = zext i32 %325 to i64
br label %339
331: ; preds = %319, %331
%332 = phi i64 [ %337, %331 ], [ 1, %319 ]
%333 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %332
%334 = load i8, i8* %333
%335 = sext i8 %334 to i32
%336 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 %335)
%337 = add nuw nsw i64 %332, 1
%338 = icmp eq i64 %337, %320
br i1 %338, label %324, label %331
339: ; preds = %329, %339
%340 = phi i64 [ 0, %329 ], [ %345, %339 ]
%341 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %340
%342 = load i8, i8* %341
%343 = sext i8 %342 to i32
%344 = call i32 @putchar(i32 %343)
%345 = add nuw nsw i64 %340, 1
%346 = icmp eq i64 %345, %330
br i1 %346, label %347, label %339
347: ; preds = %339, %324, %17, %13
ret void
}