// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x13813
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x2060
jmp 0x1397b
movq -0x10(%rbp), %rdi
callq 0x2030
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x13832
leaq 0x1714(%rip), %rax      # 0x14f42
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x22d0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq 0x11e4(%rip), %rsi      # 0x14a36
leaq -0x48(%rbp), %rdx
callq 0x2170
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x13972
movq -0x40(%rbp), %rdi
callq 0x20c0
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20c0
movq -0xe8(%rbp), %rdi
addq %rax, %rdi
addq $0x2, %rdi
callq 0x2220
movq %rax, -0xe0(%rbp)
cmpq $0x0, -0xe0(%rbp)
jne 0x138b4
movq -0x30(%rbp), %rdi
callq 0x2040
jmp 0x1397b
movq -0xe0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2070
movq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xe0(%rbp), %rdi
callq 0x20c0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0x13908
movq -0xe0(%rbp), %rdi
leaq 0x240f(%rip), %rsi      # 0x15d12
callq 0x2290
movq -0xe0(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2290
movq -0xe0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x21e0
cmpl $0x0, %eax
jne 0x13965
movq -0x18(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
callq 0x2060
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rdi
callq 0x2040
jmp 0x1397b
movq $0x0, -0x38(%rbp)
jmp 0x13847
movq -0x30(%rbp), %rdi
callq 0x2040
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop