// File: /workspace/github_c_makefile_star2_O1/MikeGray-APH[P]LibLouisAPH/source/languages/generic-backward.c
// Function: convert_indicators_capital
static int convert_indicators_capital(struct translate *translate)
{
	const struct table *table;
	int capital_in, numeric_in;
	unichar upper;

	/*   only remove indicators contained in last table in tables   */
	table = translate->tables[translate->table_cnt - 1];
	translate->table_crs = translate->table_cnt - 1;

	capital_in =
	numeric_in = 0;

	translate->input_crs =
	translate->output_len = 0;
	while(translate->input_crs < translate->input_len)
	{
		switch(translate_get_mode_indicator(translate, table, &table->numeric))
		{
		case FAIL:  return 0;

		case BEGIN:
		case WORD:  numeric_in = 1;  break;

		case END:
		case TERM:

			if(capital_in < 3)
				capital_in = 0;
			numeric_in = 0;
			break;

		/*   numeric space   */
		case SYMBOL:
		case NONE:  break;
		}

		if(numeric_in)
		{
			if(translate_copy_marked_indicators(translate) > 0)
				continue;
			if(!translate_copy_to_output(translate, 1, 1))
				return 0;
			continue;
		}

		switch(translate_get_mode_indicator(translate, table, &table->capital))
		{
		case FAIL:  return 0;
		case NONE:  break;

		case BEGIN:   capital_in = 3;  break;
		case WORD:    capital_in = 2;  break;
		case SYMBOL:  capital_in = 1;  break;

		case END:
		case TERM:  capital_in = 0;  break;
		}


		if(translate_copy_marked_indicators(translate) > 0)
			continue;

		if(capital_in)
		{
			if(capital_in < 3 && translate_has_attributes(translate, (CHAR_SPACE | CHAR_SEQUENCE_DELIMITER)))
			{
				capital_in = 0;
				if(!translate_copy_to_output(translate, 1, 1))
					return 0;
				continue;
			}

			if(capital_in == 2 && !translate_has_attributes(translate, CHAR_LETTER))
			{
				capital_in = 0;
				if(!translate_copy_to_output(translate, 1, 1))
					return 0;
				continue;
			}

			upper = generic_lower_to_upper(translate->tables[translate->table_crs], translate->input[translate->input_crs]);
			if(upper != translate->input[translate->input_crs])
			{
				CHANGE_MARK
				if(!translate_insert_dot_for_chars(translate, upper, 1))
					return 0;
			}
			else if(!translate_copy_to_output(translate, 1, 1))
				return 0;
		}
		else if(!translate_copy_to_output(translate, 1, 1))
			return 0;

		if(capital_in == 1)
			capital_in = 0;
	}

#ifdef DEBUG
	translate->output[translate->output_len] = 0;
#endif

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
movslq 0xc(%rdi), %rcx
movq -0x8(%rax,%rcx,8), %r14
decq %rcx
movl %ecx, 0x8(%rdi)
xorl %r12d, %r12d
movl %r12d, 0x68(%rdi)
movl %r12d, 0x40(%rdi)
cmpl %r12d, 0x44(%rdi)
jle 0xf1c1
leaq 0x150(%r14), %r15
leaq 0xd0(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x4cd9(%rip), %r13      # 0x13cb0
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7151
cmpl $0x5, %eax
ja 0xf00a
movl %eax, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x1, %r12d
jmp 0xf00a
xorl %r12d, %r12d
cmpl $0x3, %ebp
cmovll %r12d, %ebp
movq %rbx, %rdi
testl %r12d, %r12d
je 0xf044
callq 0x78c4
movl $0x1, %r12d
testl %eax, %eax
jg 0xf1b5
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x7666
testl %eax, %eax
jne 0xf1b5
jmp 0xf1cf
movq %r14, %rsi
movq 0x10(%rsp), %rdx
callq 0x7151
cmpl $0x6, %eax
ja 0xf07f
movl %eax, %eax
leaq 0x4c69(%rip), %rcx      # 0x13cc8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %ebp, %ebp
jmp 0xf07f
movl $0x1, %ebp
jmp 0xf07f
movl $0x3, %ebp
jmp 0xf07f
movl $0x2, %ebp
movq %rbx, %rdi
callq 0x78c4
testl %eax, %eax
jle 0xf093
xorl %r12d, %r12d
jmp 0xf1b5
testl %ebp, %ebp
je 0xf16c
cmpl $0x2, %ebp
jg 0xf0d1
movslq 0x40(%rbx), %rax
testq %rax, %rax
js 0xf0d1
cmpl %eax, 0x44(%rbx)
jle 0xf0d1
movslq 0x8(%rbx), %rcx
movq (%rbx), %rdx
movq 0x38(%rbx), %rsi
movq (%rdx,%rcx,8), %rdi
movzwl (%rsi,%rax,2), %esi
callq 0x1e99
testq %rax, %rax
je 0xf0d1
testb $0x3, 0x24(%rax)
jne 0xf107
cmpl $0x2, %ebp
jne 0xf128
movslq 0x40(%rbx), %rax
testq %rax, %rax
js 0xf107
cmpl %eax, 0x44(%rbx)
jle 0xf107
movslq 0x8(%rbx), %rcx
movq (%rbx), %rdx
movq 0x38(%rbx), %rsi
movq (%rdx,%rcx,8), %rdi
movzwl (%rsi,%rax,2), %esi
callq 0x1e99
testq %rax, %rax
je 0xf107
testb $0x40, 0x24(%rax)
jne 0xf128
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x7666
testl %eax, %eax
je 0xf1cf
xorl %ebp, %ebp
jmp 0xf08b
movslq 0x8(%rbx), %rax
movq (%rbx), %rcx
movq 0x38(%rbx), %rdx
movq (%rcx,%rax,8), %rdi
movslq 0x40(%rbx), %rax
movzwl (%rdx,%rax,2), %r12d
movzwl %r12w, %esi
callq 0x1e99
testq %rax, %rax
je 0xf15d
testb $0x1, 0x25(%rax)
je 0xf15d
movq 0x8(%rax), %rax
movzwl 0x20(%rax), %r12d
movq 0x38(%rbx), %rax
movslq 0x40(%rbx), %rcx
cmpw (%rax,%rcx,2), %r12w
jne 0xf180
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x7666
jmp 0xf1a7
movl $0x1, 0x94(%rbx)
movw %r12w, 0xe(%rsp)
movq %rbx, %rdi
leaq 0xe(%rsp), %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x74f9
testl %eax, %eax
je 0xf1cf
xorl %r12d, %r12d
cmpl $0x1, %ebp
cmovel %r12d, %ebp
movl 0x40(%rbx), %eax
cmpl 0x44(%rbx), %eax
jl 0xefd9
movq 0x60(%rbx), %rax
movslq 0x68(%rbx), %rcx
movw $0x0, (%rax,%rcx,2)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq