// File: jpcima[P]faustmd/metadata.cpp
// Function: extract_metadata(pugi::xml_document const&, Metadata&)
int extract_metadata(const pugi::xml_document &doc, Metadata &md)
{
    pugi::xml_node root = doc.child("faust");

    md.name = root.child_value("name");
    md.author = root.child_value("author");
    md.copyright = root.child_value("copyright");
    md.license = root.child_value("license");
    md.version = root.child_value("version");
    md.classname = root.child_value("classname");
    md.inputs = std::stoi(root.child_value("inputs"));
    md.outputs = std::stoi(root.child_value("outputs"));

    for (pugi::xml_node meta : root.children("meta")) {
        std::string key = meta.attribute("key").value();
        std::string value = meta.child_value();
        md.metadata.emplace_back(key, value);
    }

    for (pugi::xml_node node : root.child("ui").child("activewidgets").children("widget")) {
        if (extract_widget(node, true, md) == -1)
            return -1;
    }

    for (pugi::xml_node node : root.child("ui").child("passivewidgets").children("widget")) {
        if (extract_widget(node, false, md) == -1)
            return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x2e728(%rip), %rsi     # 0x66616
callq 0x3eeb0
movq %rax, -0x20(%rbp)
leaq 0x32d71(%rip), %rsi     # 0x6ac6f
leaq -0x20(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x3f910
movq %rax, %rsi
movq -0x18(%rbp), %rdi
callq 0x77d0
movq -0x270(%rbp), %rdi
leaq 0x2f738(%rip), %rsi     # 0x67660
callq 0x3f910
movq %rax, %rsi
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0x77d0
movq -0x270(%rbp), %rdi
leaq 0x2f71c(%rip), %rsi     # 0x67667
callq 0x3f910
movq %rax, %rsi
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x77d0
movq -0x270(%rbp), %rdi
leaq 0x2f703(%rip), %rsi     # 0x67671
callq 0x3f910
movq %rax, %rsi
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
callq 0x77d0
movq -0x270(%rbp), %rdi
leaq 0x2f6e8(%rip), %rsi     # 0x67679
callq 0x3f910
movq %rax, %rsi
movq -0x18(%rbp), %rdi
subq $-0x80, %rdi
callq 0x77d0
movq -0x270(%rbp), %rdi
leaq 0x2f6cd(%rip), %rsi     # 0x67681
callq 0x3f910
movq %rax, %rsi
movq -0x18(%rbp), %rdi
addq $0xa0, %rdi
callq 0x77d0
movq -0x270(%rbp), %rdi
leaq 0x2f6b1(%rip), %rsi     # 0x6768b
callq 0x3f910
movq %rax, -0x268(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x7a30
movq -0x268(%rbp), %rsi
movq -0x260(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x8cf0
jmp 0x3800f
xorl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdi
movl $0xa, %edx
callq 0x3bbb0
movl %eax, -0x274(%rbp)
jmp 0x38029
movl -0x274(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xd8(%rax)
leaq -0x40(%rbp), %rdi
callq 0x7380
leaq -0x41(%rbp), %rdi
callq 0x75c0
leaq 0x2f640(%rip), %rsi     # 0x67692
leaq -0x20(%rbp), %rdi
callq 0x3f910
movq %rax, -0x288(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x7a30
movq -0x288(%rbp), %rsi
movq -0x280(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x8cf0
jmp 0x3808b
xorl %eax, %eax
movl %eax, %esi
leaq -0x78(%rbp), %rdi
movl $0xa, %edx
callq 0x3bbb0
movl %eax, -0x28c(%rbp)
jmp 0x380a5
movl -0x28c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xdc(%rax)
leaq -0x78(%rbp), %rdi
callq 0x7380
leaq -0x79(%rbp), %rdi
callq 0x75c0
leaq -0xb8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq 0x2f5c2(%rip), %rdx     # 0x6769b
callq 0x3edf0
leaq -0xb8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0xde10
movq -0x88(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0xde40
leaq -0xd0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x44270
testb $0x1, %al
jne 0x3812e
jmp 0x38315
leaq -0xd0(%rbp), %rdi
callq 0x442c0
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
leaq 0x2e5b7(%rip), %rsi     # 0x66702
leaq -0xf0(%rbp), %rdi
callq 0x3f240
movq %rax, -0x118(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x3e050
movq %rax, -0x2a0(%rbp)
leaq -0x119(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x7a30
movq -0x2a0(%rbp), %rsi
movq -0x298(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x8cf0
jmp 0x381a0
leaq -0x119(%rbp), %rdi
callq 0x75c0
leaq -0xf0(%rbp), %rdi
callq 0x3f810
movq %rax, -0x2a8(%rbp)
jmp 0x381c1
leaq -0x141(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x7a30
movq -0x2a8(%rbp), %rsi
movq -0x2b0(%rbp), %rdx
leaq -0x140(%rbp), %rdi
callq 0x8cf0
jmp 0x381f0
leaq -0x141(%rbp), %rdi
callq 0x75c0
movq -0x18(%rbp), %rdi
addq $0xc0, %rdi
leaq -0x110(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x3bbf0
jmp 0x3821c
leaq -0x140(%rbp), %rdi
callq 0x7380
leaq -0x110(%rbp), %rdi
callq 0x7380
leaq -0xd0(%rbp), %rdi
callq 0x44360
jmp 0x38112
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x38268
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7380
leaq -0x41(%rbp), %rdi
callq 0x75c0
jmp 0x38506
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x38299
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x7380
leaq -0x79(%rbp), %rdi
callq 0x75c0
jmp 0x38506
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x119(%rbp), %rdi
callq 0x75c0
jmp 0x38506
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x38304
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x141(%rbp), %rdi
callq 0x75c0
jmp 0x38304
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x7380
leaq -0x110(%rbp), %rdi
callq 0x7380
jmp 0x38506
leaq -0x20(%rbp), %rdi
leaq 0x2e315(%rip), %rsi     # 0x66635
callq 0x3eeb0
movq %rax, -0x190(%rbp)
leaq -0x190(%rbp), %rdi
leaq 0x2e2fe(%rip), %rsi     # 0x66638
callq 0x3eeb0
movq %rax, -0x188(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x188(%rbp), %rsi
leaq 0x2e2eb(%rip), %rdx     # 0x66646
callq 0x3edf0
leaq -0x180(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0xde10
movq -0x150(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0xde40
leaq -0x1a8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x44270
testb $0x1, %al
jne 0x383ad
jmp 0x38407
leaq -0x1a8(%rbp), %rdi
callq 0x442c0
movq (%rax), %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x18(%rbp), %rdx
movq -0x1d0(%rbp), %rdi
movl $0x1, %esi
callq 0x38510
cmpl $-0x1, %eax
jne 0x383f7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x384fa
jmp 0x383f9
leaq -0x1a8(%rbp), %rdi
callq 0x44360
jmp 0x38394
leaq -0x20(%rbp), %rdi
leaq 0x2e223(%rip), %rsi     # 0x66635
callq 0x3eeb0
movq %rax, -0x218(%rbp)
leaq -0x218(%rbp), %rdi
leaq 0x2e229(%rip), %rsi     # 0x66655
callq 0x3eeb0
movq %rax, -0x210(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x210(%rbp), %rsi
leaq 0x2e1f9(%rip), %rdx     # 0x66646
callq 0x3edf0
leaq -0x208(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0xde10
movq -0x1d8(%rbp), %rsi
leaq -0x248(%rbp), %rdi
callq 0xde40
leaq -0x230(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x44270
testb $0x1, %al
jne 0x3849f
jmp 0x384f3
leaq -0x230(%rbp), %rdi
callq 0x442c0
movq (%rax), %rax
movq %rax, -0x250(%rbp)
movq -0x250(%rbp), %rax
movq %rax, -0x258(%rbp)
movq -0x18(%rbp), %rdx
movq -0x258(%rbp), %rdi
xorl %esi, %esi
callq 0x38510
cmpl $-0x1, %eax
jne 0x384e3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x384fa
jmp 0x384e5
leaq -0x230(%rbp), %rdi
callq 0x44360
jmp 0x38486
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x7a20
nop