// File: /workspace/github_c_makefile_star2_O3/niuyuling[P]CProxy/http_request.c
// Function: replace
char *replace(char *replace_memory, int *replace_memory_len, const char *src, const int src_len, const char *dest, const int dest_len)
{
    if (!replace_memory || !src || !dest)
        return replace_memory;

    char *p;
    int diff;

    if (src_len == dest_len) {
        for (p = memmem(replace_memory, *replace_memory_len, src, src_len); p; p = memmem(p, *replace_memory_len - (p - replace_memory), src, src_len)) {
            memcpy(p, dest, dest_len);
            p += dest_len;
        }
    } else if (src_len < dest_len) {
        int before_len;
        char *before_end, *new_replace_memory;

        diff = dest_len - src_len;
        for (p = memmem(replace_memory, *replace_memory_len, src, src_len); p; p = memmem(p, *replace_memory_len - (p - replace_memory), src, src_len)) {
            *replace_memory_len += diff;
            before_len = p - replace_memory;
            new_replace_memory = (char *)realloc(replace_memory, *replace_memory_len + 1);
            if (new_replace_memory == NULL) {
                free(replace_memory);
                return NULL;
            }
            replace_memory = new_replace_memory;
            before_end = replace_memory + before_len;
            p = before_end + dest_len;
            memmove(p, p - diff, *replace_memory_len - (p - replace_memory));
            memcpy(before_end, dest, dest_len);
        }
    } else if (src_len > dest_len) {
        diff = src_len - dest_len;
        for (p = memmem(replace_memory, *replace_memory_len, src, src_len); p; p = memmem(p, *replace_memory_len - (p - replace_memory), src, src_len)) {
            *replace_memory_len -= diff;
            memcpy(p, dest, dest_len);
            p += dest_len;
            memmove(p, p + diff, *replace_memory_len - (p - replace_memory));
        }
    }

    replace_memory[*replace_memory_len] = '\0';
    return replace_memory;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r12d
movq %rdi, %r13
testq %rdi, %rdi
sete %al
movq %rdx, 0x10(%rsp)
testq %rdx, %rdx
sete %cl
orb %al, %cl
testq %r8, %r8
sete %al
orb %cl, %al
jne 0x42f6
movq %r8, %r14
movq %rsi, %rbx
cmpl %r9d, %r12d
jne 0x415f
movslq (%rbx), %rsi
movslq %r12d, %r12
movq %r13, %rdi
movq 0x10(%rsp), %rdx
movq %r12, %rcx
callq 0x22d0
testq %rax, %rax
je 0x42e8
movq %rax, %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x22e0
addq %r12, %rbp
movslq (%rbx), %rax
movq %r13, %rsi
subq %rbp, %rsi
addq %rax, %rsi
movq %rbp, %rdi
movq 0x10(%rsp), %rdx
movq %r12, %rcx
callq 0x22d0
movq %rax, %rbp
testq %rax, %rax
jne 0x4125
jmp 0x42e8
jge 0x4246
movl %r9d, 0x8(%rsp)
movslq (%rbx), %rsi
movslq %r12d, %rcx
movq %r13, %rdi
movq 0x10(%rsp), %rdx
movq %rcx, 0x18(%rsp)
callq 0x22d0
testq %rax, %rax
je 0x42e8
movq %rax, %rbp
movq %r14, 0x20(%rsp)
movl 0x8(%rsp), %ecx
movslq %ecx, %rax
movq %rax, 0x30(%rsp)
subl %r12d, %ecx
movslq %ecx, %rax
movq %rax, 0x8(%rsp)
negq %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %r15
movslq (%rbx), %rax
movq 0x8(%rsp), %rdx
leaq (%rax,%rdx), %rcx
movl %ecx, (%rbx)
leaq (%rax,%rdx), %rsi
incq %rsi
movq %r13, %rdi
callq 0x23d0
testq %rax, %rax
je 0x4308
movq %rax, %r14
subl %r13d, %ebp
movslq %ebp, %r13
addq %rax, %r13
leaq (%r15,%r13), %rbp
movq 0x28(%rsp), %rax
leaq (%rax,%rbp), %rsi
movslq (%rbx), %rax
movq %r14, %r12
subq %rbp, %r12
addq %rax, %r12
movq %rbp, %rdi
movq %r12, %rdx
callq 0x2430
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x22e0
movq %rbp, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x22d0
movq %rax, %rbp
movq %r14, %r13
testq %rax, %rax
jne 0x41b7
jmp 0x42eb
movq %r14, 0x20(%rsp)
movl %r12d, %r14d
subl %r9d, %r14d
jle 0x42e8
movl %r9d, 0x8(%rsp)
movslq (%rbx), %rsi
movslq %r12d, %r12
movq %r13, %rdi
movq 0x10(%rsp), %rdx
movq %r12, %rcx
callq 0x22d0
testq %rax, %rax
je 0x42e8
movq %rax, %rbp
movslq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movslq %r14d, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %r15
subl %r15d, (%rbx)
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r14
movq %r14, %rdx
callq 0x22e0
addq %r14, %rbp
leaq (%r15,%rbp), %rsi
movslq (%rbx), %rdx
movq %r12, %r14
movq %rbp, %r12
subq %r13, %r12
subq %r12, %rdx
movq %rbp, %rdi
callq 0x2430
movslq (%rbx), %rsi
subq %r12, %rsi
movq %r14, %r12
movq %rbp, %rdi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
callq 0x22d0
movq %rax, %rbp
testq %rax, %rax
jne 0x4291
movq %r13, %r14
movslq (%rbx), %rax
movb $0x0, (%r14,%rax)
movq %r14, %r13
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x2030
xorl %r13d, %r13d
jmp 0x42f6