// File: /workspace/github_c_makefile_star2_O2/ebiggers[P]mysh/mysh_main.c
// Function: do_get_prompt
static const char *do_get_prompt(const char *var, const char *def)
{
#define MAX_PROMPT_LEN 127
	static char prompt[MAX_PROMPT_LEN + 1];
	const char *psp;
	size_t i;
	const char *ps;

	ps = lookup_shell_param(var);
	if (!ps)
		ps = def;
	for (psp = ps, i = 0; *psp && i < MAX_PROMPT_LEN; psp++) {
		const char *s;
		if (*psp == '\\') {
			switch (*++psp) {
			case '[':
				/* Begin a sequence of non-printing characters.
				 * This is to stop readline() from getting
				 * confused when the prompt contains terminal
				 * control sequences that expand to fewer
				 * on-screen characters than the length of the
				 * prompt string. */
			#ifdef WITH_READLINE
				prompt[i++] = RL_PROMPT_START_IGNORE;
			#endif
				break;
			case ']':
				/* End a sequence of non-printing characters */
			#ifdef WITH_READLINE
				prompt[i++] = RL_PROMPT_END_IGNORE;
			#endif
				break;
			case '0' ... '9':
				/* Literal character given in octal */
				if (*(psp + 1) >= '0' && *(psp + 1) <= '9' &&
				    *(psp + 2) >= '0' && *(psp + 2) <= '9')
				{
					int c = *(psp + 2) - '0'
						+ 8 * (*(psp + 1) - '0')
						+ 64 * (*(psp + 0) - '0');
					prompt[i++] = c;
					psp += 2;
				}
				break;
			case 'h':
				/* Hostname, excluding domain name */
				{
					char *dot;
					prompt[i] = '\0';
					gethostname(&prompt[i], MAX_PROMPT_LEN - i);
					prompt[MAX_PROMPT_LEN] = '\0';
					dot = strchrnul(&prompt[i], '.');
					*dot = '\0';
					i += dot - &prompt[i];
				}
				break;
			case 's':
				/* Name of the shell */
				s = SHELL_NAME;
				goto handle_string;
			case 'u':
				/* Current user name */
				s = lookup_shell_param("USER");
				if (!s)
					s = "I have no name!";
				goto handle_string;
			case 'v':
				/* Version of the shell */
				s = SHELL_VERSION;
				goto handle_string;
			case 'w':
			case 'W':
				/* Absolute path to working directory
				 * TODO: Relative path, replace $HOME with ~  */
				s = lookup_shell_param("PWD");
				goto handle_string;

			handle_string:
				if (s) {
					/* Append a string to the command prompt */
					size_t len = strlen(s);
					if (i + len > MAX_PROMPT_LEN)
						goto out;
					strcpy(&prompt[i], s);
					i += len;
				}
				break;
			case '$':
				/* '#' if root, otherwise '$' */
				prompt[i++] = geteuid() ? '$' : '#';
				break;
			default:
				/* unrecognized meta sequence */
				prompt[i++] = *psp;
				break;
			}
		} else {
			/* not a meta sequence */
			prompt[i++] = *psp;
		}
	}
out:
	prompt[i] = '\0';
	return prompt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r13
callq 0x459d
testq %rax, %rax
cmovneq %rax, %r13
leaq 0x7135(%rip), %r15      # 0xb240
leaq 0x334a(%rip), %rbx      # 0x745c
xorl %r12d, %r12d
movb (%r13), %al
testb %al, %al
je 0x4291
cmpq $0x7e, %r12
ja 0x4291
cmpb $0x5c, %al
jne 0x416e
leaq 0x1(%r13), %r14
movb 0x1(%r13), %al
movzbl %al, %ecx
leal -0x30(%rcx), %edx
cmpl $0xa, %edx
jae 0x4186
movb 0x2(%r13), %cl
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x4178
movb 0x3(%r13), %dl
leal -0x30(%rdx), %esi
cmpb $0x9, %sil
ja 0x4178
addq $0x3, %r13
shlb $0x3, %cl
andb $0x78, %cl
shlb $0x6, %al
addb %dl, %al
addb %cl, %al
addb $-0x30, %al
movb %al, (%r12,%r15)
incq %r12
movq %r13, %r14
movq %r12, %r13
incq %r14
movq %r13, %r12
movq %r14, %r13
jmp 0x4115
leal -0x73(%rcx), %edx
cmpl $0x4, %edx
jbe 0x41c1
cmpl $0x24, %ecx
je 0x4279
cmpl $0x57, %ecx
je 0x41f0
cmpl $0x68, %ecx
je 0x4241
cmpl $0x5d, %ecx
je 0x423a
cmpl $0x5b, %ecx
jne 0x4285
movb $0x1, (%r12,%r15)
jmp 0x4289
movslq (%rbx,%rdx,4), %rcx
addq %rbx, %rcx
leaq 0x3658(%rip), %rbp      # 0x7827
jmpq *%rcx
leaq 0x3654(%rip), %rdi      # 0x782c
callq 0x459d
movq %rax, %rbp
testq %rax, %rax
leaq 0x3647(%rip), %rax      # 0x7831
cmoveq %rax, %rbp
jmp 0x4210
leaq 0x2eb8(%rip), %rdi      # 0x70af
callq 0x459d
movq %rax, %rbp
testq %rax, %rax
jne 0x4210
jmp 0x4178
leaq 0x3631(%rip), %rbp      # 0x7841
movq %rbp, %rdi
callq 0x2100
movq %rax, %r13
addq %r12, %r13
cmpq $0x80, %r13
jae 0x4291
addq %r15, %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2070
jmp 0x417b
movb $0x2, (%r12,%r15)
jmp 0x4289
leaq (%r15,%r12), %r13
xorl %ebp, %ebp
movb %bpl, (%r12,%r15)
pushq $0x7f
popq %rsi
subq %r12, %rsi
movq %r13, %rdi
callq 0x2320
movb %bpl, 0x705f(%rip)      # 0xb2bf
movq %r13, %rdi
pushq $0x2e
popq %rsi
callq 0x20b0
movq %rax, %r13
movb %bpl, (%rax)
subq %r15, %r13
jmp 0x417b
callq 0x2190
cmpl $0x1, %eax
movb $0x24, %al
sbbb $0x0, %al
movb %al, (%r12,%r15)
incq %r12
jmp 0x4178
movb $0x0, (%r12,%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq