// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, 0xc304(%rip)      # 0xd968
pushq $0x1
popq %rax
movl %eax, 0xc2ff(%rip)      # 0xd96c
movl %eax, 0xc25d(%rip)      # 0xd8d0
movl %eax, 0xc18f(%rip)      # 0xd808
movl %eax, 0xc2f1(%rip)      # 0xd970
movl %eax, 0xc2ef(%rip)      # 0xd974
movl $0x3, 0xc239(%rip)      # 0xd8c8
movl $0xf, 0xc167(%rip)      # 0xd800
movl $0x32, 0xc2d5(%rip)     # 0xd978
movb $0x0, 0xc236(%rip)      # 0xd8e0
cmpl $0x2, %edi
jl 0x16c1
movq 0x8(%rsi), %rsi
leaq 0xc2c6(%rip), %rdi      # 0xd980
callq 0x1080
jmp 0x16e4
leaq 0x7a17(%rip), %rdi      # 0x90df
xorl %eax, %eax
callq 0x10e0
leaq 0x8377(%rip), %rdi      # 0x9a4d
leaq 0xc2a3(%rip), %rsi      # 0xd980
xorl %eax, %eax
callq 0x11e0
leaq 0xc295(%rip), %rdi      # 0xd980
leaq 0x79f3(%rip), %rsi      # 0x90e5
pushq $0x3
popq %rdx
callq 0x11a0
testl %eax, %eax
je 0x1d8e
leaq 0xc277(%rip), %rbx      # 0xd980
leaq 0x79d8(%rip), %rsi      # 0x90e8
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0x11a0
testl %eax, %eax
je 0x1d8e
andl $0x0, 0xc106(%rip)      # 0xd830
xorl %eax, %eax
leaq 0xc10d(%rip), %r15      # 0xd840
movabsq $0x2000900000000001, %r12 # imm = 0x2000900000000001
movzbl (%rbx), %ebp
cmpq $0x3d, %rbp
ja 0x174c
btq %rbp, %r12
jb 0x175e
incq %rbx
movb %bpl, (%rax,%r15)
incq %rax
movl %eax, 0xc0d4(%rip)      # 0xd830
jmp 0x173d
cltq
movb $0x0, (%rax,%r15)
leaq 0x797f(%rip), %rsi      # 0x90eb
movq %r15, %rdi
callq 0x1d9c
movq %r15, %rdi
callq 0x10b0
movl %eax, %r14d
movabsq $0xc00000001, %r13      # imm = 0xC00000001
decq %r14
testl %r14d, %r14d
jle 0x17c8
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movzbl (%rax,%r15), %eax
addl $-0x3a, %eax
cmpl $0x23, %eax
ja 0x1789
btq %rax, %r13
jae 0x1789
leaq 0xc12d(%rip), %r15      # 0xd8e0
leaq 0xc086(%rip), %rsi      # 0xd840
movq %r15, %rdi
callq 0x1080
movb $0x0, 0x1(%r14,%r15)
andl $0x0, 0xc0fd(%rip)      # 0xd8cc
cmpb $0x2c, %bpl
jne 0x1807
pushq $0x1
popq %rcx
xorl %eax, %eax
movabsq $0x100000000, %rdx      # imm = 0x100000000
movzbl (%rbx,%rcx), %esi
cmpq $0x3d, %rsi
ja 0x17f4
btq %rsi, %r12
jb 0x180e
movl %ecx, 0xc0d2(%rip)      # 0xd8cc
movb %sil, 0xf(%rsp,%rcx)
addq %rdx, %rax
incq %rcx
jmp 0x17e4
incq %rbx
xorl %eax, %eax
jmp 0x1815
sarq $0x20, %rax
addq %rcx, %rbx
movb $0x0, 0x10(%rsp,%rax)
leaq 0x78cf(%rip), %rsi      # 0x90f0
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x1d9c
movq %r15, %rdi
callq 0x10b0
movq %rax, %r12
movl %r12d, %eax
incl %r12d
leaq 0xc09a(%rip), %r15      # 0xd8e0
addq %r15, %r12
testl %eax, %eax
jle 0x187e
movzbl 0x10(%rsp,%rax), %ecx
addl $-0x3a, %ecx
cmpl $0x23, %ecx
ja 0x1860
btq %rcx, %r13
jb 0x1868
decq %rax
decq %r12
jmp 0x1849
leaq 0xc071(%rip), %rdi      # 0xd8e0
leaq 0x10(%rsp), %rsi
callq 0x1080
movb $0x0, (%r12)
cmpb $0x3d, (%rbx)
je 0x189e
leaq 0x786b(%rip), %rdi      # 0x90f5
leaq 0x8288(%rip), %rsi      # 0x9b19
pushq $0x2
popq %rdx
callq 0x1ddf
cmpb $0x3d, (%rbx)
jne 0x18a8
incq %rbx
movq %rbx, 0xbe18(%rip)      # 0xd6c0
pushq $0x2
popq %rbp
leaq 0x7752(%rip), %r12      # 0x9004
movb (%rbx), %al
testb %al, %al
je 0x1a8d
leaq 0x1(%rbx), %rcx
addq $0x2, %rbx
movq %rbx, %r14
movq %rcx, %rbx
testb %al, %al
je 0x190c
movzbl %al, %eax
cmpl $0x2f, %eax
je 0x18e0
movb (%rbx), %al
incq %rbx
incq %r14
jmp 0x18ca
callq 0x1030
movq (%rax), %rax
movsbq (%rbx), %rcx
movl (%rax,%rcx,4), %eax
addl $-0x41, %eax
cmpl $0x17, %eax
ja 0x1940
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, 0xc066(%rip)      # 0xd970
jmp 0x18b2
decq %rbx
jmp 0x18b2
andl $0x0, 0xbfb8(%rip)      # 0xd8d0
jmp 0x18b2
movl $0x1, 0xc048(%rip)      # 0xd96c
jmp 0x18b2
andl $0x0, 0xc047(%rip)      # 0xd974
jmp 0x18b2
leaq 0x7854(%rip), %rdi      # 0x918a
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1ddf
leaq 0x786b(%rip), %rdi      # 0x91b2
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1ddf
jmp 0x18b2
callq 0x1240
movq %rax, %r13
jmp 0x19c6
movl $0x1, 0xbffe(%rip)      # 0xd968
jmp 0x18b2
callq 0x1240
movq %rax, %r13
movq (%rax), %rax
xorl %ecx, %ecx
movq %r14, %rbx
movl %ecx, 0xbff3(%rip)      # 0xd978
movsbq (%rbx), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x19a2
cmpl $0x63, %ecx
jg 0x19a2
imull $0xa, %ecx, %ecx
addl %edx, %ecx
addl $-0x30, %ecx
incq %rbx
jmp 0x197f
addl $-0x2, %ecx
cmpl $0x3e6, %ecx            # imm = 0x3E6
jb 0x18b2
leaq 0x775d(%rip), %rdi      # 0x9115
leaq 0x815a(%rip), %rsi      # 0x9b19
movl %ebp, %edx
callq 0x1ddf
movq (%r13), %rax
incq %rbx
xorl %ecx, %ecx
movl %ecx, 0xbe2b(%rip)      # 0xd800
movsbq (%rbx), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x19f2
cmpl $0x63, %ecx
jg 0x19f2
imull $0xa, %ecx, %ecx
addl %edx, %ecx
addl $-0x30, %ecx
incq %rbx
jmp 0x19cf
addl $-0x2, %ecx
cmpl $0x62, %ecx
jb 0x18b2
decq %rbx
leaq 0x773b(%rip), %rdi      # 0x9143
leaq 0x810a(%rip), %rsi      # 0x9b19
movl %ebp, %edx
callq 0x1ddf
jmp 0x1a27
andl $0x0, 0xbf4d(%rip)      # 0xd96c
jmp 0x18b2
decq %rbx
movsbl 0x2(%rbx), %eax
addq $0x2, %rbx
movl %eax, %ecx
addl $-0x30, %ecx
movl %ecx, 0xbe8e(%rip)      # 0xd8c8
andb $-0x4, %al
cmpb $0x30, %al
je 0x18b2
leaq 0x771d(%rip), %rdi      # 0x9168
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1ddf
incq %rbx
leaq 0xbe82(%rip), %rax      # 0xd8e1
movzbl (%rbx), %ecx
testl %ecx, %ecx
je 0x18b2
cmpl $0x2f, %ecx
je 0x18b2
movb %cl, -0x1(%rax)
movb $0x0, (%rax)
incq %rax
incq %rbx
jmp 0x1a5f
andl $0x0, 0xbd80(%rip)      # 0xd808
jmp 0x18b2
leaq 0xbf7c(%rip), %rdi      # 0xda10
movq %rdi, 0xbffd(%rip)      # 0xda98
callq 0x1230
movq 0xbff1(%rip), %rax      # 0xda98
cmpb $0x5c, (%rax)
jne 0x1ace
movb $0x5c, %cl
testb %cl, %cl
je 0x1ace
movb 0x1(%rax), %cl
movb %cl, (%rax)
movq 0xbfda(%rip), %rcx      # 0xda98
leaq 0x1(%rcx), %rax
movq %rax, 0xbfcf(%rip)      # 0xda98
movb 0x1(%rcx), %cl
jmp 0x1aae
leaq 0xbf3b(%rip), %rsi      # 0xda10
movq %r15, %rdi
callq 0x11f0
movq %r15, %rdi
callq 0x10b0
movl $0x706d742e, (%rax,%r15) # imm = 0x706D742E
movb $0x0, 0x4(%rax,%r15)
cmpl $0x0, 0xbd36(%rip)      # 0xd830
je 0x1b31
leaq 0xbd3d(%rip), %rdi      # 0xd840
leaq 0x76bc(%rip), %rsi      # 0x91c6
callq 0x11d0
movq %rax, 0xbd22(%rip)      # 0xd838
testq %rax, %rax
jne 0x1b31
leaq 0x76a6(%rip), %rdi      # 0x91c8
leaq 0xbd17(%rip), %rsi      # 0xd840
pushq $0x4
popq %rdx
callq 0x1ddf
cmpl $0x0, 0xbd94(%rip)      # 0xd8cc
je 0x1b6b
leaq 0x7685(%rip), %rsi      # 0x91c6
leaq 0x10(%rsp), %rdi
callq 0x11d0
movq %rax, 0xbf4e(%rip)      # 0xdaa0
testq %rax, %rax
jne 0x1b6b
leaq 0x7687(%rip), %rdi      # 0x91e5
leaq 0x10(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x1ddf
leaq 0xbd6e(%rip), %rdi      # 0xd8e0
leaq 0x7556(%rip), %rsi      # 0x90cf
callq 0x11d0
movq %rax, 0xbbd3(%rip)      # 0xd758
testq %rax, %rax
jne 0x1ba0
leaq 0x766f(%rip), %rdi      # 0x9200
leaq 0x7f81(%rip), %rsi      # 0x9b19
pushq $0x4
popq %rdx
callq 0x1ddf
movq 0xbb19(%rip), %rbx      # 0xd6c0
movsbq (%rbx), %r14
testq %r14, %r14
je 0x1bd9
callq 0x1240
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
jne 0x1bd9
cmpb $0x2c, %r14b
je 0x1bd1
movzbl %r14b, %eax
cmpl $0x2f, %eax
jne 0x1bd4
jmp 0x1bd9
movb $0x0, (%rbx)
incq %rbx
jmp 0x1ba7
andw $0x0, (%rbx)
movq 0xbadc(%rip), %rax      # 0xd6c0
cmpb $0x0, (%rax)
jne 0x1bff
leaq 0x762b(%rip), %rdi      # 0x921b
leaq 0x7f22(%rip), %rsi      # 0x9b19
pushq $0x2
popq %rdx
callq 0x1ddf
andl $0x0, 0xbea2(%rip)      # 0xdaa8
andl $0x0, 0xbe9f(%rip)      # 0xdaac
andl $0x0, 0xbe9c(%rip)      # 0xdab0
andq $0x0, 0xbe9c(%rip)      # 0xdab8
andq $0x0, 0xbe9c(%rip)      # 0xdac0
andl $0x0, 0xbbe1(%rip)      # 0xd80c
andl $0x0, 0xbbde(%rip)      # 0xd810
andl $0x0, 0xbbdb(%rip)      # 0xd814
andl $0x0, 0xbbd8(%rip)      # 0xd818
andq $0x0, 0xbbb0(%rip)      # 0xd7f8
andq $0x0, 0xbe78(%rip)      # 0xdac8
andl $0x0, 0xbbd1(%rip)      # 0xd828
andl $0x0, 0xbe72(%rip)      # 0xdad0
andl $0x0, 0xbe6f(%rip)      # 0xdad4
movl $0x41414141, 0xbbbd(%rip) # imm = 0x41414141
andq $0x0, 0xbba9(%rip)      # 0xd820
pushq $0x1
popq %rcx
movl %ecx, 0xbb84(%rip)      # 0xd804
andl $0x0, 0xbee1(%rip)      # 0xdb68
movb $0x0, 0xbe52(%rip)      # 0xdae0
andl $0x0, 0xbed7(%rip)      # 0xdb6c
andl $0x0, 0xbed4(%rip)      # 0xdb70
movl $0xa, 0xbece(%rip)      # 0xdb74
movl %ecx, 0xbecc(%rip)      # 0xdb78
movl %ecx, 0xbeca(%rip)      # 0xdb7c
movl %ecx, 0xbec8(%rip)      # 0xdb80
movl %ecx, 0xbec6(%rip)      # 0xdb84
movl %ecx, 0xbec4(%rip)      # 0xdb88
movl %ecx, 0xbec2(%rip)      # 0xdb8c
movl $0x37, 0xbebc(%rip)     # 0xdb90
movl $0x2e4e49, 0xbec5(%rip) # imm = 0x2E4E49
movl $0x49414d2e, 0xbeb8(%rip) # imm = 0x49414D2E
movb $0x20, 0xbf37(%rip)     # 0xdc26
movw $0x41, 0xbf38(%rip)     # 0xdc30
leaq 0xbf31(%rip), %rdi      # 0xdc30
xorl %esi, %esi
movl %ecx, %edx
movl %ecx, %r8d
callq 0x812d
movq 0xbf3e(%rip), %rax      # 0xdc50
orw $0x10, 0x20(%rax)
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1170
movq %rbx, %rdi
callq 0x1050
movq %rax, %rdi
callq 0x10c0
leaq 0xbf25(%rip), %rbx      # 0xdc60
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1080
movq %rbx, %rdi
callq 0x10b0
movq %rax, %r14
decl %r14d
movl %r14d, %ebp
subl $0x1, %ebp
jb 0x1d7c
callq 0x1240
movq (%rax), %rcx
movslq %r14d, %rax
movsbq (%rax,%rbx), %rdx
testb $0x20, 0x1(%rcx,%rdx,2)
je 0x1d7c
movb $0x0, (%rax,%rbx)
movl %ebp, %r14d
jmp 0x1d57
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
callq 0x4b18
xorl %edi, %edi
callq 0x1210