// File: /workspace/github_c_makefile_star2_O0/TurkeyMcMac[P]ts3d/src/ui-util.c
// Function: popup_window
WINDOW *popup_window(const char *text)
{
	int width = 0, height = 0;
	int line_width = 0;
	for (const char *chrp = text; *chrp != '\0'; ++chrp) {
		if (*chrp == '\n') {
			++height;
			line_width = 0;
		} else {
			++line_width;
			if (line_width > width) width = line_width;
		}
	}
	// Simulate a final newline if it's missing:
	if (line_width != 0) ++height;
	// Add one cell of padding to all sides:
	width += 2;
	height += 2;
	// No popups larger than the screen are allowed:
	if (height > LINES || width > COLS) return NULL;
	WINDOW *win = newwin(height, width,
		(LINES - height) / 2, (COLS - width) / 2);
	if (!win) return NULL;
	const char *line = text;
	for (int y = 1; y < height - 1; ++y) {
		const char *nl = strchr(line, '\n');
		// Line length is remaining text length if there's no newline:
		int len = nl ? nl - line : (int)strlen(line);
		// Draw centered line of text:
		mvwaddnstr(win, y, (width - len) / 2, line, len);
		line += len + 1;
	}
	return win;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1031c
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x102f3
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
jmp 0x1030c
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0x1030a
movl -0x1c(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1030c
jmp 0x1030e
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x102c9
cmpl $0x0, -0x1c(%rbp)
je 0x1032b
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq 0x5c59(%rip), %rcx      # 0x15fa0
cmpl (%rcx), %eax
jg 0x10359
movl -0x14(%rbp), %eax
movq 0x5c73(%rip), %rcx      # 0x15fc8
cmpl (%rcx), %eax
jle 0x10366
movq $0x0, -0x8(%rbp)
jmp 0x10476
movl -0x18(%rbp), %edi
movl -0x14(%rbp), %esi
movq 0x5c2d(%rip), %rax      # 0x15fa0
movl (%rax), %eax
subl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x50(%rbp)
movq 0x5c3e(%rip), %rax      # 0x15fc8
movl (%rax), %eax
subl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl -0x50(%rbp), %edx
movl %eax, %ecx
callq 0x2340
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x103b9
movq $0x0, -0x8(%rbp)
jmp 0x10476
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1046e
movq -0x38(%rbp), %rdi
movl $0xa, %esi
callq 0x22c0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x10403
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
jmp 0x10412
movq -0x38(%rbp), %rdi
callq 0x2200
cltq
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x14(%rbp), %eax
subl -0x4c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
callq 0x2310
cmpl $-0x1, %eax
jne 0x1043c
jmp 0x1044c
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x4c(%rbp), %edx
callq 0x2370
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x103c8
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq