// File: gpertea[P]gclib/GStr.cpp
// Function: GStr::paste(GStr const&, int, int)
GStr&  GStr::paste(const GStr& s, int idx, int len) {
    // A negative idx specifies an idx from the right of the string.
    if (idx < 0)
        idx += length();
    make_unique(); //edit operation ahead

    // A length of -1 specifies the rest of the string.
    if (len == -1)
        len = length() - idx;

    if (idx<0 || idx>=length() || len<0 || len>length()-idx)
        invalid_args_error("replace()");

    if (len == s.length() && my_data->ref_count == 1)
        ::memcpy(&chrs()[idx], s.chars(), len);
    else {
        Data *data = new_data(length() - len + s.length());
        if (idx > 0)
            ::memcpy(data->chars, my_data->chars, idx);
        if (s.length() > 0)
            ::memcpy(&data->chars[idx], s.chars(), s.length());
        ::strcpy(&data->chars[idx+s.length()], &my_data->chars[idx+len]);
        replace_data(data);
    }

    return *this;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x98c3
movq -0x28(%rbp), %rdi
callq 0xb660
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x28(%rbp), %rdi
callq 0x63e0
cmpl $-0x1, -0x18(%rbp)
jne 0x98e1
movq -0x28(%rbp), %rdi
callq 0xb660
subl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x9920
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
callq 0xb660
movl %eax, %ecx
movl -0x2c(%rbp), %eax
cmpl %ecx, %eax
jge 0x9920
cmpl $0x0, -0x18(%rbp)
jl 0x9920
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %eax
movl %eax, -0x30(%rbp)
callq 0xb660
movl %eax, %ecx
movl -0x30(%rbp), %eax
subl -0x14(%rbp), %ecx
cmpl %ecx, %eax
jle 0x992c
leaq 0xa894(%rip), %rdi      # 0x141bb
callq 0x91c0
movl -0x18(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb660
movl %eax, %ecx
movl -0x34(%rbp), %eax
cmpl %ecx, %eax
jne 0x9983
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
cmpl $0x1, (%rax)
jne 0x9983
movq -0x28(%rbp), %rdi
callq 0xb630
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb610
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movslq -0x18(%rbp), %rdx
callq 0x21f0
jmp 0x9a6a
movq -0x28(%rbp), %rdi
callq 0xb660
subl -0x18(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb660
movl -0x44(%rbp), %edi
addl %eax, %edi
xorl %esi, %esi
callq 0x6100
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x99ce
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rdi
addq $0xc, %rdi
movq 0x20(%rax), %rsi
addq $0xc, %rsi
movslq -0x14(%rbp), %rdx
callq 0x21f0
movq -0x10(%rbp), %rdi
callq 0xb660
cmpl $0x0, %eax
jle 0x9a15
movq -0x20(%rbp), %rax
addq $0xc, %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb610
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb660
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movslq %eax, %rdx
callq 0x21f0
movq -0x20(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x60(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb660
movl -0x64(%rbp), %ecx
movq -0x60(%rbp), %rdi
movl %eax, %edx
movq -0x28(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rdi
movq 0x20(%rax), %rsi
addq $0xc, %rsi
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
cltq
addq %rax, %rsi
callq 0x2240
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x6460
movq -0x28(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)