// File: /workspace/github_cpp_makefile_star2_O1/osam-cologne[P]stereogain/dpf/utils/lv2-ttl-generator/lv2_ttl_generator.c
// Function: main
int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        printf("usage: %s /path/to/plugin-DLL\n", argv[0]);
        return 1;
    }

#ifdef TTL_GENERATOR_WINDOWS
    const HMODULE handle = LoadLibraryA(argv[1]);
#else
    void* const handle = dlopen(argv[1], RTLD_LAZY);
#endif

    if (! handle)
    {
#ifdef TTL_GENERATOR_WINDOWS
        printf("Failed to open plugin DLL\n");
#else
        printf("Failed to open plugin DLL, error was:\n%s\n", dlerror());
#endif
        return 2;
    }

#ifdef TTL_GENERATOR_WINDOWS
    const TTL_Generator_Function ttlFn = (TTL_Generator_Function)GetProcAddress(handle, "lv2_generate_ttl");
#else
    const TTL_Generator_Function ttlFn = (TTL_Generator_Function)dlsym(handle, "lv2_generate_ttl");
#endif

    if (ttlFn != NULL)
    {
        char basename[strlen(argv[1])+1];

#ifdef TTL_GENERATOR_WINDOWS
        char* base2 = strrchr(argv[1], '\\');
#else
        char* base2 = strrchr(argv[1], '/');
#endif
        if (base2 != NULL)
        {
            strcpy(basename, base2+1);
            basename[strrchr(base2, '.')-base2-1] = '\0';
        }
        else if (argv[1][0] == '.' && argv[1][1] == '/')
        {
            strcpy(basename, argv[1]+2);
            basename[strrchr(basename, '.')-basename] = '\0';
        }
        else
        {
            strcpy(basename, argv[1]);
        }

        printf("Generate ttl data for '%s', basename: '%s'\n", argv[1], basename);

        ttlFn(basename);
    }
    else
        printf("Failed to find 'lv2_generate_ttl' function\n");

#ifdef TTL_GENERATOR_WINDOWS
    FreeLibrary(handle);
#else
    dlclose(handle);
#endif

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
cmpl $0x2, %edi
jne 0x126e
movq 0x8(%r12), %rdi
movl $0x1, %esi
callq 0x1090
testq %rax, %rax
je 0x128a
movq %rax, %rbx
leaq 0xe55(%rip), %rsi       # 0x204d
movq %rax, %rdi
callq 0x10a0
testq %rax, %rax
je 0x12a7
movq %rax, %r14
movq 0x8(%r12), %rdi
callq 0x1060
movq %rsp, -0x30(%rbp)
movq %rsp, %r15
addq $0x10, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq 0x8(%r12), %r12
movq %r12, %rdi
movl $0x2f, %esi
callq 0x1080
testq %rax, %rax
je 0x12b5
movq %rax, %r13
leaq 0x1(%rax), %rsi
movq %r15, %rdi
callq 0x1040
movq %r13, %rdi
movl $0x2e, %esi
callq 0x1080
notq %r13
addq %r15, %r13
movb $0x0, (%rax,%r13)
jmp 0x12ee
movq (%r12), %rsi
leaq 0xd8b(%rip), %rdi       # 0x2004
xorl %eax, %eax
callq 0x1070
movl $0x1, %eax
jmp 0x1316
callq 0x1030
leaq 0xd8d(%rip), %rdi       # 0x2023
movq %rax, %rsi
xorl %eax, %eax
callq 0x1070
movl $0x2, %eax
jmp 0x1316
leaq 0xddc(%rip), %rdi       # 0x208a
callq 0x1050
jmp 0x130c
cmpb $0x2e, (%r12)
jne 0x12e3
cmpb $0x2f, 0x1(%r12)
jne 0x12e3
leaq 0x2(%r12), %rsi
movq %r15, %rdi
callq 0x1040
movq %r15, %rdi
movl $0x2e, %esi
callq 0x1080
movb $0x0, (%rax)
jmp 0x12ee
movq %r15, %rdi
movq %r12, %rsi
callq 0x1040
leaq 0xd69(%rip), %rdi       # 0x205e
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1070
movq %r15, %rdi
callq *%r14
movq -0x30(%rbp), %rsp
movq %rbx, %rdi
callq 0x10b0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq