// File: /workspace/github_c_makefile_star2_O3/mist64[P]cbm6502asm/src/asm.c
// Function: main
int main(int argc, char *argv[]) {
	long oldbytes;
	int i, first = TRUE;
	open_files(argc, argv); /* get command line */
	while (*src) {          /* as long as there are more src files */
		for (i = 0; (srcfile[i] = toupper(src[i])); i++)
			;
		appendef(srcfile, ".src");
		fprintf(file_tmp, "%sF%s\n", STATLINE, srcfile);
		for (i = strlen(srcfile); i > 0;
		     i--) /* extract path, if any for tmp file */
			if (srcfile[i] == '\\' || srcfile[i] == ']' ||
			    srcfile[i] == ':') {
				strcpy(defipath,
				       srcfile);     /* copy src file name */
				defipath[i + 1] = 0; /* terminate after path */
				break;
			}
		if (first) {
			if ((file_src = fopen(srcfile, "r")) == NULL)
				error_msg("error opening source file:", srcfile,
				          4);
		} else if (!freopen(srcfile, "r", file_src))
			error_msg("error opening source file:", srcfile, 4);
		while (*src++)
			; /* point to next file */
		pass1((char *)NULL, (char **)NULL,
		      (char *)NULL); /* pass1 processor */
		first = FALSE;
	}
	curpass = 2;
	oldbytes = 1000000000L; /* for word rel. branch compression */
	while (codebytes != oldbytes &&
	       curpass <= maxpass) { /* if no change in obj length */
		pass = 2;
		if (prnerrcon) { /* check if ok to print to console */
			printf("\nstarting pass %d.\n", curpass);
			if (curpass > 2)
				printf("  %ld byte change.\n",
				       codebytes - oldbytes);
		}
		oldbytes = codebytes; /* save for next compare */
		binlin = binadr = binptr = chksum = 0;
		codebytes = errcount = loc_cntr = 0;
		lbn[0] = lbn[1] = lbn[2] = lbn[3] =
		        'A'; /* reinitial local block number */
		if (emitobj) {
			fclose(file_obj);                /* close obj file */
			file_obj = fopen(objfile, "w+"); /* reopen it */
			fseek(file_obj, 0L, 0);          /* position at beginning of file */
		}
		pass2(); /* pass2 processor */
		curpass++;
		if (cputype != 3)             /* check cputype (/cx switch) */
			oldbytes = codebytes; /* don't repeat if no word
			                         relative inst */
	}
	if (emitobj) { /* close obj file */
		outhex((unsigned int)(loc_cntr + 5),
		       (char)0); /* number of lines */
		fprintf(file_obj, ";00%04X%04X\n", binlin,
		        (255 & binlin >> 8) + (binlin & 255));
	}
	if (emitlst) {               /* list file requested? */
		clean_list();        /* output list file */
		if (prnsymtab) {     /* symbol table requested? */
			list_sym();  /* output symbol table */
			macro_tab(); /* output macro table */
		}
	}
	fclose(file_tmp); /* close temporary file */
	remove(tmpdev);   /* delete temporary file */
	return (1);       /* close files, release memory, exit */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x167a
movq 0xc35d(%rip), %r15      # 0xd6b0
cmpb $0x0, (%r15)
je 0x14a8
xorl %r13d, %r13d
callq 0x1030
movq %rax, %rbx
leaq 0xc351(%rip), %r14      # 0xd6c0
movabsq $0xc00000001, %r12      # imm = 0xC00000001
leaq 0x8eae(%rip), %rbp      # 0xa22e
xorl %eax, %eax
movq (%rbx), %rcx
movsbq (%r15,%rax), %rdx
movb (%rcx,%rdx,4), %cl
movb %cl, (%rax,%r14)
incq %rax
testb %cl, %cl
jne 0x1382
movq %r14, %rdi
leaq 0x92d4(%rip), %rsi      # 0xa676
callq 0x1e44
movq 0xc39a(%rip), %rdi      # 0xd748
leaq 0x8caf(%rip), %rsi      # 0xa064
leaq 0x8caf(%rip), %rdx      # 0xa06b
movq %r14, %rcx
xorl %eax, %eax
callq 0x1140
movq %r14, %rdi
callq 0x10b0
movq %rax, %r15
testl %r15d, %r15d
jle 0x1429
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movzbl (%r15,%r14), %eax
addl $-0x3a, %eax
cmpl $0x23, %eax
ja 0x13f0
btq %rax, %r12
jb 0x13ff
leaq -0x1(%r15), %rax
cmpq $0x1, %r15
movq %rax, %r15
jg 0x13dd
jmp 0x1429
movq %rbp, %r12
leaq 0xc347(%rip), %rbp      # 0xd750
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1080
incl %r15d
movb $0x0, (%r15,%rbp)
movq %r12, %rbp
movabsq $0xc00000001, %r12      # imm = 0xC00000001
testb $0x1, %r13b
je 0x1443
movq 0xc3a2(%rip), %rdx      # 0xd7d8
movq %r14, %rdi
movq %rbp, %rsi
callq 0x10f0
jmp 0x1455
movq %r14, %rdi
movq %rbp, %rsi
callq 0x11c0
movq %rax, 0xc383(%rip)      # 0xd7d8
testq %rax, %rax
jne 0x146e
leaq 0x8c2b(%rip), %rdi      # 0xa08c
movq %r14, %rsi
movl $0x4, %edx
callq 0x1e8b
movq 0xc23b(%rip), %rax      # 0xd6b0
incq %rax
movq %rax, 0xc231(%rip)      # 0xd6b0
cmpb $0x0, -0x1(%rax)
leaq 0x1(%rax), %rax
jne 0x1478
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x7f8a
movq 0xc215(%rip), %r15      # 0xd6b0
movb $0x1, %r13b
cmpb $0x0, (%r15)
jne 0x1380
movl $0x2, 0xc32e(%rip)      # 0xd7e0
movq 0xc32f(%rip), %rax      # 0xd7e8
cmpq $0x3b9aca00, %rax       # imm = 0x3B9ACA00
je 0x15e3
cmpl $0x2, 0xc324(%rip)      # 0xd7f0
jl 0x15e3
movl $0x3b9aca00, %r12d      # imm = 0x3B9ACA00
movl $0x2, %esi
xorl %ebp, %ebp
leaq 0xc34a(%rip), %rbx      # 0xd830
leaq 0x8be2(%rip), %r14      # 0xa0cf
leaq 0x8bb3(%rip), %r15      # 0xa0a7
movl $0x2, 0xc2f6(%rip)      # 0xd7f4
cmpl $0x0, 0xc2f3(%rip)      # 0xd7f8
movq %rax, %r13
je 0x153f
movq %r15, %rdi
xorl %eax, %eax
callq 0x10e0
cmpl $0x3, 0xc2c5(%rip)      # 0xd7e0
movq 0xc2c6(%rip), %r13      # 0xd7e8
jl 0x153f
subq %r12, %r13
leaq 0x8b8d(%rip), %rdi      # 0xa0bb
movq %r13, %rsi
xorl %eax, %eax
callq 0x10e0
movq 0xc2a9(%rip), %r13      # 0xd7e8
movl %ebp, 0xc2b7(%rip)      # 0xd7fc
movl %ebp, 0xc2b5(%rip)      # 0xd800
movl %ebp, 0xc2b3(%rip)      # 0xd804
movl %ebp, 0xc2b1(%rip)      # 0xd808
movq %rbp, 0xc2b2(%rip)      # 0xd810
movl %ebp, 0xc2b4(%rip)      # 0xd818
movq %rbp, 0xc27d(%rip)      # 0xd7e8
movl $0x41414141, 0xc2a7(%rip) # imm = 0x41414141
cmpl %ebp, 0xc2a5(%rip)      # 0xd820
je 0x15a7
movq 0xc2a4(%rip), %rdi      # 0xd828
callq 0x10a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11c0
movq %rax, 0xc28d(%rip)      # 0xd828
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x11a0
xorl %eax, %eax
callq 0x8458
movl 0xc22c(%rip), %ecx      # 0xd7e0
leal 0x1(%rcx), %esi
movl %esi, 0xc223(%rip)      # 0xd7e0
cmpl $0x3, 0xc2f4(%rip)      # 0xd8b8
movq 0xc21d(%rip), %rax      # 0xd7e8
cmovneq %rax, %r13
cmpq %r13, %rax
je 0x15e3
movq %r13, %r12
cmpl 0xc213(%rip), %ecx      # 0xd7f0
jl 0x14f4
cmpl $0x0, 0xc236(%rip)      # 0xd820
je 0x1627
movl 0xc21e(%rip), %edi      # 0xd810
addl $0x5, %edi
xorl %esi, %esi
callq 0x7a9e
movq 0xc225(%rip), %rdi      # 0xd828
movl 0xc1ff(%rip), %edx      # 0xd808
movl %edx, %eax
shrl $0x8, %eax
movl $0xff, %ecx
andl %ecx, %eax
andl %edx, %ecx
addl %eax, %ecx
leaq 0x8ab2(%rip), %rsi      # 0xa0d2
xorl %eax, %eax
callq 0x1140
cmpl $0x0, 0xc28e(%rip)      # 0xd8bc
je 0x164e
xorl %eax, %eax
callq 0x72b8
cmpl $0x0, 0xc282(%rip)      # 0xd8c0
je 0x164e
xorl %eax, %eax
callq 0x9011
xorl %eax, %eax
callq 0x5b8c
movq 0xc0f3(%rip), %rdi      # 0xd748
callq 0x10a0
leaq 0xc26f(%rip), %rdi      # 0xd8d0
callq 0x1060
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq