// File: /workspace/github_c_makefile_star2_O3/mist64[P]cbm6502asm/src/asm.c
// Function: open_files
void open_files(int argc, char *argv[]) { /* open files and initialize things */
	int i;
	char *p, c, listfile[LINELENG];
	long tyme;

	assumeL = FALSE;
	wide = absasm = prnerrcon = prnsymtab = prnxref = TRUE;
	cputype = DEFCPUTYPE; /* /cx overrides default */
	maxpass = 15;         /* default maximum number of passes */
	maxmaclev = 50;       /* default maximum macro nesting depth */
	*tmpdev = 0;
	if (argc > 1)                     /* check command line */
		strcpy(comline, argv[1]); /* get command line */
	else {
		printf("\nC65>");     /* prompt user for instructions */
		scanf("%s", comline); /* read command line from console */
	}
	if (!strcmp(comline, "/H") || !strcmp(comline, "/h")) {
		help();
		exit(0);
	}
	emitobj = 0; /* assume no obj file */
	p = comline; /* pointer to command line */
	while (*p != ',' && *p != '=' && *p != '/' && *p)
		objfile[emitobj++] =
		        *p++; /* get obj file name from command line */
	objfile[emitobj] = 0; /* terminate obj file name */
	appendef(objfile, ".obj");
	for (i = strlen(objfile) - 1; i > 0;
	     i--) /* extract path, if any for tmp file */
		if (objfile[i] == '\\' || objfile[i] == ']' ||
		    objfile[i] == ':') {
			strcpy(tmpdev, objfile); /* copy list file name */
			tmpdev[i + 1] = 0;       /* terminate after path */
			break;
		}
	emitlst = 0;     /* assume no list file */
	if (*p++ == ',') /* was there a comma in command line? */
		while (*p != ',' && *p != '=' && *p != '/' && *p)
			listfile[emitlst++] =
			        *p++; /* get list file name from command line */
	listfile[emitlst] = 0;        /* terminate lst file name */
	appendef(listfile, ".lst");
	for (i = strlen(listfile); i > 0;
	     i--) /* extract path, if any for tmp file */
		if (listfile[i] == '\\' || listfile[i] == ']' ||
		    listfile[i] == ':') {
			strcpy(tmpdev, listfile); /* copy list file name */
			tmpdev[i + 1] = 0;        /* terminate after path */
			break;
		}
	if (*p != '=') /* find src file(s) */
		error_msg("too many output files specified", "", 2); /* error */
	if (*p == '=')     /* src files */
		src = ++p; /* pointer to beginning of source file list */

	while (*p) {                    /* get switches */
		while (*p != '/' && *p) /* find a slash */
			p++;
		if (*p == '/') {
			p++;
			switch (toupper(c = *p)) {
				case 'A':
					absasm = TRUE;
					break;
				case 'L':
					assumeL = TRUE;
					break;
				case 'N':
					prnerrcon = FALSE;
					break;
				case 'S':
					wide = FALSE;
					break;
				case 'T':
					prnsymtab = FALSE;
					break;
				case 'V':
					prnxref = FALSE;
					break;
				case 'X':
					prnxref = TRUE;
					break;
				case 'H':
					help();
					exit(0);
				case 'M':
					for (maxmaclev = 0;
					     isdigit(*++p) && maxmaclev < 100;
					     maxmaclev =
					             maxmaclev * 10 + *p - '0')
						;
					if (maxmaclev > 1 && maxmaclev < 1000)
						break;
					error_msg(
					        "bad /M switch - max macro "
					        "depth must be 2-999",
					        "", 2);
				case 'P':
					for (maxpass = 0;
					     isdigit(*++p) && maxpass < 100;
					     maxpass = maxpass * 10 + *p - '0')
						;
					if (maxpass > 1 && maxpass < 100) break;
					error_msg(
					        "bad /P switch - maxpass must "
					        "be 2-99",
					        "", 2);
				case 'C':
					cputype = *++p - '0';
					if (cputype >= 0 && cputype <= 3) break;
					error_msg(
					        "illegal parameter after /C "
					        "switch",
					        p, 2);
				case 'D':
					i = 0;
					while ((c = *++p)) {
						if (c == '/') break;
						tmpdev[i++] = c;
						tmpdev[i] = 0;
					}
					break;
				case 'R':
					error_msg(
					        "Illegal switch, absolute "
					        "assembly only.",
					        p, 2);
				default:
					error_msg("unknown switch", p, 2);
			}
		}
	}
	tmpnam(s1 = p1);          /* generate temporary file name */
	if (*s1 == '\\')          /* PC puts a backslash here */
		for (; *s1; s1++) /* remove it */
			*s1 = s1[1];
	strcat(tmpdev, p1);
	strcat(tmpdev, ".tmp");
	if (emitobj)
		if ((file_obj = fopen(objfile, "w")) == NULL)
			error_msg("Could not open object file: ", objfile, 4);
	if (emitlst)
		if ((file_lst = fopen(listfile, "w")) == NULL)
			error_msg("Could not open list file: ", listfile, 4);
	if ((file_tmp = fopen(tmpdev, "w+")) == NULL)
		error_msg("Could not open temp file: ", "", 4);
	p = src;
	while (*p && !isspace(*p)) {
		if (*p == ',') *p = 0; /* null separates src file names */
		if (*p == '/')         /* end of list of source files */
			break;
		p++;
	}
	*p++ = 0;
	*p++ = 0; /* double null at end of list of source files */

	if (!*src)
		error_msg("command syntax error", "", 2); /* no source files */

	/* initialize a few things */

	lbn[0] = lbn[1] = lbn[2] = lbn[3] = 'A';
	dbyt = word = byte = FALSE;
	macro_head = NULL;  /* no macros defined yet */
	root_symtab = NULL; /* symbols defined yet */
	pass = 1;
	codebytes = binlin = binadr = binptr = chksum = 0;
	fnptr = forcelong = errcount = tmpcounter = 0;
	condlevel = macrolevel = endflag = loc_cntr = subttl[0] = 0;
	radix = 10;
	condit = TRUE;
	linenum = list = mlist = gen = 1;
	clist = 1;
	formln = 55;
	strcpy(name, ".MAIN."); /* default title */
	spechar = ' ';
	strcpy(cur_sect, "A"); /* default section name */
	insert_symbol(cur_sect, 0L, TRUE, TRUE,
	              TRUE); /* enter section name in table */
	ptr->section = TRUE; /* flag it as a section name */
	time(&tyme);
	strcpy(datetime, asctime(localtime(&tyme))); /* get time and date */
	for (i = strlen(datetime) - 1; i && isspace(datetime[i]); i--)
		datetime[i] = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl $0x0, 0xc2c3(%rip)      # 0xd958
movl $0x1, %eax
movl %eax, 0xc2bc(%rip)      # 0xd95c
movl %eax, 0xc21a(%rip)      # 0xd8c0
movl %eax, 0xc14c(%rip)      # 0xd7f8
movl %eax, 0xc2ae(%rip)      # 0xd960
movl %eax, 0xc2ac(%rip)      # 0xd964
movl $0x3, 0xc1f6(%rip)      # 0xd8b8
movl $0xf, 0xc124(%rip)      # 0xd7f0
movl $0x32, 0xc292(%rip)     # 0xd968
movb $0x0, 0xc1f3(%rip)      # 0xd8d0
cmpl $0x2, %edi
jl 0x16f4
movq 0x8(%rsi), %rsi
leaq 0xc283(%rip), %rdi      # 0xd970
callq 0x1080
jmp 0x1717
leaq 0x89e4(%rip), %rdi      # 0xa0df
xorl %eax, %eax
callq 0x10e0
leaq 0x9362(%rip), %rdi      # 0xaa6b
leaq 0xc260(%rip), %rsi      # 0xd970
xorl %eax, %eax
callq 0x11d0
movl $0x482f, %eax           # imm = 0x482F
xorl 0xc24e(%rip), %eax      # 0xd970
movzbl 0xc249(%rip), %ecx      # 0xd972
orw %ax, %cx
je 0x1e36
movl $0x682f, %eax           # imm = 0x682F
xorl 0xc233(%rip), %eax      # 0xd970
movzbl 0xc22e(%rip), %ecx      # 0xd972
orw %ax, %cx
je 0x1e36
movl $0x0, 0xc0c9(%rip)      # 0xd820
leaq 0xc212(%rip), %r12      # 0xd970
xorl %eax, %eax
leaq 0xc0c9(%rip), %rbx      # 0xd830
movabsq $0x2000900000000001, %r15 # imm = 0x2000900000000001
movzbl (%r12), %r13d
cmpq $0x3d, %r13
ja 0x1782
btq %r13, %r15
jb 0x1794
incq %r12
movb %r13b, (%rax,%rbx)
incq %rax
movl %eax, 0xc08e(%rip)      # 0xd820
jmp 0x1771
cltq
movb $0x0, (%rax,%rbx)
leaq 0x894a(%rip), %rsi      # 0xa0eb
movq %rbx, %rdi
callq 0x1e44
movq %rbx, %rdi
callq 0x10b0
movl %eax, %ebp
movabsq $0xc00000001, %r14      # imm = 0xC00000001
decq %rbp
testl %ebp, %ebp
jle 0x17f8
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movzbl (%rax,%rbx), %eax
addl $-0x3a, %eax
cmpl $0x23, %eax
ja 0x17bd
btq %rax, %r14
jae 0x17bd
leaq 0xc0ec(%rip), %rbx      # 0xd8d0
leaq 0xc045(%rip), %rsi      # 0xd830
movq %rbx, %rdi
callq 0x1080
movb $0x0, 0x1(%rbp,%rbx)
movl $0x0, 0xc0ba(%rip)      # 0xd8bc
cmpb $0x2c, %r13b
jne 0x183d
movl $0x1, %ecx
xorl %eax, %eax
movabsq $0x100000000, %rdx      # imm = 0x100000000
movzbl (%r12,%rcx), %esi
cmpq $0x3d, %rsi
ja 0x182a
btq %rsi, %r15
jb 0x1844
movl %ecx, 0xc08c(%rip)      # 0xd8bc
movb %sil, 0xf(%rsp,%rcx)
addq %rdx, %rax
incq %rcx
jmp 0x1819
incq %r12
xorl %eax, %eax
jmp 0x184b
sarq $0x20, %rax
addq %rcx, %r12
movb $0x0, 0x10(%rsp,%rax)
leaq 0x8899(%rip), %rsi      # 0xa0f0
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e44
movq %rbx, %rdi
callq 0x10b0
movq %rax, %rbx
testl %ebx, %ebx
jle 0x18b5
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
incq %rbx
movzbl 0xf(%rsp,%rbx), %eax
addl $-0x3a, %eax
cmpl $0x23, %eax
ja 0x188f
btq %rax, %r14
jb 0x189a
decq %rbx
cmpq $0x1, %rbx
jg 0x187c
jmp 0x18b5
leaq 0xc02f(%rip), %r14      # 0xd8d0
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x1080
movl %ebx, %eax
movb $0x0, (%rax,%r14)
cmpb $0x3d, (%r12)
je 0x18dc
leaq 0x8832(%rip), %rdi      # 0xa0f5
leaq 0x926d(%rip), %rsi      # 0xab37
movl $0x2, %edx
callq 0x1e8b
movb (%r12), %al
cmpb $0x3d, %al
jne 0x18eb
movb 0x1(%r12), %al
incq %r12
movq %r12, 0xbdc5(%rip)      # 0xd6b0
testb %al, %al
je 0x1b30
leaq 0x870a(%rip), %r14      # 0xa004
leaq 0xbfd0(%rip), %r13      # 0xd8d1
leaq 0x922f(%rip), %rbx      # 0xab37
testb %al, %al
je 0x1947
movzbl %al, %eax
cmpl $0x2f, %eax
jne 0x1959
leaq 0x1(%r12), %r15
callq 0x1030
movq (%rax), %rax
movsbq 0x1(%r12), %rcx
movl (%rax,%rcx,4), %eax
addl $-0x41, %eax
cmpl $0x17, %eax
ja 0x199b
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movl $0x1, 0xc01b(%rip)      # 0xd960
jmp 0x194a
movq %r12, %r15
movb (%r15), %al
movq %r15, %r12
testb %al, %al
jne 0x1908
jmp 0x1b30
movb 0x1(%r12), %al
incq %r12
jmp 0x1908
movl $0x0, 0xbf53(%rip)      # 0xd8c0
jmp 0x194a
movl $0x1, 0xbfe3(%rip)      # 0xd95c
jmp 0x194a
movl $0x0, 0xbfdf(%rip)      # 0xd964
jmp 0x194a
leaq 0x87fc(%rip), %rdi      # 0xa18a
movq %r15, %rsi
movl $0x2, %edx
callq 0x1e8b
leaq 0x8810(%rip), %rdi      # 0xa1b2
movq %r15, %rsi
movl $0x2, %edx
callq 0x1e8b
jmp 0x194a
callq 0x1230
movq %rax, %rbp
jmp 0x1a69
movl $0x1, 0xbf90(%rip)      # 0xd958
jmp 0x194a
callq 0x1230
movq %rax, %rbp
movq (%rax), %rax
movl $0x0, 0xbf89(%rip)      # 0xd968
movsbq 0x2(%r12), %rdx
addq $0x2, %r12
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x1a1b
movq %r12, %r15
jmp 0x1a55
movl $0x0, 0xbf5d(%rip)      # 0xd95c
jmp 0x194a
movq %r12, %r15
jmp 0x1ad4
movl $0x0, 0xbde2(%rip)      # 0xd7f8
jmp 0x194a
xorl %ecx, %ecx
movq %r12, %r15
movsbl %dl, %edx
leal (%rcx,%rcx,4), %ecx
leal (%rdx,%rcx,2), %ecx
addl $-0x30, %ecx
movl %ecx, 0xbf36(%rip)      # 0xd968
movsbq 0x1(%r15), %rdx
incq %r15
testb $0x8, 0x1(%rax,%rdx,2)
je 0x1a46
cmpl $0x64, %ecx
jl 0x1a20
addl $-0x2, %ecx
cmpl $0x3e6, %ecx            # imm = 0x3E6
jb 0x194a
leaq 0x86b9(%rip), %rdi      # 0xa115
movq %rbx, %rsi
movl $0x2, %edx
callq 0x1e8b
movq (%rbp), %rax
movl $0x0, 0xbd79(%rip)      # 0xd7f0
movsbq 0x1(%r15), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x1abd
incq %r15
xorl %ecx, %ecx
movsbl %dl, %edx
leal (%rcx,%rcx,4), %ecx
leal (%rdx,%rcx,2), %ecx
addl $-0x30, %ecx
movl %ecx, 0xbd56(%rip)      # 0xd7f0
movsbq 0x1(%r15), %rdx
incq %r15
testb $0x8, 0x1(%rax,%rdx,2)
je 0x1aae
cmpl $0x64, %ecx
jl 0x1a88
addl $-0x2, %ecx
cmpl $0x62, %ecx
jb 0x194a
decq %r15
leaq 0x867f(%rip), %rdi      # 0xa143
movq %rbx, %rsi
movl $0x2, %edx
callq 0x1e8b
movq %r15, %r12
movsbl 0x2(%r12), %eax
addq $0x2, %r15
movl %eax, %ecx
addl $-0x30, %ecx
movl %ecx, 0xbdcf(%rip)      # 0xd8b8
andb $-0x4, %al
cmpb $0x30, %al
je 0x194a
leaq 0x866e(%rip), %rdi      # 0xa168
movq %r15, %rsi
movl $0x2, %edx
callq 0x1e8b
incq %r15
movq %r13, %rcx
movzbl (%r15), %eax
testl %eax, %eax
je 0x194d
cmpl $0x2f, %eax
je 0x194d
movb %al, -0x1(%rcx)
movb $0x0, (%rcx)
incq %rcx
incq %r15
jmp 0x1b0d
leaq 0xbec9(%rip), %rdi      # 0xda00
movq %rdi, 0xbf4a(%rip)      # 0xda88
callq 0x1220
movq 0xbf3e(%rip), %rax      # 0xda88
cmpb $0x5c, (%rax)
jne 0x1b6c
movb 0x1(%rax), %cl
movb %cl, (%rax)
movq 0xbf2d(%rip), %rcx      # 0xda88
leaq 0x1(%rcx), %rax
movq %rax, 0xbf22(%rip)      # 0xda88
cmpb $0x0, 0x1(%rcx)
jne 0x1b4f
leaq 0xbd5d(%rip), %rbx      # 0xd8d0
leaq 0xbe86(%rip), %rsi      # 0xda00
movq %rbx, %rdi
callq 0x11e0
movq %rbx, %rdi
callq 0x10b0
movl $0x706d742e, (%rax,%rbx) # imm = 0x706D742E
movb $0x0, 0x4(%rax,%rbx)
cmpl $0x0, 0xbc83(%rip)      # 0xd820
je 0x1bd6
leaq 0xbc8a(%rip), %rdi      # 0xd830
leaq 0x8619(%rip), %rsi      # 0xa1c6
callq 0x11c0
movq %rax, 0xbc6f(%rip)      # 0xd828
testq %rax, %rax
jne 0x1bd6
leaq 0x8603(%rip), %rdi      # 0xa1c8
leaq 0xbc64(%rip), %rsi      # 0xd830
movl $0x4, %edx
callq 0x1e8b
cmpl $0x0, 0xbcdf(%rip)      # 0xd8bc
je 0x1c12
leaq 0x85e0(%rip), %rsi      # 0xa1c6
leaq 0x10(%rsp), %rdi
callq 0x11c0
movq %rax, 0xbe99(%rip)      # 0xda90
testq %rax, %rax
jne 0x1c12
leaq 0x85e2(%rip), %rdi      # 0xa1e5
leaq 0x10(%rsp), %rsi
movl $0x4, %edx
callq 0x1e8b
leaq 0xbcb7(%rip), %rdi      # 0xd8d0
leaq 0x84af(%rip), %rsi      # 0xa0cf
callq 0x11c0
movq %rax, 0xbb1c(%rip)      # 0xd748
testq %rax, %rax
jne 0x1c49
leaq 0x85c8(%rip), %rdi      # 0xa200
leaq 0x8ef8(%rip), %rsi      # 0xab37
movl $0x4, %edx
callq 0x1e8b
movq 0xba60(%rip), %rbx      # 0xd6b0
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x1c8b
callq 0x1230
movq (%rax), %rcx
movsbq %bpl, %rdx
testb $0x20, 0x1(%rcx,%rdx,2)
jne 0x1c8b
cmpb $0x2c, %bpl
je 0x1c7c
movzbl %bpl, %ecx
cmpl $0x2f, %ecx
jne 0x1c7f
jmp 0x1c8b
movb $0x0, (%rbx)
movb 0x1(%rbx), %bpl
incq %rbx
testb %bpl, %bpl
jne 0x1c5d
movw $0x0, (%rbx)
movq 0xba19(%rip), %rax      # 0xd6b0
cmpb $0x0, (%rax)
jne 0x1cb4
leaq 0x8578(%rip), %rdi      # 0xa21b
leaq 0x8e8d(%rip), %rsi      # 0xab37
movl $0x2, %edx
callq 0x1e8b
movl $0x41414141, 0xbb5e(%rip) # imm = 0x41414141
xorl %eax, %eax
movl %eax, 0xbdd2(%rip)      # 0xda98
movl %eax, 0xbdd0(%rip)      # 0xda9c
movl %eax, 0xbdce(%rip)      # 0xdaa0
movq %rax, 0xbdcf(%rip)      # 0xdaa8
movq %rax, 0xbdd0(%rip)      # 0xdab0
movl $0x1, %ecx
movl %ecx, 0xbb09(%rip)      # 0xd7f4
movl %eax, 0xbb0b(%rip)      # 0xd7fc
movl %eax, 0xbb09(%rip)      # 0xd800
movl %eax, 0xbb07(%rip)      # 0xd804
movl %eax, 0xbb05(%rip)      # 0xd808
movq %rax, 0xbade(%rip)      # 0xd7e8
movq %rax, 0xbda7(%rip)      # 0xdab8
movl %eax, 0xbb01(%rip)      # 0xd818
movl %eax, 0xbda3(%rip)      # 0xdac0
movl %eax, 0xbda1(%rip)      # 0xdac4
movb $0x0, 0xbda6(%rip)      # 0xdad0
movq %rax, 0xbadf(%rip)      # 0xd810
movl %eax, 0xbe21(%rip)      # 0xdb58
movl %eax, 0xbe1f(%rip)      # 0xdb5c
movl %eax, 0xbe1d(%rip)      # 0xdb60
movl $0xa, 0xbe17(%rip)      # 0xdb64
movl %ecx, 0xbe15(%rip)      # 0xdb68
movl %ecx, 0xbe13(%rip)      # 0xdb6c
movl %ecx, 0xbe11(%rip)      # 0xdb70
movl %ecx, 0xbe0f(%rip)      # 0xdb74
movl %ecx, 0xbe0d(%rip)      # 0xdb78
movl %ecx, 0xbe0b(%rip)      # 0xdb7c
movl $0x37, 0xbe05(%rip)     # 0xdb80
movl $0x49414d2e, 0xbe0b(%rip) # imm = 0x49414D2E
movl $0x2e4e49, 0xbe04(%rip) # imm = 0x2E4E49
movb $0x20, 0xbe80(%rip)     # 0xdc16
movw $0x41, 0xbe81(%rip)     # 0xdc20
leaq 0xbe7a(%rip), %rdi      # 0xdc20
xorl %esi, %esi
movl $0x1, %edx
movl $0x1, %r8d
callq 0x8b70
movq 0xbe81(%rip), %rax      # 0xdc40
orw $0x10, 0x20(%rax)
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1170
movq %rbx, %rdi
callq 0x1050
movq %rax, %rdi
callq 0x10c0
leaq 0xbe68(%rip), %rbx      # 0xdc50
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1080
movq %rbx, %rdi
callq 0x10b0
movq %rax, %r14
decl %r14d
je 0x1e24
callq 0x1230
movq (%rax), %rcx
movslq %r14d, %r14
movsbq (%r14,%rbx), %rdx
testb $0x20, 0x1(%rcx,%rdx,2)
je 0x1e24
movb $0x0, (%r14,%rbx)
decl %r14d
jne 0x1e08
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
callq 0x4e54
xorl %edi, %edi
callq 0x1200