// File: /workspace/github_c_makefile_star2_O0/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 %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 0x113ff
movq 0xc0c0e(%rip), %rax     # 0xd1ff0
movq (%rax), %rdi
leaq 0x97c18(%rip), %rsi     # 0xa9004
movb $0x0, %al
callq 0x11150
movl $0x1, -0x4(%rbp)
jmp 0x116e4
movl $0x6, %edi
leaq 0x9be43(%rip), %rsi     # 0xad24e
callq 0x111f0
leaq -0xc1c(%rbp), %rdi
callq 0x14680
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0xe40(%rbp), %rdi
leaq -0xc1c(%rbp), %rdx
callq 0x11740
cmpl $0x0, -0xc1c(%rbp)
je 0x11445
jmp 0x116c2
leaq -0xe40(%rbp), %rdi
movl $0x20000, %esi          # imm = 0x20000
leaq 0xb6fd8(%rip), %rdx     # 0xc8430
movl $0x127, %ecx            # imm = 0x127
leaq 0xbd80c(%rip), %r8      # 0xcec70
movl $0x65, %r9d
leaq -0xc1c(%rbp), %rax
movq %rax, (%rsp)
callq 0x11a30
movq %rax, -0xf18(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x1148f
jmp 0x11666
movb $0x1, -0xe43(%rbp)
movb $0x1, -0xe42(%rbp)
movb $0x0, -0xe41(%rbp)
leaq -0xc1c(%rbp), %rdi
callq 0x6ec40
movq %rax, -0xf30(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x114c5
jmp 0x11666
movl $0x0, -0xe88(%rbp)
leaq 0x9216a(%rip), %rax     # 0xa3640
movq %rax, -0xe80(%rbp)
leaq 0x9224c(%rip), %rax     # 0xa3730
movq %rax, -0xe78(%rbp)
movq -0xf30(%rbp), %rax
movq %rax, -0xe50(%rbp)
leaq 0x92280(%rip), %rax     # 0xa3780
movq %rax, -0xe60(%rbp)
leaq 0x96e32(%rip), %rax     # 0xa8340
movq %rax, -0xe58(%rbp)
leaq -0xf10(%rbp), %rdi
callq 0xa03e0
movq -0xf18(%rbp), %rdi
leaq -0xe88(%rbp), %rsi
leaq -0xe43(%rbp), %rdx
leaq -0xc1c(%rbp), %rcx
callq 0x15820
movq %rax, -0xf20(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x11557
jmp 0x11666
movq -0xf20(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq 0x16130
cmpl $0x0, -0xc1c(%rbp)
je 0x11578
jmp 0x11666
movq -0xf20(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x38150
movq -0xf30(%rbp), %rdi
movq -0xf20(%rbp), %rax
movq 0x58(%rax), %rsi
leaq 0x9e167(%rip), %rax     # 0xaf708
movq (%rax), %rcx
movq -0xf20(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x310(%rax), %r8
leaq 0xbfc73(%rip), %rdx     # 0xd1230
leaq -0xf10(%rbp), %r9
leaq -0xc1c(%rbp), %rax
movl $0xf000, (%rsp)         # imm = 0xF000
movq %rax, 0x8(%rsp)
callq 0xa38a0
movq %rax, -0xf28(%rbp)
cmpl $0x0, -0xc1c(%rbp)
je 0x115ee
jmp 0x11666
movq -0xf28(%rbp), %rdi
callq 0x857a0
movq -0xf28(%rbp), %rdi
leaq 0x97a11(%rip), %rsi     # 0xa9019
leaq 0xe1(%rip), %rdx        # 0x116f0
leaq -0xc1c(%rbp), %rcx
callq 0x7c820
cmpl $0x0, -0xc1c(%rbp)
je 0x11626
jmp 0x11666
movq -0xf28(%rbp), %rdi
callq 0x6f580
movq -0xf30(%rbp), %rdi
callq 0x6ece0
movq -0xf20(%rbp), %rdi
callq 0x15ad0
movq -0xf18(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq 0x11bb0
movl $0x0, -0x4(%rbp)
jmp 0x116e4
movq -0xf28(%rbp), %rdi
callq 0x6f580
movq -0xf30(%rbp), %rdi
callq 0x6ece0
movq -0xf20(%rbp), %rdi
callq 0x15ad0
cmpq $0x0, -0xf18(%rbp)
je 0x116a9
movq -0xf18(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq 0x11bb0
jmp 0x116c0
movq -0xc28(%rbp), %rax
movq -0xc38(%rbp), %rdi
leaq -0xc1c(%rbp), %rsi
callq *%rax
jmp 0x116c2
movq 0xc0927(%rip), %rax     # 0xd1ff0
movq (%rax), %rdi
leaq -0xc1c(%rbp), %rsi
movl $0x1, %edx
callq 0x14a10
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf40, %rsp            # imm = 0xF40
popq %rbp
retq