// File: /workspace/github_c_makefile_star2_O3/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 0x11502
movq %rsi, %r14
leaq 0x64e85(%rip), %rsi     # 0x762d4
movl $0x6, %edi
callq 0x11220
leaq 0x2f4(%rsp), %rbx
movq %rbx, %rdi
callq 0x133c4
movq 0x8(%r14), %rsi
leaq 0xd0(%rsp), %rdi
movq %rbx, %rdx
callq 0x116f4
cmpl $0x0, (%rbx)
jne 0x115df
subq $0x8, %rsp
leaq 0x89f1f(%rip), %rdx     # 0x9b3b0
leaq 0x90818(%rip), %r8      # 0xa1cb0
leaq 0xd8(%rsp), %rdi
movl $0x20000, %esi          # imm = 0x20000
movl $0x127, %ecx            # imm = 0x127
movl $0x65, %r9d
pushq %rbx
callq 0x118ec
addq $0x10, %rsp
movq %rax, %rbx
cmpl $0x0, 0x2f4(%rsp)
je 0x114d5
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x11599
movw $0x101, 0x5(%rsp)       # imm = 0x101
movb $0x0, 0x7(%rsp)
leaq 0x2f4(%rsp), %r15
movq %r15, %rdi
callq 0x4de68
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x11511
xorl %r15d, %r15d
jmp 0x11596
callq 0x11320
movl $0x1, %ebx
jmp 0x11600
leaq 0x8(%rsp), %r15
movl $0x0, (%r15)
leaq 0x5c3a0(%rip), %rax     # 0x6d8c4
movq %rax, 0x8(%r15)
leaq 0x5c40c(%rip), %rax     # 0x6d93b
movq %rax, 0x10(%r15)
movq %r14, 0x38(%r15)
leaq 0x5c413(%rip), %rax     # 0x6d951
movq %rax, 0x28(%r15)
leaq 0x5fc49(%rip), %rax     # 0x71192
movq %rax, 0x30(%r15)
leaq 0x48(%rsp), %rdi
callq 0x6bc06
leaq 0x5(%rsp), %rdx
leaq 0x2f4(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x13e18
movq %rax, %r15
cmpl $0x0, (%r12)
jne 0x11596
leaq 0x2f4(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x14426
cmpl $0x0, (%r12)
je 0x11613
xorl %r12d, %r12d
movq %r12, %rdi
callq 0x4e410
movq %r14, %rdi
callq 0x4deb3
movq %r15, %rdi
callq 0x13ff4
testq %rbx, %rbx
je 0x115c8
leaq 0x2f4(%rsp), %rsi
movq %rbx, %rdi
callq 0x119db
jmp 0x115df
movq 0x2d8(%rsp), %rdi
leaq 0x2f4(%rsp), %rsi
callq *0x2e8(%rsp)
movq 0x93a0a(%rip), %rax     # 0xa4ff0
movq (%rax), %rdi
leaq 0x2f4(%rsp), %rsi
movl $0x1, %ebx
movl $0x1, %edx
callq 0x13660
movl %ebx, %eax
addq $0xf00, %rsp            # imm = 0xF00
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x58(%r15), %rdi
callq 0x2b55e
leaq 0x66cd5(%rip), %rax     # 0x782f8
movq (%rax), %rcx
movq 0x58(%r15), %rsi
movq 0x60(%r15), %rax
movq 0x310(%rax), %r8
leaq 0x92bf4(%rip), %rdx     # 0xa4230
leaq 0x48(%rsp), %r9
movq %r14, %rdi
pushq %r12
pushq $0xf000                 # imm = 0xF000
callq 0x6da04
addq $0x10, %rsp
movq %rax, %r12
cmpl $0x0, 0x2f4(%rsp)
jne 0x11599
movq %r12, %rdi
callq 0x5bb40
leaq 0x609a5(%rip), %rsi     # 0x72019
leaq 0x4d(%rip), %rdx        # 0x116c8
leaq 0x2f4(%rsp), %r13
movq %r12, %rdi
movq %r13, %rcx
callq 0x55c88
cmpl $0x0, (%r13)
jne 0x11599
movq %r12, %rdi
callq 0x4e410
movq %r14, %rdi
callq 0x4deb3
movq %r15, %rdi
callq 0x13ff4
leaq 0x2f4(%rsp), %rsi
movq %rbx, %rdi
callq 0x119db
xorl %ebx, %ebx
jmp 0x11600