// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movq %rdi, %r12
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
testq %r8, %r8
sete %al
orb %cl, %al
jne 0x430d
movl %r9d, %r13d
movq %r8, %r14
movq %rsi, %rbx
movq %rdx, 0x10(%rsp)
cmpl %r9d, %ebp
jne 0x417d
movq %r14, %r15
movslq (%rbx), %rsi
movslq %ebp, %rbp
movq %r12, %rdi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
callq 0x22c0
testq %rax, %rax
je 0x42ff
movq %rax, %r14
movq %rbp, 0x8(%rsp)
movslq %r13d, %rbp
movq 0x10(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x22d0
addq %rbp, %r14
movslq (%rbx), %rax
movq %r12, %rsi
subq %r14, %rsi
addq %rax, %rsi
movq %r14, %rdi
movq %r13, %rdx
movq 0x8(%rsp), %rcx
callq 0x22c0
movq %rax, %r14
testq %rax, %rax
jne 0x4143
jmp 0x42ff
jge 0x4264
movl %r13d, %r15d
movslq (%rbx), %rsi
movslq %ebp, %rcx
movq %r12, %rdi
movq 0x10(%rsp), %rdx
movq %rcx, 0x8(%rsp)
callq 0x22c0
testq %rax, %rax
je 0x42ff
movq %rax, %r13
movslq %r15d, %rax
movq %rax, 0x28(%rsp)
subl %ebp, %r15d
movslq %r15d, %rax
movq %rax, 0x30(%rsp)
negq %rax
movq %rax, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movslq (%rbx), %rax
movq 0x30(%rsp), %rdx
leaq (%rax,%rdx), %rcx
movl %ecx, (%rbx)
leaq (%rax,%rdx), %rsi
incq %rsi
movq %r12, %rdi
callq 0x23c0
testq %rax, %rax
je 0x431f
movq %rax, %rbp
subl %r12d, %r13d
movslq %r13d, %r14
addq %rax, %r14
movq %rbx, %r15
movq 0x28(%rsp), %rbx
leaq (%r14,%rbx), %r12
movq 0x20(%rsp), %rax
leaq (%r12,%rax), %rsi
movslq (%r15), %rax
movq %rbp, %r13
subq %r12, %r13
addq %rax, %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0x2420
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
movq %r15, %rbx
callq 0x22d0
movq %r12, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
callq 0x22c0
movq %rax, %r13
movq %rbp, %r12
testq %rax, %rax
jne 0x41ca
jmp 0x4302
movq %r14, %r15
movl %ebp, %r14d
subl %r13d, %r14d
jle 0x42ff
movl %r13d, 0x8(%rsp)
movslq (%rbx), %rsi
movslq %ebp, %rbp
movq %r12, %rdi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
callq 0x22c0
testq %rax, %rax
je 0x42ff
movq %rax, %r13
movslq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
movslq %r14d, %r14
movq %r15, 0x18(%rsp)
subl %r14d, (%rbx)
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdx
callq 0x22d0
addq %r15, %r13
leaq (%r14,%r13), %rsi
movslq (%rbx), %rdx
movq %rbp, %r15
movq %r13, %rbp
subq %r12, %rbp
subq %rbp, %rdx
movq %r13, %rdi
callq 0x2420
movslq (%rbx), %rsi
subq %rbp, %rsi
movq %r15, %rbp
movq %r13, %rdi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x22c0
movq %rax, %r13
testq %rax, %rax
jne 0x42a8
movq %r12, %rbp
movslq (%rbx), %rax
movb $0x0, (%rbp,%rax)
movq %rbp, %r12
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x2030
xorl %r12d, %r12d
jmp 0x430d