// File: /workspace/github_c_makefile_star2_O3/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
movq %rdx, %rbx
movq %rdi, %r14
movb $0x0, (%rdx)
cmpb $0x2f, (%rdi)
jne 0xe18d
movslq %ecx, %rdx
movq %rbx, %rdi
movq %r14, %rsi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2080
movl %ecx, 0x4(%rsp)
movq %rsi, %rdi
callq 0x2040
testq %rax, %rax
leaq 0x14f0(%rip), %rdi      # 0xf693
cmovneq %rax, %rdi
callq 0x22e0
leaq 0x11c2(%rip), %rsi      # 0xf375
leaq 0x10(%rsp), %rdx
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x2190
testq %rax, %rax
je 0xe284
movq %rax, %r13
leaq 0x18(%rsp), %r12
leaq 0x10(%rsp), %rbp
movq %r13, %rdi
callq 0x20e0
movq %rax, %r15
movq %r14, %rdi
callq 0x20e0
leaq (%r15,%rax), %rdi
addq $0x2, %rdi
callq 0x2230
testq %rax, %rax
je 0xe284
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
callq 0x2090
movq %r15, %rdi
callq 0x20e0
cmpb $0x2f, -0x1(%r15,%rax)
je 0xe231
movq %r15, %rdi
callq 0x20e0
movw $0x2f, (%r15,%rax)
movq %r15, %rdi
movq %r14, %rsi
callq 0x22a0
movq %r15, %rdi
movq %r12, %rsi
callq 0x2200
testl %eax, %eax
je 0xe26a
xorl %edi, %edi
leaq 0x1121(%rip), %rsi      # 0xf375
movq %rbp, %rdx
callq 0x2190
movq %rax, %r13
testq %rax, %rax
jne 0xe1db
jmp 0xe284
movslq 0x4(%rsp), %r14
leaq -0x1(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2080
movb $0x0, -0x1(%rbx,%r14)
movq 0x8(%rsp), %rdi
callq 0x2050
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq