// File: /workspace/github_c_makefile_star2_O1/rakitzis[P]rc/which.c
// Function: which
extern char *which(char *name, bool verbose) {
	static char *test = NULL;
	static size_t testlen = 0;
	List *path;
	int len;
	struct stat st;
	if (name == NULL)	/* no filename? can happen with "> foo" as a command */
		return NULL;
	if (!initialized) {
		initialized = TRUE;
		uid = geteuid();
		gid = getegid();
#if HAVE_GETGROUPS
#if HAVE_POSIX_GETGROUPS
		ngroups = getgroups(0, (GETGROUPS_T *)0);
		if (ngroups < 0) {
			uerror("getgroups");
			rc_exit(1);
		}
#else
		ngroups = NGROUPS;
#endif
		if (ngroups) {	
			gidset = ealloc(ngroups * sizeof(GETGROUPS_T));
			getgroups(ngroups, gidset);
		}
#endif
	}
	if (isabsolute(name)) /* absolute pathname? */
		return rc_access(name, verbose, &st) ? name : NULL;
	len = strlen(name);
	for (path = varlookup("path"); path != NULL; path = path->n) {
		size_t need = strlen(path->w) + len + 2; /* one for null terminator, one for the '/' */
		if (testlen < need) {
			efree(test);
			test = ealloc(testlen = need);
		}
		if (*path->w == '\0') {
			strcpy(test, name);
		} else {
			strcpy(test, path->w);
			if (!streq(test, "/")) /* "//" is special to POSIX */
				strcat(test, "/");
			strcat(test, name);
		}
		if (rc_access(test, FALSE, &st))
			return test;
	}
	if (verbose)
		fprint(2, RC "cannot find `%s'\n", name);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
testq %rdi, %rdi
je 0xe188
movl %esi, %ebp
movq %rdi, %rbx
cmpb $0x0, 0xd01d(%rip)      # 0x1aff8
jne 0xe04d
movb $0x1, 0xd014(%rip)      # 0x1aff8
callq 0x3160
movl %eax, 0xcff1(%rip)      # 0x1afe0
callq 0x3280
movl %eax, 0xcfea(%rip)      # 0x1afe4
xorl %edi, %edi
xorl %esi, %esi
callq 0x3260
movl %eax, 0xcff3(%rip)      # 0x1affc
testl %eax, %eax
jns 0xe023
leaq 0x6714(%rip), %rdi      # 0x14728
callq 0xc7ed
movl $0x1, %edi
callq 0x4fb5
movslq 0xcfd2(%rip), %rdi      # 0x1affc
testq %rdi, %rdi
je 0xe04d
shlq $0x2, %rdi
callq 0xa0c4
movq %rax, 0xcfc1(%rip)      # 0x1b000
movl 0xcfb7(%rip), %edi      # 0x1affc
movq %rax, %rsi
callq 0x3260
movq %rbx, %rdi
callq 0xc8c8
testl %eax, %eax
je 0xe076
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdf04
xorl %r14d, %r14d
testl %eax, %eax
cmovneq %rbx, %r14
jmp 0xe18b
movl %ebp, 0x4(%rsp)
movq %rbx, %rdi
callq 0x30f0
movq %rax, %r14
leaq 0x104f(%rip), %rdi      # 0xf0db
callq 0xcaf4
testq %rax, %rax
je 0xe166
movq %rax, %r15
movslq %r14d, %rbp
addq $0x2, %rbp
leaq 0x8(%rsp), %r12
movq (%r15), %rdi
callq 0x30f0
movq %rax, %r13
addq %rbp, %r13
cmpq %r13, 0xcf32(%rip)      # 0x1aff0
jae 0xe0e2
movq 0xcf21(%rip), %rdi      # 0x1afe8
callq 0xa095
movq %r13, 0xcf1d(%rip)      # 0x1aff0
movq %r13, %rdi
callq 0xa0c4
movq %rax, 0xcf06(%rip)      # 0x1afe8
movq (%r15), %rsi
cmpb $0x0, (%rsi)
movq 0xcef9(%rip), %r13      # 0x1afe8
je 0xe130
movq %r13, %rdi
callq 0x3070
cmpb $0x2f, (%r13)
jne 0xe113
movq %r13, %rdi
leaq 0xfca(%rip), %rsi       # 0xf0d4
callq 0x31f0
testl %eax, %eax
je 0xe123
movq %r13, %rdi
callq 0x30f0
movw $0x2f, (%r13,%rax)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3310
jmp 0xe13b
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3070
movq 0xcea6(%rip), %rdi      # 0x1afe8
xorl %esi, %esi
movq %r12, %rdx
callq 0xdf04
testl %eax, %eax
je 0xe157
movq 0xce91(%rip), %r14      # 0x1afe8
jne 0xe18b
movq 0x10(%r15), %r15
testq %r15, %r15
jne 0xe0a9
cmpl $0x0, 0x4(%rsp)
je 0xe188
leaq 0x65be(%rip), %rsi      # 0x14732
xorl %r14d, %r14d
movl $0x2, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xb06f
jmp 0xe18b
xorl %r14d, %r14d
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq