// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5e80
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x568c
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0x56b8
cmpq $0x7f, -0x20(%rbp)
setb %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x56c4
jmp 0x5966
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x5934
movq -0x18(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x18(%rbp)
movsbl 0x1(%rax), %eax
addl $-0x24, %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0x53, %eax
ja 0x5913
movq -0x58(%rbp), %rax
leaq 0x4d3d(%rip), %rcx      # 0xa440
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
leaq 0x8f1e(%rip), %rax      # 0xe640
movb $0x1, (%rax,%rcx)
jmp 0x5932
movq -0x20(%rbp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
leaq 0x8eff(%rip), %rax      # 0xe640
movb $0x2, (%rax,%rcx)
jmp 0x5932
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x30, %eax
jl 0x57d5
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x39, %eax
jg 0x57d5
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x30, %eax
jl 0x57d5
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x39, %eax
jg 0x57d5
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
subl $0x30, %eax
movq -0x18(%rbp), %rcx
movsbl 0x1(%rcx), %ecx
subl $0x30, %ecx
shll $0x3, %ecx
addl %ecx, %eax
movq -0x18(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x30, %ecx
shll $0x6, %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
leaq 0x8e7a(%rip), %rax      # 0xe640
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x18(%rbp)
jmp 0x5932
movq -0x20(%rbp), %rcx
leaq 0x8e5b(%rip), %rax      # 0xe640
movb $0x0, (%rax,%rcx)
leaq 0x8e50(%rip), %rdi      # 0xe640
addq -0x20(%rbp), %rdi
movl $0x7f, %esi
subq -0x20(%rbp), %rsi
callq 0x2330
movb $0x0, 0x8eb6(%rip)      # 0xe6bf
leaq 0x8e30(%rip), %rdi      # 0xe640
addq -0x20(%rbp), %rdi
movl $0x2e, %esi
callq 0x20b0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movb $0x0, (%rax)
movq -0x40(%rbp), %rax
leaq 0x8e0c(%rip), %rcx      # 0xe640
addq -0x20(%rbp), %rcx
subq %rcx, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x5932
leaq 0x513c(%rip), %rax      # 0xa98b
movq %rax, -0x30(%rbp)
jmp 0x5896
leaq 0x5134(%rip), %rdi      # 0xa990
callq 0x5e80
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x5877
leaq 0x5122(%rip), %rax      # 0xa995
movq %rax, -0x30(%rbp)
jmp 0x5896
leaq 0x5125(%rip), %rax      # 0xa9a5
movq %rax, -0x30(%rbp)
jmp 0x5896
leaq 0x4822(%rip), %rdi      # 0xa0af
callq 0x5e80
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x58dd
movq -0x30(%rbp), %rdi
callq 0x2100
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
addq -0x48(%rbp), %rax
cmpq $0x7f, %rax
jbe 0x58bd
jmp 0x5968
leaq 0x8d7c(%rip), %rdi      # 0xe640
addq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x2070
movq -0x48(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x5932
callq 0x2190
movl %eax, %edx
movl $0x23, %eax
movl $0x24, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %dl
movq -0x20(%rbp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
leaq 0x8d32(%rip), %rax      # 0xe640
movb %dl, (%rax,%rcx)
jmp 0x5932
movq -0x18(%rbp), %rax
movb (%rax), %dl
movq -0x20(%rbp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
leaq 0x8d11(%rip), %rax      # 0xe640
movb %dl, (%rax,%rcx)
jmp 0x5953
movq -0x18(%rbp), %rax
movb (%rax), %dl
movq -0x20(%rbp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
leaq 0x8cf0(%rip), %rax      # 0xe640
movb %dl, (%rax,%rcx)
jmp 0x5955
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x569c
jmp 0x5968
movq -0x20(%rbp), %rcx
leaq 0x8ccd(%rip), %rax      # 0xe640
movb $0x0, (%rax,%rcx)
leaq 0x8cc2(%rip), %rax      # 0xe640
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)