// File: 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
subq $0xa0, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x80(%rbp)
movb -0x9(%rbp), %al
movq -0x28(%rbp), %rdx
movsbl %al, %esi
callq 0x1a730
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1a6a1
movl $0x18, %edi
callq 0x43d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
xorl %esi, %esi
callq 0x1b150
jmp 0x1a568
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0x38(%rbp)
movsbl -0x9(%rbp), %esi
callq 0x1b370
movzbl %al, %eax
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1b390
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x1a5da
movq -0x28(%rbp), %rdi
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq $0x0, -0x50(%rbp)
leaq -0x50(%rbp), %rdx
callq 0x1b1b0
jmp 0x1a5da
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x43a0
jmp 0x1a71a
movl $0x38, %edi
callq 0x43d0
movq %rax, -0x98(%rbp)
movb $0x1, -0x71(%rbp)
movb -0x9(%rbp), %al
movb %al, -0x89(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x41a0
jmp 0x1a607
movq -0x98(%rbp), %rdi
movb -0x89(%rbp), %al
movq -0x38(%rbp), %rcx
movsd -0x20(%rbp), %xmm0
movsbl %al, %esi
leaq -0x70(%rbp), %rdx
callq 0x1b3b0
jmp 0x1a62b
movq -0x98(%rbp), %rax
movb $0x0, -0x71(%rbp)
movq %rax, -0x30(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4828
movq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0x1b410
movq -0xa0(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x1a6e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1a68b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4828
testb $0x1, -0x71(%rbp)
jne 0x1a693
jmp 0x1a69f
movq -0x98(%rbp), %rdi
callq 0x43a0
jmp 0x1a71a
movq -0x18(%rbp), %rdi
callq 0x45e0
cmpq $0x0, %rax
jbe 0x1a6e2
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
cmpq $0x0, %rax
jne 0x1a6d4
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
callq 0x4040
movsd -0x20(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x30(%rax)
jmp 0x1a6e4
movq -0x18(%rbp), %rdi
callq 0x45e0
movq -0x80(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jle 0x1a709
movq -0x18(%rbp), %rdi
callq 0x45e0
movq %rax, %rcx
movq -0x80(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
addq $0xa0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)