// File: /workspace/github_c_makefile_star2_O1/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
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
testq %rsi, %rsi
je 0x37896
cmpb $0x0, (%r14)
je 0x37896
movq $-0x1, %rcx
leaq 0x1(%rcx), %rax
cmpb $0x0, 0x1(%r14,%rcx)
movq %rax, %rcx
jne 0x37885
jmp 0x37898
xorl %eax, %eax
cmpq $0x4, %rax
jl 0x37b4e
addq %r14, %rax
addq $-0x3, %rax
xorl %ecx, %ecx
leaq 0xe80b0(%rip), %rdx     # 0x11f962
movb (%rax,%rcx), %sil
movb (%rcx,%rdx), %dil
testb %sil, %sil
je 0x378c7
incq %rcx
cmpb %dil, %sil
je 0x378b2
cmpb %dil, %sil
jne 0x37b4e
cmpb $0x2f, (%r14)
jne 0x378de
xorl %r12d, %r12d
jmp 0x3796d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9b323
testq %rax, %rax
je 0x378fe
movq %rax, %r13
movq (%rax), %rsi
cmpb $0x2f, (%rsi)
jne 0x3790e
movq %r13, %r12
jmp 0x37969
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9b4ff
movq %rax, %r12
jmp 0x37969
movq %rbx, %rdi
callq 0x9b4ff
movq %rax, %r12
movslq 0x8(%r13), %rax
cmpq $0x11, %rax
jne 0x37955
movq (%r13), %rdi
testq %rdi, %rdi
je 0x37939
callq 0x9050
movq $0x0, (%r13)
movl $0x0, 0x8(%r13)
movq 0x838(%rbx), %rax
movq %rax, 0x18(%r13)
movq %r13, 0x838(%rbx)
jmp 0x37969
movq 0x838(%rbx,%rax,8), %rcx
movq %rcx, 0x18(%r13)
movq %r13, 0x838(%rbx,%rax,8)
movq (%r12), %rbp
testq %r12, %r12
cmoveq %r14, %rbp
movq %rbp, %rdi
movl $0x2, %esi
callq 0x9380
testq %rax, %rax
je 0x37a76
testq %r15, %r15
je 0x37a97
movq %rax, %r13
movabsq $0x6e75665f74696ecc, %rcx # imm = 0x6E75665F74696ECC
movq 0x148(%rbx), %rax
movq 0x10(%rax), %rax
movq 0xa20(%rax), %rax
cmpb $0x1, (%rax)
jne 0x37a07
leaq 0xe7fa8(%rip), %rdx     # 0x11f966
leaq -0x63(%rcx), %rsi
cmpq %rcx, 0x18(%rax)
jne 0x379fe
cmpl $0x9, 0x2c(%rax)
jne 0x379fe
movq 0x20(%rax), %rdi
cmpq %rsi, (%rdi)
jne 0x379fe
xorl %r8d, %r8d
movb 0x8(%r8,%rdx), %r9b
movb 0x8(%rdi,%r8), %r10b
cmpb %r10b, %r9b
jne 0x379f5
leaq 0x1(%r8), %r11
testq %r8, %r8
movq %r11, %r8
jne 0x379da
cmpb %r10b, %r9b
je 0x37b61
movq 0x10(%rax), %rax
cmpb $0x1, (%rax)
je 0x379c2
leaq 0xe7f58(%rip), %rsi     # 0x11f966
movl $0x9, %edx
movq %rbx, %rdi
movl $0x144, %r8d            # imm = 0x144
callq 0xa5ef
movq %rax, %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc3ac
cmpb $0xa, (%rax)
jne 0x37ade
movq 0x8(%rax), %rax
movq 0x10(%rax), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x95d0
movq %rax, %r15
testq %rax, %rax
je 0x37b10
movq %rbx, %rdi
callq *%r15
testq %r12, %r12
je 0x37b3c
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa9a3
jmp 0x37b3c
callq 0x9040
leaq 0xe7f33(%rip), %rdx     # 0x11f9b5
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
movq %rbp, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xfc3d
movb $0x1, %bpl
testq %r12, %r12
je 0x37b0e
movslq 0x8(%r12), %rax
cmpq $0x11, %rax
jne 0x37af9
movq (%r12), %rdi
testq %rdi, %rdi
je 0x37ac0
callq 0x9050
movq $0x0, (%r12)
movl $0x0, 0x8(%r12)
movq 0x838(%rbx), %rax
movq %rax, 0x18(%r12)
movq %r12, 0x838(%rbx)
jmp 0x37b0e
leaq 0xe7eaf(%rip), %rdx     # 0x11f994
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0xfc3d
jmp 0x37b45
movq 0x838(%rbx,%rax,8), %rcx
movq %rcx, 0x18(%r12)
movq %r12, 0x838(%rbx,%rax,8)
jmp 0x37b49
callq 0x9040
leaq 0xe7e54(%rip), %rdx     # 0x11f970
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
movq %r14, %rcx
movq %rbp, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0xfc3d
movq %r13, %rdi
callq 0x96d0
testq %r15, %r15
je 0x37b45
movb $0x1, %al
jmp 0x37b47
xorl %eax, %eax
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x37b50
xorl %eax, %eax
andb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rax), %rdx
jmp 0x37a24