// File: /workspace/github_c_makefile_star2_O1/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, %r12
callq 0x4c5b
testq %rax, %rax
cmovneq %rax, %r12
movb (%r12), %al
xorl %ebx, %ebx
testb %al, %al
je 0x4888
leaq 0x315c(%rip), %r13      # 0x7827
leaq 0x6b6e(%rip), %r15      # 0xb240
cmpb $0x5c, %al
jne 0x472e
leaq 0x1(%r12), %rbp
movb 0x1(%r12), %al
movzbl %al, %ecx
cmpl $0x56, %ecx
jg 0x4764
leal -0x30(%rcx), %edx
cmpl $0xa, %edx
jae 0x47cd
movb 0x2(%r12), %cl
leal -0x30(%rcx), %edx
xorl %r14d, %r14d
cmpb $0x9, %dl
ja 0x473b
movb 0x3(%r12), %dl
leal -0x30(%rdx), %esi
cmpb $0x9, %sil
ja 0x473b
addq $0x3, %r12
shlb $0x3, %cl
andb $0x78, %cl
shlb $0x6, %al
addb %dl, %al
addb %cl, %al
addb $-0x30, %al
movb %al, (%rbx,%r15)
incq %rbx
jmp 0x4738
movb %al, (%rbx,%r15)
incq %rbx
xorl %r14d, %r14d
movq %r12, %rbp
testl %r14d, %r14d
jne 0x4882
movb 0x1(%rbp), %al
testb %al, %al
je 0x4888
incq %rbp
movq %rbp, %r12
cmpq $0x7f, %rbx
jb 0x46d2
jmp 0x4888
cmpl $0x67, %ecx
jg 0x477f
cmpl $0x57, %ecx
je 0x47bc
cmpl $0x5b, %ecx
je 0x47e4
cmpl $0x5d, %ecx
jne 0x47de
movb $0x2, (%rbx,%r15)
jmp 0x47e9
leal -0x73(%rcx), %edx
cmpl $0x4, %edx
ja 0x47f4
leaq 0x2cce(%rip), %rsi      # 0x745c
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
movq %r13, %r12
jmpq *%rcx
leaq 0x308b(%rip), %rdi      # 0x782c
callq 0x4c5b
movq %rax, %r12
testq %rax, %rax
leaq 0x307e(%rip), %rax      # 0x7831
cmoveq %rax, %r12
jmp 0x483d
leaq 0x28ec(%rip), %rdi      # 0x70af
callq 0x4c5b
movq %rax, %r12
jmp 0x483d
cmpl $0x24, %ecx
jne 0x47de
callq 0x2190
cmpl $0x1, %eax
movb $0x24, %al
sbbb $0x0, %al
movb %al, (%rbx,%r15)
jmp 0x47e9
movb $0x1, (%rbx,%r15)
incq %rbx
xorl %r14d, %r14d
jmp 0x473b
cmpl $0x68, %ecx
jne 0x47de
leaq (%r15,%rbx), %r12
xorl %r14d, %r14d
movb %r14b, (%rbx,%r15)
movl $0x7f, %esi
subq %rbx, %rsi
movq %r12, %rdi
callq 0x2320
movb %r14b, 0x6aa4(%rip)     # 0xb2bf
movq %r12, %rdi
movl $0x2e, %esi
callq 0x20b0
movq %rax, %rbx
movb %r14b, (%rax)
subq %r15, %rbx
jmp 0x473b
leaq 0x3004(%rip), %r12      # 0x7841
xorl %r14d, %r14d
testq %r12, %r12
je 0x473b
movq %r12, %rdi
callq 0x2100
movq %rax, %r13
addq %rbx, %r13
cmpq $0x7f, %r13
ja 0x4870
addq %r15, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2070
movq %r13, %rbx
jmp 0x4876
movl $0x7, %r14d
leaq 0x2faa(%rip), %r13      # 0x7827
jmp 0x473b
cmpl $0x7, %r14d
jne 0x4893
leaq 0x69b1(%rip), %rax      # 0xb240
movb $0x0, (%rbx,%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq