// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/subtptd.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: subtptd 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_PTD_CAPS;
	backend.sys_trans = subtilis_ptd_sys_trans;
	backend.sys_check = subtilis_ptd_sys_check;
	backend.backend_data = pool;
	backend.asm_parse = subtilis_ptd_asm_parse;
	backend.asm_free = subtilis_riscos_asm_free;

	subtilis_arm_vfp_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, ptd_rules, ptd_rules_count, p->st->max_allocated,
	    &fp_if, SUBTILIS_PTD_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 0x1148c
movq %rsi, %r14
leaq 0x5ee65(%rip), %rsi     # 0x70244
pushq $0x6
popq %rdi
callq 0x11220
leaq 0x2f4(%rsp), %rbx
movq %rbx, %rdi
callq 0x130b4
movq 0x8(%r14), %rsi
leaq 0xd0(%rsp), %rdi
movq %rbx, %rdx
callq 0x11688
cmpl $0x0, (%rbx)
jne 0x1157b
subq $0x8, %rsp
leaq 0x89f91(%rip), %rdx     # 0x9b3b0
leaq 0x9088a(%rip), %r8      # 0xa1cb0
leaq 0xd8(%rsp), %rdi
pushq $0x65
popq %r9
movl $0x20000, %esi          # imm = 0x20000
movl $0x127, %ecx            # imm = 0x127
pushq %rbx
callq 0x1186c
popq %rcx
popq %rdx
movq %rax, %rbx
cmpl $0x0, 0x2f4(%rsp)
je 0x1145f
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x11535
movw $0x101, 0x5(%rsp)       # imm = 0x101
movb $0x0, 0x7(%rsp)
leaq 0x2f4(%rsp), %r15
movq %r15, %rdi
callq 0x4b100
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x114b0
xorl %r15d, %r15d
jmp 0x11532
movq 0x93b5d(%rip), %rax     # 0xa4ff0
movq (%rax), %rcx
leaq 0x5ab67(%rip), %rdi     # 0x6c004
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
callq 0x11290
pushq $0x1
popq %rbx
jmp 0x11597
leaq 0x8(%rsp), %r15
andl $0x0, (%r15)
leaq 0x56f0f(%rip), %rax     # 0x683cf
movq %rax, 0x8(%r15)
leaq 0x56f6f(%rip), %rax     # 0x6843a
movq %rax, 0x10(%r15)
movq %r14, 0x38(%r15)
leaq 0x56f76(%rip), %rax     # 0x68450
movq %rax, 0x28(%r15)
leaq 0x5a687(%rip), %rax     # 0x6bb6c
movq %rax, 0x30(%r15)
leaq 0x48(%rsp), %rdi
callq 0x6681c
leaq 0x5(%rsp), %rdx
leaq 0x2f4(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x13ab8
movq %rax, %r15
cmpl $0x0, (%r12)
jne 0x11532
leaq 0x2f4(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x1408a
cmpl $0x0, (%r12)
je 0x115aa
xorl %r12d, %r12d
movq %r12, %rdi
callq 0x4b66f
movq %r14, %rdi
callq 0x4b140
movq %r15, %rdi
callq 0x13c90
testq %rbx, %rbx
je 0x11564
leaq 0x2f4(%rsp), %rsi
movq %rbx, %rdi
callq 0x1193e
jmp 0x1157b
movq 0x2d8(%rsp), %rdi
leaq 0x2f4(%rsp), %rsi
callq *0x2e8(%rsp)
movq 0x93a6e(%rip), %rax     # 0xa4ff0
movq (%rax), %rdi
leaq 0x2f4(%rsp), %rsi
pushq $0x1
popq %rbx
movl %ebx, %edx
callq 0x13356
movl %ebx, %eax
addq $0xf00, %rsp            # imm = 0xF00
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x58(%r15), %rdi
callq 0x2a096
leaq 0x60cae(%rip), %rax     # 0x72268
movq (%rax), %rcx
movq 0x58(%r15), %rsi
movq 0x60(%r15), %rax
movq 0x310(%rax), %r8
leaq 0x92c5d(%rip), %rdx     # 0xa4230
leaq 0x48(%rsp), %r9
movq %r14, %rdi
pushq %r12
pushq $0xf000                 # imm = 0xF000
callq 0x68504
popq %rcx
popq %rdx
movq %rax, %r12
cmpl $0x0, 0x2f4(%rsp)
jne 0x11535
movq %r12, %rdi
callq 0x57a58
leaq 0x5aa10(%rip), %rsi     # 0x6c019
leaq 0x4d(%rip), %rdx        # 0x1165d
leaq 0x2f4(%rsp), %r13
movq %r12, %rdi
movq %r13, %rcx
callq 0x522a8
cmpl $0x0, (%r13)
jne 0x11535
movq %r12, %rdi
callq 0x4b66f
movq %r14, %rdi
callq 0x4b140
movq %r15, %rdi
callq 0x13c90
leaq 0x2f4(%rsp), %rsi
movq %rbx, %rdi
callq 0x1193e
xorl %ebx, %ebx
jmp 0x11597