// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/lib/common.c
// Function: replaceChars
char *replaceChars(char *string, char *old, char *new)
/*
  Replaces the old with the new. The old and new string need not be of equal size
 Can take any length string.
 Return value needs to be freeMem'd.
*/
{
int numTimes = 0;
int oldLen = strlen(old);
int newLen = strlen(new);
int strLen = 0;
char *result = NULL;
char *ptr = strstr(string, old);
char *resultPtr = NULL;

while(NULL != ptr)
    {
    numTimes++;
    ptr += oldLen;
    ptr = strstr(ptr, old);
    }
strLen = max(strlen(string) + (numTimes * (newLen - oldLen)), strlen(string));
result = needMem(strLen + 1);

ptr = strstr(string, old);
resultPtr = result;
while(NULL != ptr)
    {
    strLen = ptr - string;
    strcpy(resultPtr, string);
    string = ptr + oldLen;

    resultPtr += strLen;
    strcpy(resultPtr, new);
    resultPtr += newLen;
    ptr = strstr(string, old);
    }

strcpy(resultPtr, string);
return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x31f0
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x31f0
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3730
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
xorl %eax, %eax
cmpq -0x38(%rbp), %rax
je 0xae60
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3730
movq %rax, -0x38(%rbp)
jmp 0xae2b
movq -0x8(%rbp), %rdi
callq 0x31f0
movl -0x1c(%rbp), %ecx
movl -0x24(%rbp), %edx
subl -0x20(%rbp), %edx
imull %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x31f0
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jbe 0xaeb5
movq -0x8(%rbp), %rdi
callq 0x31f0
movl -0x1c(%rbp), %ecx
movl -0x24(%rbp), %edx
subl -0x20(%rbp), %edx
imull %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0xaec2
movq -0x8(%rbp), %rdi
callq 0x31f0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x152f0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3730
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
xorl %eax, %eax
cmpq -0x38(%rbp), %rax
je 0xaf68
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x28(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x30c0
movq -0x38(%rbp), %rax
movslq -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x8(%rbp)
movl -0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x30c0
movl -0x24(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3730
movq %rax, -0x38(%rbp)
jmp 0xaef4
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x30c0
movq -0x30(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop