// File: /workspace/github_c_makefile_star2_O2/seanpringle[P]xoat/./textbox.c
// Function: textbox_create
Textbox* textbox_create(Window parent, unsigned long flags, short x, short y, short w, short h, char *font, char *fg, char *bg, char *text, char *prompt)
{
	Textbox *tb = calloc(1, sizeof(Textbox));

	tb->flags = flags;
	tb->parent = parent;

	tb->x = x; tb->y = y; tb->w = MAX(1, w); tb->h = MAX(1, h);

	XColor color; Colormap map = DefaultColormap(display, DefaultScreen(display));
	unsigned int cp = XAllocNamedColor(display, map, bg, &color, &color) ? color.pixel: None;

	tb->window = XCreateSimpleWindow(display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, None, cp);

	// need to preload the font to calc line height
	textbox_font(tb, font, fg, bg);

	tb->prompt = strdup(prompt ? prompt: "");
	textbox_text(tb, text ? text: "");

	// auto height/width modes get handled here
	textbox_moveresize(tb, tb->x, tb->y, tb->w, tb->h);

	// edit mode controls
	if (tb->flags & TB_EDITABLE)
	{
		tb->xim = XOpenIM(display, NULL, NULL, NULL);
		tb->xic = XCreateIC(tb->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, tb->window, XNFocusWindow, tb->window, NULL);
	}

	return tb;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r13d
movl %r8d, %r12d
movl %ecx, %r14d
movl %edx, %ebp
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
movq %rdi, 0x10(%rsp)
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0x3500
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq %rax, (%rbx)
movq %r15, 0x10(%rbx)
movw %bp, 0x18(%rbx)
movl %ebp, %r15d
movw %r14w, 0x1a(%rbx)
cmpw $0x2, %r12w
pushq $0x1
popq %rbp
cmovll %ebp, %r12d
movw %r12w, 0x1c(%rbx)
cmpw $0x2, %r13w
cmovgel %r13d, %ebp
movw %bp, 0x1e(%rbx)
movq 0xb115(%rip), %rdi      # 0xebb0
movq 0xe8(%rdi), %rax
movslq 0xe0(%rdi), %rcx
shlq $0x7, %rcx
movq 0x50(%rax,%rcx), %rsi
leaq 0x18(%rsp), %r13
movq 0x70(%rsp), %rdx
movq %r13, %rcx
movq %r13, %r8
callq 0x31a0
xorl %r10d, %r10d
testl %eax, %eax
movl (%r13), %eax
movq 0xb0d9(%rip), %rdi      # 0xebb0
cmovneq %rax, %r10
subq $0x8, %rsp
movq 0x18(%rsp), %rsi
movl %r15d, %edx
movl %r14d, %ecx
movl %r12d, %r8d
movl %ebp, %r9d
pushq %r10
pushq $0x0
pushq $0x0
callq 0x31e0
addq $0x20, %rsp
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rcx
callq 0x3bc6
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
leaq 0x6bde(%rip), %r12      # 0xa70a
cmoveq %r12, %rdi
callq 0x3430
movq %rax, 0x58(%rbx)
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
cmoveq %r12, %rsi
movq %rbx, %rdi
callq 0x3c74
movswl 0x18(%rbx), %esi
movswl 0x1a(%rbx), %edx
movswl 0x1c(%rbx), %ecx
movswl 0x1e(%rbx), %r8d
movq %rbx, %rdi
callq 0x3cc5
testb $0x8, 0x2(%rbx)
je 0x3bb4
movq 0xb03d(%rip), %rdi      # 0xebb0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3490
movq %rax, 0x60(%rbx)
movq 0x8(%rbx), %r8
leaq 0x67f9(%rip), %rsi      # 0xa386
leaq 0x67fd(%rip), %rcx      # 0xa391
leaq 0x6803(%rip), %r9       # 0xa39e
movl $0x408, %edx            # imm = 0x408
movq %rax, %rdi
xorl %eax, %eax
pushq $0x0
pushq %r8
callq 0x3030
popq %rcx
popq %rdx
movq %rax, 0x68(%rbx)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq