// File: /workspace/github_c_makefile_star2_O0/niuyuling[P]CProxy/http_request.c
// Function: regrep
static char *regrep(char *str, int *str_len, const char *src, char *dest, int dest_len)
{
    if (!str || !src || !dest)
        return NULL;

    regmatch_t pm[10];
    regex_t reg;
    char child_num[2] = { '\\', '0' }, *p, *real_dest;
    int match_len, real_dest_len, i;

    p = str;
    regcomp(&reg, src, REG_NEWLINE | REG_ICASE | REG_EXTENDED);
    while (regexec(&reg, p, 10, pm, 0) == 0) {
        real_dest = (char *)malloc(dest_len);
        if (real_dest == NULL) {
            regfree(&reg);
            free(str);
            return NULL;
        }
        memcpy(real_dest, dest, dest_len);
        real_dest_len = dest_len;
        //不进行不必要的字符串操作
        if (pm[1].rm_so >= 0) {
            /* 替换目标字符串中的子表达式 */
            for (i = 1; i < 10 && pm[i].rm_so > -1; i++) {
                child_num[1] = i + 48;
                real_dest = replace(real_dest, &real_dest_len, child_num, 2, p + pm[i].rm_so, pm[i].rm_eo - pm[i].rm_so);
                if (real_dest == NULL) {
                    regfree(&reg);
                    free(str);
                    return NULL;
                }
            }
        }

        match_len = pm[0].rm_eo - pm[0].rm_so;
        p += pm[0].rm_so;
        //目标字符串不大于匹配字符串则不用分配新内存
        if (match_len >= real_dest_len) {
            memcpy(p, real_dest, real_dest_len);
            if (match_len > real_dest_len)
                //strcpy(p + real_dest_len, p + match_len);
                memmove(p + real_dest_len, p + match_len, *str_len - (p + match_len - str));
            p += real_dest_len;
            *str_len -= match_len - real_dest_len;
        } else {
            int diff;
            char *before_end, *new_str;

            diff = real_dest_len - match_len;
            *str_len += diff;
            new_str = (char *)realloc(str, *str_len + 1);
            if (new_str == NULL) {
                free(str);
                free(real_dest);
                regfree(&reg);
                return NULL;
            }
            str = new_str;
            before_end = str + pm[0].rm_so;
            p = before_end + real_dest_len;
            memmove(p, p - diff, *str_len - (p - str) + 1);
            memcpy(before_end, real_dest, real_dest_len);
        }
        free(real_dest);
    }

    regfree(&reg);
    return str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x6e04
cmpq $0x0, -0x20(%rbp)
je 0x6e04
cmpq $0x0, -0x28(%rbp)
jne 0x6e11
movq $0x0, -0x8(%rbp)
jmp 0x71b1
movw 0x567a(%rip), %ax       # 0xc492
movw %ax, -0xc2(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
movl $0x7, %edx
callq 0x2230
movq -0xd0(%rbp), %rsi
leaq -0x80(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
movl $0xa, %edx
xorl %r8d, %r8d
callq 0x23a0
cmpl $0x0, %eax
jne 0x719d
movslq -0x2c(%rbp), %rdi
callq 0x2350
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0x6ea3
leaq -0xc0(%rbp), %rdi
callq 0x2120
movq -0x10(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x71b1
movq -0xd8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
callq 0x2300
movl -0x2c(%rbp), %eax
movl %eax, -0xe0(%rbp)
cmpl $0x0, -0x78(%rbp)
jl 0x6fb0
movl $0x1, -0xe4(%rbp)
xorl %eax, %eax
cmpl $0xa, -0xe4(%rbp)
movb %al, -0xf9(%rbp)
jge 0x6efa
movslq -0xe4(%rbp), %rax
cmpl $-0x1, -0x80(%rbp,%rax,8)
setg %al
movb %al, -0xf9(%rbp)
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x6f09
jmp 0x6fae
movl -0xe4(%rbp), %eax
addl $0x30, %eax
movb %al, -0xc1(%rbp)
movq -0xd8(%rbp), %rdi
leaq -0xc2(%rbp), %rdx
movq -0xd0(%rbp), %r8
movslq -0xe4(%rbp), %rax
movslq -0x80(%rbp,%rax,8), %rax
addq %rax, %r8
movslq -0xe4(%rbp), %rax
movl -0x7c(%rbp,%rax,8), %r9d
movslq -0xe4(%rbp), %rax
subl -0x80(%rbp,%rax,8), %r9d
leaq -0xe0(%rbp), %rsi
movl $0x2, %ecx
callq 0x4d00
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0x6f98
leaq -0xc0(%rbp), %rdi
callq 0x2120
movq -0x10(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x71b1
jmp 0x6f9a
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x6ed4
jmp 0x6fb0
movl -0x7c(%rbp), %eax
subl -0x80(%rbp), %eax
movl %eax, -0xdc(%rbp)
movl -0x80(%rbp), %ecx
movq -0xd0(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movl -0xdc(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jl 0x708b
movq -0xd0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movslq -0xe0(%rbp), %rdx
callq 0x2300
movl -0xdc(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jle 0x7056
movq -0xd0(%rbp), %rdi
movslq -0xe0(%rbp), %rax
addq %rax, %rdi
movq -0xd0(%rbp), %rsi
movslq -0xdc(%rbp), %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movslq (%rax), %rdx
movq -0xd0(%rbp), %rax
movslq -0xdc(%rbp), %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
subq %rax, %rdx
callq 0x2450
movl -0xe0(%rbp), %ecx
movq -0xd0(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movl -0xdc(%rbp), %edx
subl -0xe0(%rbp), %edx
movq -0x18(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
jmp 0x718c
movl -0xe0(%rbp), %eax
subl -0xdc(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0xe8(%rbp), %ecx
movq -0x18(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x23e0
movq %rax, -0xf8(%rbp)
cmpq $0x0, -0xf8(%rbp)
jne 0x70ff
movq -0x10(%rbp), %rdi
callq 0x2030
movq -0xd8(%rbp), %rdi
callq 0x2030
leaq -0xc0(%rbp), %rdi
callq 0x2120
movq $0x0, -0x8(%rbp)
jmp 0x71b1
movq -0xf8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movslq -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movslq -0xe0(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movslq -0xe8(%rbp), %rcx
xorl %eax, %eax
subq %rcx, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movslq (%rax), %rdx
movq -0xd0(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
subq %rax, %rdx
addq $0x1, %rdx
callq 0x2450
movq -0xf0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movslq -0xe0(%rbp), %rdx
callq 0x2300
movq -0xd8(%rbp), %rdi
callq 0x2030
jmp 0x6e3f
leaq -0xc0(%rbp), %rdi
callq 0x2120
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop