// File: /workspace/github_c_makefile_star2_O1/ebiggers[P]mysh/mysh_param.c
// Function: lookup_param
const char *
lookup_param(const char *name, size_t len)
{
	static char buf[20];
	unsigned char char_type = shell_char_type(*name);
	if (char_type & SHELL_PARAM_NUMERIC_CHAR) {
		/* Positional parameter */
		unsigned n = 0;
		do {
			n *= 10;
			n += *name - '0';
		} while (--len);
		if (n > num_positional_parameters)
			return NULL;
		else
			return positional_parameters[n];
	} else if (char_type & SHELL_PARAM_SPECIAL_CHAR) {
		/* Special variable */
		switch (*name) {
		case '$':
			/* $$: Process ID */
			sprintf(buf, "%d", getpid());
			return buf;
		case '?':
			/* $?: Exit status of last command */
			sprintf(buf, "%d", mysh_last_exit_status);
			return buf;
		case '#':
			/* $#: Number of positional parameters */
			sprintf(buf, "%u", num_positional_parameters);
			return buf;
		case '!':
			/* $!: pid of last process in last background pipeline */
			if (mysh_last_background_pid == 0) {
				return NULL;
			} else {
				sprintf(buf, "%d", mysh_last_background_pid);
				return buf;
			}
		case '*':
		case '@': /* Note: $@ does not yet behave correctly (it's treated the same as $*) */
			/* All positional parameters */
			return get_all_positional_params();
		}
	} else {
		/* Regular variable; look it up in the trie. */
		return lookup_shell_param_len(name, len);
	}
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movzbl (%rdi), %eax
leaq 0x2c23(%rip), %rcx      # 0x7b10
movzbl (%rcx,%rax), %ecx
testb $0x2, %cl
jne 0x4f0b
testb $0x8, %cl
jne 0x4f2d
xorl %edx, %edx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4e18
movsbl %al, %ecx
addl $-0x30, %ecx
xorl %eax, %eax
leal (%rax,%rax,4), %eax
leal (%rcx,%rax,2), %eax
decq %rsi
jne 0x4f13
cmpl 0x65d0(%rip), %eax      # 0xb4f4
jbe 0x4f5d
xorl %ebx, %ebx
jmp 0x508c
movzbl %al, %eax
xorl %ebx, %ebx
leal -0x21(%rax), %ecx
cmpl $0x9, %ecx
ja 0x4f6f
leaq 0x290f(%rip), %rax      # 0x7850
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x62eb(%rip), %rax      # 0xb23c
movl (%rax), %edx
testl %edx, %edx
jne 0x5014
jmp 0x4f26
movq 0x6594(%rip), %rcx      # 0xb4f8
movl %eax, %eax
movq (%rcx,%rax,8), %rbx
jmp 0x508c
cmpl $0x3f, %eax
je 0x500b
cmpl $0x40, %eax
jne 0x508c
movq 0x6578(%rip), %rdi      # 0xb500
testq %rdi, %rdi
je 0x4f92
callq 0x2050
movl 0x655b(%rip), %r14d     # 0xb4f4
testq %r14, %r14
je 0x502e
movq 0x654f(%rip), %r15      # 0xb4f8
leal 0x1(%r14), %eax
cmpl $0x3, %eax
movl $0x2, %r12d
cmovael %eax, %r12d
movl $0x1, %r13d
movl $0x1, %ebx
movq (%r15,%r13,8), %rdi
callq 0x2100
addq %rax, %rbx
incq %r13
cmpq %r13, %r12
jne 0x4fc5
jmp 0x5033
callq 0x20e0
leaq 0x64f9(%rip), %rbx      # 0xb4e0
leaq 0x28a3(%rip), %rsi      # 0x7891
movq %rbx, %rdi
movl %eax, %edx
jmp 0x5025
movl 0x64f9(%rip), %edx      # 0xb4f4
leaq 0x64de(%rip), %rbx      # 0xb4e0
leaq 0x288b(%rip), %rsi      # 0x7894
jmp 0x5022
leaq 0x620e(%rip), %rax      # 0xb220
movl (%rax), %edx
leaq 0x64c5(%rip), %rbx      # 0xb4e0
leaq 0x286f(%rip), %rsi      # 0x7891
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2340
jmp 0x508c
movl $0x1, %ebx
addq %r14, %rbx
movq %rbx, %rdi
callq 0x6754
movq %rax, 0x64bb(%rip)      # 0xb500
movb $0x0, (%rax)
cmpl $0x0, 0x64a5(%rip)      # 0xb4f4
je 0x5085
movl $0x1, %ebx
movq 0x649b(%rip), %rcx      # 0xb4f8
movl %ebx, %edx
movq (%rcx,%rdx,8), %rsi
movq %rax, %rdi
callq 0x20f0
cmpl 0x6483(%rip), %ebx      # 0xb4f4
je 0x507b
movw $0x20, (%rax)
incq %rax
incl %ebx
cmpl 0x6471(%rip), %ebx      # 0xb4f4
jbe 0x5056
movq 0x6474(%rip), %rbx      # 0xb500
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq