// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/src/StringSet.cc
// Function: StringSet::insert(char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, double, StringSet::Node*)
StringSet::Node*
StringSet::insert(char letter,
                  const string &factor,
                  flt_type cost,
                  StringSet::Node *node)
{
    // Find a possible existing arc with the letter
    Arc *arc = find_arc(letter, node);

    // No existing arc: create a new arc
    if (arc == nullptr) {
        Node *new_node = new Node();
        unsigned int remapped = remap_char(letter); // unsigned char!
        if (node->arcs.size() < remapped+1) node->arcs.resize(remapped+1, nullptr);
        arc = new Arc(letter, factor, new_node, cost);
        node->arcs[remapped] = arc;
    }

    // Update the existing arc if factor was set
    else if (factor.length() > 0) {
        if (arc->factor.length() == 0) arc->factor = factor;
        arc->cost = cost;
    }

    // Maintain the length of the longest factor
    if ((int)factor.length() > max_factor_length)
        max_factor_length = factor.length();

    return arc->target_node;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r15
movl %esi, %r13d
movq %rdi, %rbx
movzbl %r13b, %r14d
movzbl 0x1c(%rdi,%r14), %eax
movq (%rcx), %rcx
movq 0x8(%r15), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
cmpq %rax, %rsi
jbe 0xcc89
movq (%rcx,%rax,8), %r12
jmp 0xcc8c
xorl %r12d, %r12d
testq %r12, %r12
je 0xcccd
cmpq $0x0, 0x8(%rdx)
je 0xcd9e
cmpq $0x0, 0x10(%r12)
jne 0xccc1
leaq 0x8(%r12), %rdi
movq %rdx, %rsi
movq %rdx, %r14
movsd %xmm0, -0x38(%rbp)
callq 0x41c0
movsd -0x38(%rbp), %xmm0
movq %r14, %rdx
movsd %xmm0, 0x30(%r12)
jmp 0xcd9e
movsd %xmm0, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movl $0x18, %edi
callq 0x4390
movq %rax, -0x30(%rbp)
movq %rax, %rdi
xorl %esi, %esi
callq 0xd3f6
movzbl 0x1c(%rbx,%r14), %r14d
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x3, %rax
cmpq %r14, %rax
ja 0xcd1b
leaq 0x1(%r14), %rsi
leaq -0x68(%rbp), %rdx
movq $0x0, (%rdx)
movq %r15, %rdi
callq 0xd440
movl $0x38, %edi
callq 0x4390
movq %rax, %r12
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0x5f0a
movb %r13b, (%r12)
leaq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
movq %rax, 0x8(%r12)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
callq 0x5f0a
movq -0x30(%rbp), %rax
movq %rax, 0x28(%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x30(%r12)
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0xcd93
callq 0x4350
movq (%r15), %rax
movq %r12, (%rax,%r14,8)
movq -0x40(%rbp), %rdx
movl 0x8(%rdx), %eax
cmpl %eax, 0x18(%rbx)
jge 0xcda9
movl %eax, 0x18(%rbx)
movq 0x28(%r12), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0xcdd7
callq 0x4350
jmp 0xcdd7
movq %rax, %rbx
movq %r12, -0x30(%rbp)
jmp 0xcde0
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x4350
movq %rbx, %rdi
callq 0x4650
nop