// File: /workspace/github_cpp_makefile_star2_O2/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 0x1265
movq 0x8(%r12), %rdi
pushq $0x1
popq %rsi
callq 0x1090
testq %rax, %rax
je 0x127b
movq %rax, %rbx
leaq 0xe57(%rip), %rsi       # 0x204d
movq %rax, %rdi
callq 0x10a0
testq %rax, %rax
je 0x1296
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
pushq $0x2f
popq %rsi
movq %r12, %rdi
callq 0x1080
testq %rax, %rax
je 0x12a4
movq %rax, %r13
leaq 0x1(%rax), %rsi
movq %r15, %rdi
callq 0x1040
pushq $0x2e
popq %rsi
movq %r13, %rdi
callq 0x1080
notq %r13
addq %r15, %r13
movb $0x0, (%rax,%r13)
jmp 0x12db
movq (%r12), %rsi
leaq 0xd94(%rip), %rdi       # 0x2004
xorl %eax, %eax
callq 0x1070
pushq $0x1
jmp 0x1293
callq 0x1030
leaq 0xd9c(%rip), %rdi       # 0x2023
movq %rax, %rsi
xorl %eax, %eax
callq 0x1070
pushq $0x2
popq %rax
jmp 0x1303
leaq 0xded(%rip), %rdi       # 0x208a
callq 0x1050
jmp 0x12f9
cmpb $0x2e, (%r12)
jne 0x12d0
cmpb $0x2f, 0x1(%r12)
jne 0x12d0
leaq 0x2(%r12), %rsi
movq %r15, %rdi
callq 0x1040
pushq $0x2e
popq %rsi
movq %r15, %rdi
callq 0x1080
movb $0x0, (%rax)
jmp 0x12db
movq %r15, %rdi
movq %r12, %rsi
callq 0x1040
leaq 0xd7c(%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