// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movq %rdx, %rax
movq %rdi, %r14
movb $0x0, (%rdx)
cmpb $0x2f, (%rdi)
jne 0xce19
movslq %ecx, %rdx
movq %rax, %rdi
movq %r14, %rsi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2080
movl %ecx, 0xc(%rsp)
movq %rax, 0x18(%rsp)
movq %rsi, %rdi
callq 0x2040
testq %rax, %rax
leaq 0x185f(%rip), %rdi      # 0xe693
cmovneq %rax, %rdi
callq 0x22e0
leaq 0x1531(%rip), %r12      # 0xe375
leaq 0x20(%rsp), %r13
leaq 0x28(%rsp), %r15
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2190
testq %rax, %rax
je 0xcefe
movq %rax, %rbx
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 0xcefe
movq %rax, %rbp
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2090
movq %rbp, %rdi
callq 0x20e0
cmpb $0x2f, -0x1(%rbp,%rax)
je 0xcebe
movq %rbp, %rdi
callq 0x20e0
movw $0x2f, (%rbp,%rax)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x22a0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2200
testl %eax, %eax
je 0xcedf
xorl %edi, %edi
jmp 0xce56
movslq 0xc(%rsp), %rbx
leaq -0x1(%rbx), %rdx
movq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2080
movb $0x0, -0x1(%r14,%rbx)
movq 0x10(%rsp), %rdi
callq 0x2050
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop