// File: /workspace/github_c_makefile_star2_O2/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 0xd645
movl %esi, %ebp
movq %rdi, %rbx
cmpb $0x0, 0xdb45(%rip)      # 0x1aff8
jne 0xd524
movb $0x1, 0xdb3c(%rip)      # 0x1aff8
callq 0x3160
movl %eax, 0xdb19(%rip)      # 0x1afe0
callq 0x3280
movl %eax, 0xdb12(%rip)      # 0x1afe4
xorl %edi, %edi
xorl %esi, %esi
callq 0x3260
movl %eax, 0xdb1b(%rip)      # 0x1affc
testl %eax, %eax
jns 0xd4ff
leaq 0x628c(%rip), %rdi      # 0x13778
callq 0xbe9d
pushq $0x1
popq %rdi
callq 0x4d65
movl 0xdafd(%rip), %eax      # 0x1affc
testl %eax, %eax
je 0xd524
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x9a83
movq %rax, 0xdaea(%rip)      # 0x1b000
movl 0xdae0(%rip), %edi      # 0x1affc
movq %rax, %rsi
callq 0x3260
movq %rbx, %rdi
callq 0xbf5d
testl %eax, %eax
je 0xd54d
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0xd3e0
xorl %r14d, %r14d
testl %eax, %eax
cmovneq %rbx, %r14
jmp 0xd651
movl %ebp, 0x4(%rsp)
movq %rbx, %rdi
callq 0x30f0
movq %rax, %r15
leaq 0xb74(%rip), %rdi       # 0xe0d7
callq 0xc16d
movq %rax, %r14
movslq %r15d, %rbp
addq $0x2, %rbp
leaq 0x8(%rsp), %r15
testq %r14, %r14
je 0xd625
movq (%r14), %r13
movq %r13, %rdi
callq 0x30f0
movq %rax, %r12
addq %rbp, %r12
cmpq %r12, 0xda58(%rip)      # 0x1aff0
jae 0xd5bf
movq 0xda47(%rip), %rdi      # 0x1afe8
callq 0x9a5c
movq %r12, 0xda43(%rip)      # 0x1aff0
movq %r12, %rdi
callq 0x9a83
movq %rax, 0xda2c(%rip)      # 0x1afe8
movq (%r14), %r13
cmpb $0x0, (%r13)
movq 0xda1d(%rip), %r12      # 0x1afe8
movq %r12, %rdi
je 0xd603
movq %r13, %rsi
callq 0x3070
cmpb $0x2f, (%r12)
jne 0xd5e7
cmpb $0x0, 0x1(%r12)
je 0xd5f6
movq %r12, %rdi
callq 0x30f0
movw $0x2f, (%r12,%rax)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3310
jmp 0xd60b
movq %rbx, %rsi
callq 0x3070
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0xd3e0
testl %eax, %eax
jne 0xd64a
movq 0x10(%r14), %r14
jmp 0xd577
cmpl $0x0, 0x4(%rsp)
je 0xd645
leaq 0x614f(%rip), %rsi      # 0x13782
xorl %r14d, %r14d
pushq $0x2
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa8f6
jmp 0xd651
xorl %r14d, %r14d
jmp 0xd651
movq 0xd997(%rip), %r14      # 0x1afe8
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq