// File: /workspace/github_c_makefile_star2_O1/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 0x1678
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 0x1e4d
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 0x1e94
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 0x7fb4
movq 0xc215(%rip), %r15      # 0xd6b0
movb $0x1, %r13b
cmpb $0x0, (%r15)
jne 0x1380
movl $0x2, 0xc32e(%rip)      # 0xd7e0
cmpq $0x3b9aca00, 0xc32b(%rip) # imm = 0x3B9ACA00
je 0x15e1
cmpl $0x2, 0xc326(%rip)      # 0xd7f0
jl 0x15e1
movl $0x3b9aca00, %ebp       # imm = 0x3B9ACA00
movl $0x2, %esi
xorl %r13d, %r13d
leaq 0xc34c(%rip), %rbx      # 0xd830
leaq 0x8be4(%rip), %r14      # 0xa0cf
leaq 0x8bb5(%rip), %r15      # 0xa0a7
leaq 0x8bc2(%rip), %r12      # 0xa0bb
movl $0x2, 0xc2f1(%rip)      # 0xd7f4
cmpl $0x0, 0xc2ee(%rip)      # 0xd7f8
je 0x1533
movq %r15, %rdi
xorl %eax, %eax
callq 0x10e0
cmpl $0x3, 0xc2c3(%rip)      # 0xd7e0
jl 0x1533
movq 0xc2c2(%rip), %rsi      # 0xd7e8
subq %rbp, %rsi
movq %r12, %rdi
xorl %eax, %eax
callq 0x10e0
movq 0xc2ae(%rip), %rbp      # 0xd7e8
movl %r13d, 0xc2bb(%rip)     # 0xd7fc
movl %r13d, 0xc2b8(%rip)     # 0xd800
movl %r13d, 0xc2b5(%rip)     # 0xd804
movl %r13d, 0xc2b2(%rip)     # 0xd808
movq %r13, 0xc2b3(%rip)      # 0xd810
movl %r13d, 0xc2b4(%rip)     # 0xd818
movq %r13, 0xc27d(%rip)      # 0xd7e8
movl $0x41414141, 0xc2a7(%rip) # imm = 0x41414141
cmpl %r13d, 0xc2a4(%rip)     # 0xd820
je 0x15a8
movq 0xc2a3(%rip), %rdi      # 0xd828
callq 0x10a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11c0
movq %rax, 0xc28c(%rip)      # 0xd828
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x11a0
xorl %eax, %eax
callq 0x8470
movl 0xc22b(%rip), %eax      # 0xd7e0
leal 0x1(%rax), %esi
movl %esi, 0xc222(%rip)      # 0xd7e0
cmpl $0x3, 0xc2f3(%rip)      # 0xd8b8
movq 0xc21c(%rip), %rcx      # 0xd7e8
cmovneq %rcx, %rbp
cmpq %rbp, %rcx
je 0x15e1
cmpl 0xc215(%rip), %eax      # 0xd7f0
jl 0x14f9
cmpl $0x0, 0xc238(%rip)      # 0xd820
je 0x1625
movl 0xc220(%rip), %edi      # 0xd810
addl $0x5, %edi
xorl %esi, %esi
callq 0x7aa3
movq 0xc227(%rip), %rdi      # 0xd828
movl 0xc201(%rip), %edx      # 0xd808
movl %edx, %eax
shrl $0x8, %eax
movl $0xff, %ecx
andl %ecx, %eax
andl %edx, %ecx
addl %eax, %ecx
leaq 0x8ab4(%rip), %rsi      # 0xa0d2
xorl %eax, %eax
callq 0x1140
cmpl $0x0, 0xc290(%rip)      # 0xd8bc
je 0x164c
xorl %eax, %eax
callq 0x7308
cmpl $0x0, 0xc284(%rip)      # 0xd8c0
je 0x164c
xorl %eax, %eax
callq 0x8fde
xorl %eax, %eax
callq 0x5b12
movq 0xc0f5(%rip), %rdi      # 0xd748
callq 0x10a0
leaq 0xc271(%rip), %rdi      # 0xd8d0
callq 0x1060
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq