// File: /workspace/github_c_makefile_star2_O2/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
movq %rdx, %r15
movq %rdi, %r13
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %dl
orb %al, %dl
testq %r8, %r8
sete %al
orb %dl, %al
jne 0x412f
movl %r9d, %ebp
movq %r8, %r14
movq %rsi, %rbx
cmpl %r9d, %ecx
jne 0x3fb9
movslq (%rbx), %rsi
movslq %ecx, %r12
movq %r13, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x22d0
movq %rax, %rbp
testq %rax, %rax
je 0x4126
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
jmp 0x3f80
movq %r14, 0x18(%rsp)
jge 0x40a2
movl %ebp, %r14d
subl %ecx, %r14d
movq %rbx, 0x8(%rsp)
movslq (%rbx), %rsi
movslq %ecx, %rcx
movq %r13, %rdi
movq %r15, %rdx
movq %rcx, 0x30(%rsp)
callq 0x22d0
movl %ebp, %ecx
movq %rax, %rbp
movslq %ecx, %rax
movq %rax, 0x28(%rsp)
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
negq %rax
movq %rax, 0x20(%rsp)
testq %rbp, %rbp
je 0x4121
movq 0x8(%rsp), %rbx
movslq (%rbx), %rax
movq 0x10(%rsp), %rdx
leaq (%rax,%rdx), %rcx
movl %ecx, (%rbx)
leaq (%rax,%rdx), %rsi
incq %rsi
movq %r13, %rdi
callq 0x23d0
testq %rax, %rax
je 0x4141
movq %rax, %r14
subl %r13d, %ebp
movslq %ebp, %r13
addq %rax, %r13
movq %rbx, %rax
movq %r15, %rbx
movq 0x28(%rsp), %r15
leaq (%r15,%r13), %rbp
movq 0x20(%rsp), %rcx
leaq (%rcx,%rbp), %rsi
movslq (%rax), %rax
movq %r14, %r12
subq %rbp, %r12
addq %rax, %r12
movq %rbp, %rdi
movq %r12, %rdx
callq 0x2430
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %r15
callq 0x22e0
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x30(%rsp), %rcx
callq 0x22d0
movq %rax, %rbp
movq %r14, %r13
jmp 0x4002
movl %ecx, %r14d
subl %ebp, %r14d
jle 0x4126
movslq (%rbx), %rsi
movslq %ecx, %rcx
movq %r13, %rdi
movq %r15, %rdx
movq %rcx, 0x8(%rsp)
callq 0x22d0
movq %rax, %r12
movslq %ebp, %rax
movq %rax, 0x10(%rsp)
movslq %r14d, %r14
testq %r12, %r12
je 0x4126
subl %r14d, (%rbx)
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rbp
movq %rbp, %rdx
callq 0x22e0
addq %rbp, %r12
leaq (%r12,%r14), %rsi
movslq (%rbx), %rdx
movq %r12, %rbp
subq %r13, %rbp
subq %rbp, %rdx
movq %r12, %rdi
callq 0x2430
movslq (%rbx), %rsi
subq %rbp, %rsi
movq %r12, %rdi
movq %r15, %rdx
movq 0x8(%rsp), %rcx
callq 0x22d0
movq %rax, %r12
jmp 0x40ce
movq 0x8(%rsp), %rbx
movslq (%rbx), %rax
movb $0x0, (%r13,%rax)
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 0x412f