// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: load_shared_object
static bool load_shared_object(s7_scheme *sc, const char *fname, s7_pointer env)
    {
        /* if fname ends in .so, try loading it as a c shared object
         *   (load "/home/bil/cl/m_j0.so" (inlet 'init_func 'init_m_j0))
         */
        s7_int fname_len;

        fname_len = safe_strlen(fname);
        if ((fname_len > 3) &&
                (local_strcmp((const char *)(fname + (fname_len - 3)), ".so")))
        {
            void *library;
            char *pwd_name;
            block_t *pname = NULL;

            if (fname[0] != '/')
            {
                block_t *searched;
                searched = search_load_path(sc, fname); /* returns NULL if *load-path* is nil, or if nothing matches */
                if (searched)
                {
                    if (((const char *)block_data(searched))[0] == '/')
                        pname = searched;
                    else
                    {
                        pname = full_filename(sc, (const char *)block_data(searched)); /* this is necessary, at least in Linux -- we can't blithely dlopen whatever is passed to us */
                        liberate(sc, searched);
                    }
                    pwd_name = (char *)block_data(pname);
                }
                else /* perhaps no *load-path* entries */
                {
                    pname = full_filename(sc, fname);
                    pwd_name = (char *)block_data(pname);
                }
            }
            /* else pname is NULL, so use fname */
            library = dlopen((pname) ? pwd_name : fname, RTLD_NOW);
            if (library)
            {
                if (env) /* look for 'init_func in env */
                {
                    s7_pointer init;

                    init = s7_let_ref(sc, env, make_symbol(sc, "init_func"));
                    if (is_symbol(init))
                    {
                        const char *init_name;
                        void *init_func;

                        init_name = symbol_name(init);
                        init_func = dlsym(library, init_name);
                        if (init_func)
                        {
                            typedef void *(*dl_func)(s7_scheme *sc);
                            ((dl_func)init_func)(sc);
                            if (pname) liberate(sc, pname);
                            return(true);
                        }
                        s7_warn(sc, 512, "loaded %s, but can't find %s (%s)?\n", fname, init_name, dlerror());
                        dlclose(library);
                    }
                    else s7_warn(sc, 512, "can't load %s: no init function\n", fname);
                    return(false);
                }
            }
            else s7_warn(sc, 512, "load %s failed: %s\n", (pname) ? pwd_name : fname, dlerror());
            if (pname) liberate(sc, pname);
        }
        return(false);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0x3571b
movq %rsi, %r14
movb (%rsi), %al
testb %al, %al
je 0x3571b
movq %rdx, %r12
movq %rdi, %rbx
xorl %ecx, %ecx
cmpb $0x0, 0x1(%r14,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x35542
cmpq $0x4, %rcx
jl 0x3571b
xorl %edx, %edx
leaq 0xe1511(%rip), %rsi     # 0x116a72
leaq (%r14,%rdx), %rdi
movb -0x3(%rcx,%rdi), %dil
movb (%rdx,%rsi), %r8b
testb %dil, %dil
je 0x3557b
incq %rdx
cmpb %r8b, %dil
je 0x35561
cmpb %r8b, %dil
jne 0x3571b
cmpb $0x2f, %al
jne 0x3558d
xorl %r15d, %r15d
jmp 0x3560c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x94c90
testq %rax, %rax
je 0x355e2
movq %rax, %r15
movq (%rax), %rsi
cmpb $0x2f, (%rsi)
je 0x35609
movq %rbx, %rdi
callq 0x94e45
movq %rax, %r13
movslq 0x8(%r15), %rax
cmpq $0x11, %rax
jne 0x355f2
movq (%r15), %rdi
testq %rdi, %rdi
je 0x355d1
callq 0x8050
movq $0x0, (%r15)
movl $0x0, 0x8(%r15)
leaq 0x838(%rbx), %rax
jmp 0x355fc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x94e45
movq %rax, %r15
jmp 0x35609
leaq (%rbx,%rax,8), %rax
addq $0x838, %rax            # imm = 0x838
movq (%rax), %rcx
movq %rcx, 0x18(%r15)
movq %r15, (%rax)
movq %r13, %r15
movq (%r15), %rbp
testq %r15, %r15
cmoveq %r14, %rbp
movq %rbp, %rdi
movl $0x2, %esi
callq 0x8380
testq %rax, %rax
je 0x35694
testq %r12, %r12
je 0x356b5
movq %rax, %r13
leaq 0xe143e(%rip), %rsi     # 0x116a76
movq %rbx, %rdi
callq 0x9afc
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xb54b
cmpb $0xa, (%rax)
jne 0x356e9
movq 0x8(%rax), %rax
movq 0x10(%rax), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x85d0
testq %rax, %rax
je 0x3572e
movq %rbx, %rdi
callq *%rax
movb $0x1, %bpl
testq %r15, %r15
je 0x3571d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9a12
jmp 0x3571d
callq 0x8040
leaq 0xe1425(%rip), %rdx     # 0x116ac5
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
movq %rbp, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xeea2
testq %r15, %r15
je 0x3571b
movslq 0x8(%r15), %rax
cmpq $0x11, %rax
jne 0x35706
movq (%r15), %rdi
testq %rdi, %rdi
je 0x356d8
callq 0x8050
movq $0x0, (%r15)
movl $0x0, 0x8(%r15)
addq $0x838, %rbx            # imm = 0x838
jmp 0x35711
leaq 0xe13b4(%rip), %rdx     # 0x116aa4
xorl %ebp, %ebp
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0xeea2
jmp 0x3571d
leaq (%rbx,%rax,8), %rbx
addq $0x838, %rbx            # imm = 0x838
movq (%rbx), %rax
movq %rax, 0x18(%r15)
movq %r15, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x8040
leaq 0xe1346(%rip), %rdx     # 0x116a80
xorl %ebp, %ebp
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
movq %r14, %rcx
movq %r12, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0xeea2
movq %r13, %rdi
callq 0x86d0
jmp 0x3571d