// File: jpcima[P]faustmd/call_faust.cpp
// Function: call_faust(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, pugi::xml_document&, Faust_Args const&)
int call_faust(const std::string &dspfile, pugi::xml_document &docmd, const Faust_Args &faustargs)
{
    char workdir[] = P_tmpdir "/faustXXXXXX";
    if (mktempdir(workdir) == -1)
        return 1;
    auto workdir_cleanup = gsl::finally([&]() { rmdir(workdir); });

    gsl::cstring_span dspfilebase = dspfile;
    {
        size_t index = dspfile.rfind('/');
        if (index != std::string::npos)
            dspfilebase = dspfilebase.subspan(index + 1);
    }

    const std::string xmlfilebase = gsl::to_string(dspfilebase) + ".xml";
    const std::string cppfilebase = gsl::to_string(dspfilebase) + ".cpp";
    const std::string xmlfile = std::string(workdir) + '/' + xmlfilebase;
    const std::string cppfile = std::string(workdir) + '/' + cppfilebase;

    std::vector<char *> fargv {
        (char *)"faust",
        (char *)"-double",
        (char *)"-xml",
        (char *)"-O",
        (char *)workdir,
        (char *)"-o",
        (char *)cppfilebase.c_str(),
        (char *)dspfile.c_str(),
    };

    if (const char *program = getenv("FAUST"))
        fargv[0] = (char *)program;

    for (const std::string &dir : faustargs.incdirs) {
        fargv.push_back((char *)"-I");
        fargv.push_back((char *)dir.c_str());
    }

    if (!faustargs.classname.empty()) {
        fargv.push_back((char *)"-cn");
        fargv.push_back((char *)faustargs.classname.c_str());
    }
    if (!faustargs.processname.empty()) {
        fargv.push_back((char *)"-pn");
        fargv.push_back((char *)faustargs.processname.c_str());
    }

    for (const std::string &arg : faustargs.miscargs)
        fargv.push_back((char *)arg.c_str());

    fargv.push_back(nullptr);
    if (execute(fargv.data()) == -1)
        return -1;

    auto xml_cleanup =
        gsl::finally([&]() { unlink(xmlfile.c_str()); unlink(cppfile.c_str()); });

    pugi::xml_parse_result xmlret = docmd.load_file(xmlfile.c_str());
    if (!xmlret)
        return -1;

    if (apply_workarounds(docmd, cppfile) == -1)
        return -1;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x380, %rsp            # imm = 0x380
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq 0x5af12(%rip), %rax     # 0x665d0
movq %rax, -0x40(%rbp)
movq 0x5af0f(%rip), %rax     # 0x665d8
movq %rax, -0x38(%rbp)
movb 0x5af0d(%rip), %al      # 0x665e0
movb %al, -0x30(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xbf80
cmpl $-0x1, %eax
jne 0xb6f0
movl $0x1, -0x4(%rbp)
jmp 0xbf66
leaq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xc150
movq -0x10(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xd840
jmp 0xb714
movq -0x10(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x7b40
movq %rax, -0x88(%rbp)
cmpq $-0x1, -0x88(%rbp)
je 0xb7a2
movq -0x88(%rbp), %rsi
incq %rsi
leaq -0x70(%rbp), %rdi
callq 0xd890
movq %rdx, -0x340(%rbp)
movq %rax, -0x338(%rbp)
jmp 0xb75d
movq -0x340(%rbp), %rax
movq -0x338(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0x90(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0xb7a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbf5b
leaq -0xd8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xd920
jmp 0xb7b4
leaq 0x5ae56(%rip), %rdx     # 0x66611
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xd8d0
jmp 0xb7d0
leaq -0xd8(%rbp), %rdi
callq 0x7380
leaq -0x118(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xd920
jmp 0xb7ee
leaq 0x5c286(%rip), %rdx     # 0x67a7b
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xd8d0
jmp 0xb80a
leaq -0x118(%rbp), %rdi
callq 0x7380
leaq -0x179(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x7a30
movq -0x348(%rbp), %rdx
leaq -0x178(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x8cf0
jmp 0xb842
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
movl $0x2f, %edx
callq 0xda00
jmp 0xb85c
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0xd9b0
jmp 0xb878
leaq -0x158(%rbp), %rdi
callq 0x7380
leaq -0x178(%rbp), %rdi
callq 0x7380
leaq -0x179(%rbp), %rdi
callq 0x75c0
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0x7a30
movq -0x350(%rbp), %rdx
leaq -0x1e0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x8cf0
jmp 0xb8c8
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
movl $0x2f, %edx
callq 0xda00
jmp 0xb8e2
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0xd9b0
jmp 0xb8fe
leaq -0x1c0(%rbp), %rdi
callq 0x7380
leaq -0x1e0(%rbp), %rdi
callq 0x7380
leaq -0x1e1(%rbp), %rdi
callq 0x75c0
leaq 0x5aced(%rip), %rax     # 0x66616
movq %rax, -0x250(%rbp)
leaq 0x5ace5(%rip), %rax     # 0x6661c
movq %rax, -0x248(%rbp)
leaq 0x5acdf(%rip), %rax     # 0x66624
movq %rax, -0x240(%rbp)
leaq 0x5acd6(%rip), %rax     # 0x66629
movq %rax, -0x238(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq 0x5acc0(%rip), %rax     # 0x6662c
movq %rax, -0x228(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x71f0
movq %rax, -0x220(%rbp)
movq -0x10(%rbp), %rdi
callq 0x71f0
movq %rax, -0x218(%rbp)
leaq -0x250(%rbp), %rax
movq %rax, -0x210(%rbp)
movq $0x8, -0x208(%rbp)
leaq -0x251(%rbp), %rdi
movq %rdi, -0x358(%rbp)
callq 0xda50
movq -0x358(%rbp), %rcx
movq -0x210(%rbp), %rsi
movq -0x208(%rbp), %rdx
leaq -0x200(%rbp), %rdi
callq 0xda70
jmp 0xb9e5
leaq -0x251(%rbp), %rdi
callq 0xdaf0
leaq 0x5ac37(%rip), %rdi     # 0x6662f
callq 0x76b0
movq %rax, -0x260(%rbp)
cmpq $0x0, -0x260(%rbp)
je 0xbb49
movq -0x260(%rbp), %rax
movq %rax, -0x360(%rbp)
leaq -0x200(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xdb10
movq -0x360(%rbp), %rcx
movq %rcx, (%rax)
jmp 0xbb49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x7380
jmp 0xbf5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbf4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x7380
jmp 0xbf4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbaca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbabe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x7380
leaq -0x178(%rbp), %rdi
callq 0x7380
leaq -0x179(%rbp), %rdi
callq 0x75c0
jmp 0xbf43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbb1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbb0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x7380
leaq -0x1e0(%rbp), %rdi
callq 0x7380
leaq -0x1e1(%rbp), %rdi
callq 0x75c0
jmp 0xbf37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x251(%rbp), %rdi
callq 0xdaf0
jmp 0xbf2b
movq -0x20(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x268(%rbp)
movq -0x268(%rbp), %rdi
callq 0xdb30
movq %rax, -0x270(%rbp)
movq -0x268(%rbp), %rdi
callq 0xdb60
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0xdb90
testb $0x1, %al
jne 0xbb9a
jmp 0xbc1c
leaq -0x270(%rbp), %rdi
callq 0xdbd0
movq %rax, -0x280(%rbp)
leaq 0x5a4e1(%rip), %rax     # 0x66095
movq %rax, -0x288(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0xdbf0
jmp 0xbbd0
movq -0x280(%rbp), %rdi
callq 0x71f0
movq %rax, -0x290(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0xdbf0
jmp 0xbbf8
jmp 0xbbfa
leaq -0x270(%rbp), %rdi
callq 0xdc20
jmp 0xbb7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbf1f
movq -0x20(%rbp), %rdi
callq 0x7960
testb $0x1, %al
jne 0xbc73
leaq 0x5a48d(%rip), %rax     # 0x660bd
movq %rax, -0x298(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0xdbf0
jmp 0xbc4c
movq -0x20(%rbp), %rdi
callq 0x71f0
movq %rax, -0x2a0(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xdbf0
jmp 0xbc71
jmp 0xbc73
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x7960
testb $0x1, %al
jne 0xbcd2
leaq 0x5a45c(%rip), %rax     # 0x660e7
movq %rax, -0x2a8(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0xdbf0
jmp 0xbca7
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x71f0
movq %rax, -0x2b0(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0xdbf0
jmp 0xbcd0
jmp 0xbcd2
movq -0x20(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x2b8(%rbp)
movq -0x2b8(%rbp), %rdi
callq 0xdb30
movq %rax, -0x2c0(%rbp)
movq -0x2b8(%rbp), %rdi
callq 0xdb60
movq %rax, -0x2c8(%rbp)
leaq -0x2c0(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0xdb90
testb $0x1, %al
jne 0xbd20
jmp 0xbd6b
leaq -0x2c0(%rbp), %rdi
callq 0xdbd0
movq %rax, -0x2d0(%rbp)
movq -0x2d0(%rbp), %rdi
callq 0x71f0
movq %rax, -0x2d8(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0xdbf0
jmp 0xbd5b
jmp 0xbd5d
leaq -0x2c0(%rbp), %rdi
callq 0xdc20
jmp 0xbd07
movq $0x0, -0x2e0(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0xdbf0
jmp 0xbd8b
leaq -0x200(%rbp), %rdi
callq 0xdc40
movq %rax, %rdi
callq 0xc190
movl %eax, -0x364(%rbp)
jmp 0xbda7
movl -0x364(%rbp), %eax
cmpl $-0x1, %eax
jne 0xbdc8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x2e4(%rbp)
jmp 0xbed8
leaq -0x138(%rbp), %rax
movq %rax, -0x378(%rbp)
movq %rax, -0x318(%rbp)
leaq -0x1a0(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x308(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0xc350
movq -0x378(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x370(%rbp)
callq 0x71f0
movq -0x370(%rbp), %rsi
movq %rax, %rdx
leaq -0x330(%rbp), %rdi
movl $0x74, %ecx
xorl %r8d, %r8d
callq 0x45420
jmp 0xbe35
leaq -0x330(%rbp), %rdi
callq 0x44530
movb %al, -0x379(%rbp)
jmp 0xbe49
movb -0x379(%rbp), %al
testb $0x1, %al
jne 0xbe85
jmp 0xbe55
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x2e4(%rbp)
jmp 0xbecc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x308(%rbp), %rdi
callq 0xd0b0
jmp 0xbf1f
movq -0x18(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0xc3a0
movl %eax, -0x380(%rbp)
jmp 0xbe9d
movl -0x380(%rbp), %eax
cmpl $-0x1, %eax
jne 0xbebb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x2e4(%rbp)
jmp 0xbecc
movl $0x0, -0x4(%rbp)
movl $0x1, -0x2e4(%rbp)
leaq -0x308(%rbp), %rdi
callq 0xd0b0
leaq -0x200(%rbp), %rdi
callq 0xdc60
leaq -0x1a0(%rbp), %rdi
callq 0x7380
leaq -0x138(%rbp), %rdi
callq 0x7380
leaq -0xf8(%rbp), %rdi
callq 0x7380
leaq -0xb8(%rbp), %rdi
callq 0x7380
leaq -0x58(%rbp), %rdi
callq 0xd100
jmp 0xbf66
leaq -0x200(%rbp), %rdi
callq 0xdc60
leaq -0x1a0(%rbp), %rdi
callq 0x7380
leaq -0x138(%rbp), %rdi
callq 0x7380
leaq -0xf8(%rbp), %rdi
callq 0x7380
leaq -0xb8(%rbp), %rdi
callq 0x7380
leaq -0x58(%rbp), %rdi
callq 0xd100
jmp 0xbf72
movl -0x4(%rbp), %eax
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x7a20
nopl (%rax,%rax)