// File: aempirei[P]Chat-Art/palette.cc
// Function: geometry_from_string(geometry&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool geometry_from_string(geometry& g, std::string s) {

	int rgb[3];
	int n;
	int mode;
	int skip;

	auto pos = s.find_first_of("#\r\n");

	if(pos != std::string::npos)
		s.resize(pos);

	if(sscanf(s.c_str(), " mcb %d %d %d color %d %d %d %n",
				&mode, &g.code, &g.base,
				rgb+0, rgb+1, rgb+2,
				&skip)
			== 6)
	{

		// color modes

		g.mode = (geometry::mode_type)mode;

		for(int i = 0; i < 3; i++)
			g.color[i] = (uint8_t)rgb[i];

	} else if(sscanf(s.c_str(), " mcb %d %d %d ratio %d %d size %d %d %n",
				&mode, &g.code, &g.base,
				&g.ratio, &n,
				g.size + 1, g.size + 0,
				&skip)
			== 7)
	{

		// symbol modes

		g.mode = (geometry::mode_type)mode;

	} else if(strspn(s.c_str(), " \t") == strlen(s.c_str())) {

		// blank line

		g.mode = geometry::NOP;
		return false;

	} else {

		// invalid line

		g.mode = geometry::ERR;
		return false;
	}

	// unexpected trailing characters

	if(s[skip] != '\0') {
		g.mode = geometry::ERR;
		return false;
	  }

	// all good

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x78, %rsp
movq %rsi, -0x58(%rbp)
movq %rdi, %rax
movq -0x58(%rbp), %rdi
movq %rdi, -0x50(%rbp)
movq %rax, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
leaq 0x3636(%rip), %rsi      # 0x608d
xorl %eax, %eax
movl %eax, %edx
callq 0x20c0
movq %rax, -0x40(%rbp)
cmpq $-0x1, -0x40(%rbp)
je 0x2a78
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2240
movq -0x50(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
movq -0x18(%rbp), %rcx
addq $0x1c, %rcx
movq -0x18(%rbp), %r8
addq $0x20, %r8
leaq -0x2c(%rbp), %r9
leaq -0x2c(%rbp), %r11
addq $0x4, %r11
leaq -0x2c(%rbp), %r10
addq $0x8, %r10
leaq 0x35e2(%rip), %rsi      # 0x6091
leaq -0x34(%rbp), %rdx
leaq -0x38(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x2170
cmpl $0x6, %eax
jne 0x2b0f
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movl $0x0, -0x44(%rbp)
cmpl $0x3, -0x44(%rbp)
jge 0x2b0a
movslq -0x44(%rbp), %rax
movl -0x2c(%rbp,%rax,4), %eax
movzbl %al, %edx
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl %edx, 0x8(%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2ae2
jmp 0x2bda
movq -0x50(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
movq -0x18(%rbp), %rcx
addq $0x1c, %rcx
movq -0x18(%rbp), %r8
addq $0x20, %r8
movq -0x18(%rbp), %r9
addq $0x14, %r9
movq -0x18(%rbp), %r11
addq $0x4, %r11
movq -0x18(%rbp), %r10
leaq 0x356b(%rip), %rsi      # 0x60b1
leaq -0x34(%rbp), %rdx
leaq -0x30(%rbp), %rbx
leaq -0x38(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x2170
cmpl $0x7, %eax
jne 0x2b7d
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0x2bd8
movq -0x50(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
leaq 0x3549(%rip), %rsi      # 0x60d9
callq 0x20a0
movq -0x50(%rbp), %rdi
movq %rax, -0x60(%rbp)
callq 0x2090
movq %rax, %rdi
callq 0x20b0
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jne 0x2bc7
movq -0x18(%rbp), %rax
movl $0x0, 0x18(%rax)
movb $0x0, -0x9(%rbp)
jmp 0x2c04
movq -0x18(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movb $0x0, -0x9(%rbp)
jmp 0x2c04
jmp 0x2bda
movq -0x50(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x2310
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x2c00
movq -0x18(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movb $0x0, -0x9(%rbp)
jmp 0x2c04
movb $0x1, -0x9(%rbp)
movb -0x9(%rbp), %al
andb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %rbp
retq