// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/subtro.c
// Function: main
int main(int argc, char *argv[])
{
	subtilis_error_t err;
	subtilis_stream_t s;
	subtilis_settings_t settings;
	subtilis_backend_t backend;
	subtilis_arm_fp_if_t fp_if;
	subtilis_lexer_t *l = NULL;
	subtilis_parser_t *p = NULL;
	subtilis_arm_prog_t *arm_p = NULL;
	subtilis_arm_op_pool_t *pool = NULL;

	if (argc != 2) {
		fprintf(stderr, "Usage: subtro file\n");
		return 1;
	}

	setlocale(LC_ALL, "C");

	subtilis_error_init(&err);
	subtilis_stream_from_file(&s, argv[1], &err);
	if (err.type != SUBTILIS_ERROR_OK)
		goto fail;

	l = subtilis_lexer_new(&s, SUBTILIS_CONFIG_LEXER_BUF_SIZE,
			       subtilis_keywords_list, SUBTILIS_KEYWORD_TOKENS,
			       subtilis_arm_keywords_list,
			       SUBTILIS_ARM_KEYWORD_TOKENS, &err);
	if (err.type != SUBTILIS_ERROR_OK)
		goto cleanup;

	settings.handle_escapes = true;
	settings.ignore_graphics_errors = true;
	settings.check_mem_leaks = false;

	pool = subtilis_arm_op_pool_new(&err);
	if (err.type != SUBTILIS_ERROR_OK)
		goto cleanup;

	backend.caps = SUBTILIS_RISCOS_ARM_CAPS;
	backend.sys_trans = subtilis_riscos_arm2_sys_trans;
	backend.sys_check = subtilis_riscos_arm2_sys_check;
	backend.backend_data = pool;
	backend.asm_parse = subtilis_riscos_arm2_asm_parse;
	backend.asm_free = subtilis_riscos_asm_free;

	subtilis_arm_fpa_if_init(&fp_if);

	p = subtilis_parser_new(l, &backend, &settings, &err);
	if (err.type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_parse(p, &err);
	if (err.type != SUBTILIS_ERROR_OK)
		goto cleanup;

	//	subtilis_ir_prog_dump(p->prog);

	arm_p = subtilis_riscos_generate(
	    pool, p->prog, riscos_arm2_rules, riscos_arm2_rules_count,
	    p->st->max_allocated, &fp_if, SUBTILIS_RISCOS_ARM2_PROGRAM_START,
	    &err);
	if (err.type != SUBTILIS_ERROR_OK)
		goto cleanup;

	//	printf("\n\n");
	//	subtilis_arm_prog_dump(arm_p);

	subtilis_arm_encode(arm_p, "RunImage", prv_set_prog_size, &err);
	if (err.type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_arm_prog_delete(arm_p);
	subtilis_arm_op_pool_delete(pool);
	subtilis_parser_delete(p);
	subtilis_lexer_delete(l, &err);

	return 0;

cleanup:
	subtilis_arm_prog_delete(arm_p);
	subtilis_arm_op_pool_delete(pool);
	subtilis_parser_delete(p);
	if (l)
		subtilis_lexer_delete(l, &err);
	else
		s.close(s.handle, &err);

fail:
	subtilis_error_fprintf(stderr, &err, true);

	return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf00, %rsp            # imm = 0xF00
cmpl $0x2, %edi
jne 0x1248c
movq %rsi, %r14
leaq 0x5de55(%rip), %rsi     # 0x70234
pushq $0x6
popq %rdi
callq 0x12220
leaq 0x2f4(%rsp), %rbx
movq %rbx, %rdi
callq 0x140a4
movq 0x8(%r14), %rsi
leaq 0xd0(%rsp), %rdi
movq %rbx, %rdx
callq 0x12678
cmpl $0x0, (%rbx)
jne 0x1257e
subq $0x8, %rsp
leaq 0x890d1(%rip), %rdx     # 0x9b4f0
leaq 0x8f9ca(%rip), %r8      # 0xa1df0
leaq 0xd8(%rsp), %rdi
pushq $0x65
popq %r9
movl $0x20000, %esi          # imm = 0x20000
movl $0x127, %ecx            # imm = 0x127
pushq %rbx
callq 0x1285c
popq %rcx
popq %rdx
movq %rax, %rbx
cmpl $0x0, 0x2f4(%rsp)
je 0x1245f
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x12538
movw $0x101, 0x5(%rsp)       # imm = 0x101
movb $0x0, 0x7(%rsp)
leaq 0x2f4(%rsp), %r15
movq %r15, %rdi
callq 0x4c0f0
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x124b0
xorl %r15d, %r15d
jmp 0x12535
movq 0x93b5d(%rip), %rax     # 0xa5ff0
movq (%rax), %rcx
leaq 0x59b67(%rip), %rdi     # 0x6c004
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
callq 0x12290
pushq $0x1
popq %rbx
jmp 0x1259a
leaq 0x8(%rsp), %r15
movl $0x64, (%r15)
leaq 0x56248(%rip), %rax     # 0x6870b
movq %rax, 0x8(%r15)
leaq 0x562a8(%rip), %rax     # 0x68776
movq %rax, 0x10(%r15)
movq %r14, 0x38(%r15)
leaq 0x562af(%rip), %rax     # 0x6878c
movq %rax, 0x28(%r15)
leaq 0x59a98(%rip), %rax     # 0x6bf80
movq %rax, 0x30(%r15)
leaq 0x48(%rsp), %rdi
callq 0x672eb
leaq 0x5(%rsp), %rdx
leaq 0x2f4(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x14aa8
movq %rax, %r15
cmpl $0x0, (%r12)
jne 0x12535
leaq 0x2f4(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x1507a
cmpl $0x0, (%r12)
je 0x125ad
xorl %r12d, %r12d
movq %r12, %rdi
callq 0x4c65f
movq %r14, %rdi
callq 0x4c130
movq %r15, %rdi
callq 0x14c80
testq %rbx, %rbx
je 0x12567
leaq 0x2f4(%rsp), %rsi
movq %rbx, %rdi
callq 0x1292e
jmp 0x1257e
movq 0x2d8(%rsp), %rdi
leaq 0x2f4(%rsp), %rsi
callq *0x2e8(%rsp)
movq 0x93a6b(%rip), %rax     # 0xa5ff0
movq (%rax), %rdi
leaq 0x2f4(%rsp), %rsi
pushq $0x1
popq %rbx
movl %ebx, %edx
callq 0x14346
movl %ebx, %eax
addq $0xf00, %rsp            # imm = 0xF00
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x60c04(%rip), %rax     # 0x731b8
movq (%rax), %rcx
movq 0x58(%r15), %rsi
movq 0x60(%r15), %rax
movq 0x310(%rax), %r8
leaq 0x92c63(%rip), %rdx     # 0xa5230
leaq 0x48(%rsp), %r9
movq %r14, %rdi
pushq %r12
pushq $0x8000                 # imm = 0x8000
callq 0x68918
popq %rcx
popq %rdx
movq %rax, %r12
cmpl $0x0, 0x2f4(%rsp)
jne 0x12538
leaq 0x59a1d(%rip), %rsi     # 0x6c018
leaq 0x4d(%rip), %rdx        # 0x1264f
leaq 0x2f4(%rsp), %r13
movq %r12, %rdi
movq %r13, %rcx
callq 0x53298
cmpl $0x0, (%r13)
jne 0x12538
movq %r12, %rdi
callq 0x4c65f
movq %r14, %rdi
callq 0x4c130
movq %r15, %rdi
callq 0x14c80
leaq 0x2f4(%rsp), %rsi
movq %rbx, %rdi
callq 0x1292e
xorl %ebx, %ebx
jmp 0x1259a