// File: ahupowerdns[P]mcounter/./ext/doctest.h
// Function: doctest::String::operator+=(doctest::String const&)
String& String::operator+=(const String& other) {
    const unsigned my_old_size = size();
    const unsigned other_size  = other.size();
    const unsigned total_size  = my_old_size + other_size;
    if(isOnStack()) {
        if(total_size < len) {
            // append to the current stack space
            memcpy(buf + my_old_size, other.c_str(), other_size + 1);
            // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
            setLast(last - total_size);
        } else {
            // alloc new chunk
            char* temp = new char[total_size + 1];
            // copy current data to new location before writing in the union
            memcpy(temp, buf, my_old_size); // skip the +1 ('\0') for speed
            // update data in union
            setOnHeap();
            data.size     = total_size;
            data.capacity = data.size + 1;
            data.ptr      = temp;
            // transfer the rest of the data
            memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1);
        }
    } else {
        if(data.capacity > total_size) {
            // append to the current heap block
            data.size = total_size;
            memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1);
        } else {
            // resize
            data.capacity *= 2;
            if(data.capacity <= total_size)
                data.capacity = total_size + 1;
            // alloc new chunk
            char* temp = new char[data.capacity];
            // copy current data to new location before releasing it
            memcpy(temp, data.ptr, my_old_size); // skip the +1 ('\0') for speed
            // release old chunk
            delete[] data.ptr;
            // update the rest of the union members
            data.size = total_size;
            data.ptr  = temp;
            // transfer the rest of the data
            memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1);
        }
    }

    return *this;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x38(%rbp)
callq 0x7cb0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7cb0
movq -0x38(%rbp), %rdi
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
callq 0x20ca0
testb $0x1, %al
jne 0x7af7
jmp 0x7bb6
cmpl $0x18, -0x1c(%rbp)
jae 0x7b3d
movq -0x38(%rbp), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20cd0
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x6370
movq -0x38(%rbp), %rdi
movl $0x17, %esi
subl -0x1c(%rbp), %esi
callq 0x7810
jmp 0x7bb1
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x6030
movq -0x38(%rbp), %rsi
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x6370
movq -0x38(%rbp), %rdi
callq 0x7830
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq (%rax), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20cd0
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x6370
jmp 0x7ca1
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x1c(%rbp), %eax
jbe 0x7bfd
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq (%rax), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20cd0
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x6370
jmp 0x7c9f
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
shll %ecx
movl %ecx, 0xc(%rax)
movl 0xc(%rax), %eax
cmpl -0x1c(%rbp), %eax
ja 0x7c1e
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
callq 0x6030
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq (%rax), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x6370
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x7c62
movq -0x58(%rbp), %rdi
callq 0x6600
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq (%rax), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20cd0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x6370
jmp 0x7ca1
movq -0x38(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)