// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0xf40, %rsp            # imm = 0xF40
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0xf18(%rbp)
movq $0x0, -0xf20(%rbp)
movq $0x0, -0xf28(%rbp)
movq $0x0, -0xf30(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x123ff
movq 0xc1c0e(%rip), %rax     # 0xd3ff0
movq (%rax), %rdi
leaq 0x96c18(%rip), %rsi     # 0xa9004
movb $0x0, %al
callq 0x12150
movl $0x1, -0x4(%rbp)
jmp 0x126c8
movl $0x6, %edi
leaq 0x9ae33(%rip), %rsi     # 0xad23e
callq 0x121f0
leaq -0xc1c(%rbp), %rdi
callq 0x15670
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0xe40(%rbp), %rdi
leaq -0xc1c(%rbp), %rdx
callq 0x12730
cmpl $0x0, -0xc1c(%rbp)
je 0x12445
jmp 0x126a6
leaq -0xe40(%rbp), %rdi
movl $0x20000, %esi          # imm = 0x20000
leaq 0xb7118(%rip), %rdx     # 0xc9570
movl $0x127, %ecx            # imm = 0x127
leaq 0xbd94c(%rip), %r8      # 0xcfdb0
movl $0x65, %r9d
leaq -0xc1c(%rbp), %rax
movq %rax, (%rsp)
callq 0x12a20
movq %rax, -0xf18(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x1248f
jmp 0x1264a
movb $0x1, -0xe43(%rbp)
movb $0x1, -0xe42(%rbp)
movb $0x0, -0xe41(%rbp)
leaq -0xc1c(%rbp), %rdi
callq 0x6fc30
movq %rax, -0xf30(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x124c5
jmp 0x1264a
movl $0x64, -0xe88(%rbp)
leaq 0x90f6a(%rip), %rax     # 0xa3440
movq %rax, -0xe80(%rbp)
leaq 0x9104c(%rip), %rax     # 0xa3530
movq %rax, -0xe78(%rbp)
movq -0xf30(%rbp), %rax
movq %rax, -0xe50(%rbp)
leaq 0x91080(%rip), %rax     # 0xa3580
movq %rax, -0xe60(%rbp)
leaq 0x95dc2(%rip), %rax     # 0xa82d0
movq %rax, -0xe58(%rbp)
leaq -0xf10(%rbp), %rdi
callq 0xa0e00
movq -0xf18(%rbp), %rdi
leaq -0xe88(%rbp), %rsi
leaq -0xe43(%rbp), %rdx
leaq -0xc1c(%rbp), %rcx
callq 0x16810
movq %rax, -0xf20(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x12557
jmp 0x1264a
movq -0xf20(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq 0x17120
cmpl $0x0, -0xc1c(%rbp)
je 0x12578
jmp 0x1264a
movq -0xf30(%rbp), %rdi
movq -0xf20(%rbp), %rax
movq 0x58(%rax), %rsi
leaq 0x9e0c7(%rip), %rax     # 0xb0658
movq (%rax), %rcx
movq -0xf20(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x310(%rax), %r8
leaq 0xc0c83(%rip), %rdx     # 0xd3230
leaq -0xf10(%rbp), %r9
leaq -0xc1c(%rbp), %rax
movl $0x8000, (%rsp)         # imm = 0x8000
movq %rax, 0x8(%rsp)
callq 0xa3830
movq %rax, -0xf28(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x125de
jmp 0x1264a
movq -0xf28(%rbp), %rdi
leaq 0x96a2c(%rip), %rsi     # 0xa9018
leaq 0xed(%rip), %rdx        # 0x126e0
leaq -0xc1c(%rbp), %rcx
callq 0x7d810
cmpl $0x0, -0xc1c(%rbp)
je 0x1260a
jmp 0x1264a
movq -0xf28(%rbp), %rdi
callq 0x70570
movq -0xf30(%rbp), %rdi
callq 0x6fcd0
movq -0xf20(%rbp), %rdi
callq 0x16ac0
movq -0xf18(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq 0x12ba0
movl $0x0, -0x4(%rbp)
jmp 0x126c8
movq -0xf28(%rbp), %rdi
callq 0x70570
movq -0xf30(%rbp), %rdi
callq 0x6fcd0
movq -0xf20(%rbp), %rdi
callq 0x16ac0
cmpq $0x0, -0xf18(%rbp)
je 0x1268d
movq -0xf18(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq 0x12ba0
jmp 0x126a4
movq -0xc28(%rbp), %rax
movq -0xc38(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq *%rax
jmp 0x126a6
movq 0xc1943(%rip), %rax     # 0xd3ff0
movq (%rax), %rdi
leaq -0xc1c(%rbp), %rsi
movl $0x1, %edx
callq 0x15a00
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf40, %rsp            # imm = 0xF40
popq %rbp
retq
nopw %cs:(%rax,%rax)