// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro11/util.c
// Function: my_searchenv2
static void my_searchenv2(
    char *name,
    char *envname,
    char *hitfile,
    int hitlen)
{
    char           *env;
    char           *envcopy;
    char           *envcopy2;
    char           *cp;
    char           *last;

    *hitfile = 0;                      /* Default failure indication */

    /* Note: If the given name is absolute, then don't search the
       path, but use it as is. */

    if (
#ifdef WIN32
           strchr(name, ':') != NULL || /* Contain a drive spec? */
           name[0] == '\\' ||          /* Start with absolute ref? */
#endif
           name[0] == '/') {           /* Start with absolute ref? */
        strncpy(hitfile, name, hitlen); /* Copy to target */
        return;
    }

    env = getenv(envname);
    if (env == NULL) {                 /* If not defined, search in */
        env = ".";                     /* current directory */
    }

    envcopy = strdup(env);             /* strtok destroys its text
                                          argument.  I don't want the return
                                          value from getenv destroyed. */

    envcopy2 = envcopy;
    while ((cp = strtok_r(envcopy2, PATHSEP, &last)) != NULL) {
        struct stat     info;
        char           *concat = malloc(strlen(cp) + strlen(name) + 2);

        if (concat == NULL) {
            free(envcopy);
            return;
        }
        strcpy(concat, cp);
        if (concat[strlen(concat) - 1] != '/')
            strcat(concat, "/");
        strcat(concat, name);
        if (!stat(concat, &info)) {
            /* Copy the file name to hitfile.  Assure that it's really
               zero-delimited. */
            strncpy(hitfile, concat, hitlen - 1);
            hitfile[hitlen - 1] = 0;
            free(envcopy);
            return;
        }
        envcopy2 = NULL;
    }

    /* If I fall out of that loop, then hitfile indicates no match,
       and return. */
    free(envcopy);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %ecx, %ebp
movq %rdx, %rbx
movq %rdi, %r14
movb $0x0, (%rdx)
cmpb $0x2f, (%rdi)
jne 0xe44a
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2080
movq %rsi, %rdi
callq 0x2040
testq %rax, %rax
leaq 0x1240(%rip), %rdi      # 0xf69c
cmovneq %rax, %rdi
callq 0x22e0
movq %rax, %r13
movslq %ebp, %rax
decq %rax
movq %rax, 0x8(%rsp)
movq %r13, %r15
movq %r15, %rdi
leaq 0xefe(%rip), %rsi       # 0xf37e
leaq 0x10(%rsp), %rdx
callq 0x2190
testq %rax, %rax
je 0xe536
movq %rax, %r12
movq %rax, %rdi
callq 0x20e0
movq %rax, %rbp
movq %r14, %rdi
callq 0x20e0
leaq (%rax,%rbp), %rdi
addq $0x2, %rdi
callq 0x2230
testq %rax, %rax
je 0xe522
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
callq 0x2090
movq %rbp, %rdi
callq 0x20e0
cmpb $0x2f, -0x1(%rbp,%rax)
je 0xe4e7
movq %rbp, %rdi
callq 0x20e0
movw $0x2f, (%rbp,%rax)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x22a0
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x2200
testl %eax, %eax
je 0xe50a
movb $0x1, %al
xorl %r15d, %r15d
jmp 0xe52c
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x8(%rsp), %r12
movq %r12, %rdx
callq 0x2080
movb $0x0, (%rbx,%r12)
movq %r13, %rdi
callq 0x2050
xorl %eax, %eax
testb %al, %al
jne 0xe476
jmp 0xe53e
movq %r13, %rdi
callq 0x2050
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq