// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movl %r9d, %r12d
movl %r8d, %r13d
movl %ecx, 0x4(%rsp)
movl %edx, (%rsp)
movq %rsi, %r14
movq %rdi, %rbp
movq 0x70(%rsp), %r15
movl $0x1, %edi
movl $0x80, %esi
callq 0x3500
movq %rax, %rbx
movq %r14, (%rax)
movq %rbp, 0x10(%rax)
movl (%rsp), %eax
movw %ax, 0x18(%rbx)
movl 0x4(%rsp), %eax
movw %ax, 0x1a(%rbx)
cmpw $0x2, %r13w
movl $0x1, %eax
cmovll %eax, %r13d
movw %r13w, 0x1c(%rbx)
cmpw $0x2, %r12w
cmovgel %r12d, %eax
movw %ax, 0x1e(%rbx)
movq 0xa941(%rip), %rdi      # 0xebb0
movq 0xe8(%rdi), %rax
movslq 0xe0(%rdi), %rcx
shlq $0x7, %rcx
movq 0x50(%rax,%rcx), %rsi
leaq 0x8(%rsp), %r14
movq 0x60(%rsp), %r12
movq %r12, %rdx
movq %r14, %rcx
movq %r14, %r8
callq 0x31a0
xorl %r10d, %r10d
testl %eax, %eax
movl (%r14), %eax
movq 0xa903(%rip), %rdi      # 0xebb0
movq 0x10(%rbx), %rsi
movswl 0x18(%rbx), %edx
movswl 0x1a(%rbx), %ecx
movswl 0x1c(%rbx), %r8d
movswl 0x1e(%rbx), %r9d
cmovneq %rax, %r10
subq $0x8, %rsp
pushq %r10
pushq $0x0
pushq $0x0
callq 0x31e0
addq $0x20, %rsp
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %r12, %rcx
callq 0x439c
testq %r15, %r15
leaq 0x63d5(%rip), %r14      # 0xa6d2
cmoveq %r14, %r15
movq %r15, %rdi
callq 0x3430
movq %rax, 0x58(%rbx)
movq 0x68(%rsp), %rsi
testq %rsi, %rsi
cmoveq %r14, %rsi
movq %rbx, %rdi
callq 0x444a
movswl 0x18(%rbx), %esi
movswl 0x1a(%rbx), %edx
movswl 0x1c(%rbx), %ecx
movswl 0x1e(%rbx), %r8d
movq %rbx, %rdi
callq 0x449f
testb $0x8, 0x2(%rbx)
je 0x438a
movq 0xa869(%rip), %rdi      # 0xebb0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3490
movq %rax, 0x60(%rbx)
movq 0x8(%rbx), %r8
leaq 0x5fed(%rip), %rsi      # 0xa34e
leaq 0x5ff1(%rip), %rcx      # 0xa359
leaq 0x5ff7(%rip), %r9       # 0xa366
movl $0x408, %edx            # imm = 0x408
movq %rax, %rdi
xorl %eax, %eax
pushq $0x0
pushq %r8
callq 0x3030
addq $0x10, %rsp
movq %rax, 0x68(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq