// File: /workspace/github_c_makefile_star2_O1/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, 0xc2c5(%rip)      # 0xd958
movl $0x1, %eax
movl %eax, 0xc2be(%rip)      # 0xd95c
movl %eax, 0xc21c(%rip)      # 0xd8c0
movl %eax, 0xc14e(%rip)      # 0xd7f8
movl %eax, 0xc2b0(%rip)      # 0xd960
movl %eax, 0xc2ae(%rip)      # 0xd964
movl $0x3, 0xc1f8(%rip)      # 0xd8b8
movl $0xf, 0xc126(%rip)      # 0xd7f0
movl $0x32, 0xc294(%rip)     # 0xd968
movb $0x0, 0xc1f5(%rip)      # 0xd8d0
cmpl $0x2, %edi
jl 0x16f2
movq 0x8(%rsi), %rsi
leaq 0xc285(%rip), %rdi      # 0xd970
callq 0x1080
jmp 0x1715
leaq 0x89e6(%rip), %rdi      # 0xa0df
xorl %eax, %eax
callq 0x10e0
leaq 0x9364(%rip), %rdi      # 0xaa6b
leaq 0xc262(%rip), %rsi      # 0xd970
xorl %eax, %eax
callq 0x11d0
movl $0x482f, %eax           # imm = 0x482F
xorl 0xc250(%rip), %eax      # 0xd970
movzbl 0xc24b(%rip), %ecx      # 0xd972
orw %ax, %cx
je 0x1e3f
movl $0x682f, %eax           # imm = 0x682F
xorl 0xc235(%rip), %eax      # 0xd970
movzbl 0xc230(%rip), %ecx      # 0xd972
orw %ax, %cx
je 0x1e3f
movl $0x0, 0xc0cb(%rip)      # 0xd820
leaq 0xc214(%rip), %r13      # 0xd970
xorl %eax, %eax
leaq 0xc0cb(%rip), %rbx      # 0xd830
movabsq $0x2000900000000001, %r15 # imm = 0x2000900000000001
movzbl (%r13), %r12d
cmpq $0x3d, %r12
ja 0x1780
btq %r12, %r15
jb 0x1792
incq %r13
movb %r12b, (%rax,%rbx)
incq %rax
movl %eax, 0xc090(%rip)      # 0xd820
jmp 0x176f
movslq 0xc087(%rip), %rax      # 0xd820
movb $0x0, (%rax,%rbx)
leaq 0x8947(%rip), %rsi      # 0xa0eb
movq %rbx, %rdi
callq 0x1e4d
movq %rbx, %rdi
callq 0x10b0
movl %eax, %ebp
movabsq $0xc00000001, %r14      # imm = 0xC00000001
decq %rbp
testl %ebp, %ebp
jle 0x17fb
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movzbl (%rax,%rbx), %eax
addl $-0x3a, %eax
cmpl $0x23, %eax
ja 0x17c0
btq %rax, %r14
jae 0x17c0
leaq 0xc0e9(%rip), %rbx      # 0xd8d0
leaq 0xc042(%rip), %rsi      # 0xd830
movq %rbx, %rdi
callq 0x1080
movb $0x0, 0x1(%rbp,%rbx)
movl $0x0, 0xc0b7(%rip)      # 0xd8bc
cmpb $0x2c, %r12b
jne 0x1846
movl 0xc0ab(%rip), %eax      # 0xd8bc
movslq %eax, %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
movl $0x1, %ecx
movzbl (%r13,%rcx), %esi
cmpq $0x3d, %rsi
ja 0x1833
btq %rsi, %r15
jb 0x184b
leal (%rax,%rcx), %edi
movl %edi, 0xc080(%rip)      # 0xd8bc
movb %sil, -0x1(%rdx,%rcx)
incq %rcx
jmp 0x1821
incq %r13
jmp 0x184e
addq %rcx, %r13
movslq 0xc067(%rip), %rax      # 0xd8bc
movb $0x0, 0x10(%rsp,%rax)
leaq 0x888f(%rip), %rsi      # 0xa0f0
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e4d
movq %rbx, %rdi
callq 0x10b0
movq %rax, %rbx
testl %ebx, %ebx
jle 0x18bf
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
incq %rbx
movzbl 0xf(%rsp,%rbx), %eax
addl $-0x3a, %eax
cmpl $0x23, %eax
ja 0x1899
btq %rax, %r14
jb 0x18a4
decq %rbx
cmpq $0x1, %rbx
jg 0x1886
jmp 0x18bf
leaq 0xc025(%rip), %r14      # 0xd8d0
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x1080
movl %ebx, %eax
movb $0x0, (%rax,%r14)
cmpb $0x3d, (%r13)
je 0x18de
leaq 0x8828(%rip), %rdi      # 0xa0f5
leaq 0x9263(%rip), %rsi      # 0xab37
movl $0x2, %edx
callq 0x1e94
cmpb $0x3d, (%r13)
jne 0x18ef
incq %r13
movq %r13, 0xbdc1(%rip)      # 0xd6b0
cmpb $0x0, (%r13)
je 0x1b33
leaq 0x88b1(%rip), %rbx      # 0xa1b2
leaq 0x86fc(%rip), %r14      # 0xa004
leaq 0xbfc2(%rip), %rbp      # 0xd8d1
leaq 0x9221(%rip), %r12      # 0xab37
movzbl (%r13), %eax
testl %eax, %eax
je 0x1a21
cmpl $0x2f, %eax
jne 0x195c
leaq 0x1(%r13), %r15
callq 0x1030
movq (%rax), %rax
movsbq 0x1(%r13), %rcx
movl (%rax,%rcx,4), %eax
addl $-0x41, %eax
cmpl $0x17, %eax
ja 0x19a2
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movl $0x1, 0xc009(%rip)      # 0xd960
jmp 0x1a24
incq %r13
jmp 0x1916
movl $0x0, 0xbf55(%rip)      # 0xd8c0
jmp 0x1a24
movl $0x1, 0xbfe2(%rip)      # 0xd95c
jmp 0x1a24
movl $0x0, 0xbfdb(%rip)      # 0xd964
jmp 0x1a24
leaq 0x87f5(%rip), %rdi      # 0xa18a
movq %r15, %rsi
movl $0x2, %edx
callq 0x1e94
movq %rbx, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x1e94
jmp 0x1a24
movq %r15, %r13
jmp 0x1a62
movl $0x1, 0xbf92(%rip)      # 0xd958
jmp 0x1a24
callq 0x1230
movq (%rax), %rcx
movl $0x0, 0xbf8e(%rip)      # 0xd968
movsbq 0x2(%r13), %rdx
addq $0x2, %r13
xorl %eax, %eax
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x1a1d
movsbl %dl, %edx
leal (%rax,%rax,4), %eax
leal (%rdx,%rax,2), %eax
addl $-0x30, %eax
movl %eax, 0xbf6a(%rip)      # 0xd968
movsbq 0x1(%r13), %rdx
incq %r13
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x1a12
cmpl $0x64, %eax
jl 0x19ec
addl $-0x2, %eax
cmpl $0x3e6, %eax            # imm = 0x3E6
setb %al
testb %al, %al
je 0x1a4e
movq %r13, %r15
cmpb $0x0, (%r15)
movq %r15, %r13
jne 0x1916
jmp 0x1b33
movl $0x0, 0xbf1c(%rip)      # 0xd95c
jmp 0x1a24
movl $0x0, 0xbdac(%rip)      # 0xd7f8
jmp 0x1a24
leaq 0x86c0(%rip), %rdi      # 0xa115
movq %r12, %rsi
movl $0x2, %edx
callq 0x1e94
callq 0x1230
movq (%rax), %rcx
movl $0x0, 0xbd7c(%rip)      # 0xd7f0
leaq 0x1(%r13), %r15
movsbq 0x1(%r13), %rdx
xorl %eax, %eax
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x1ab9
movsbl %dl, %edx
leal (%rax,%rax,4), %eax
leal (%rdx,%rax,2), %eax
addl $-0x30, %eax
movl %eax, 0xbd58(%rip)      # 0xd7f0
movsbq 0x1(%r15), %rdx
incq %r15
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x1aac
cmpl $0x64, %eax
jl 0x1a86
addl $-0x2, %eax
cmpl $0x62, %eax
setb %al
leaq -0x1(%r15), %r13
testb %al, %al
jne 0x1a24
leaq 0x867b(%rip), %rdi      # 0xa143
movq %r12, %rsi
movl $0x2, %edx
callq 0x1e94
movsbl 0x2(%r13), %eax
movq %r13, %r15
addq $0x2, %r15
movl %eax, %ecx
addl $-0x30, %ecx
movl %ecx, 0xbdcc(%rip)      # 0xd8b8
andb $-0x4, %al
cmpb $0x30, %al
je 0x1a24
leaq 0x866b(%rip), %rdi      # 0xa168
movq %r15, %rsi
movl $0x2, %edx
callq 0x1e94
incq %r15
movq %rbp, %rax
movzbl (%r15), %ecx
testl %ecx, %ecx
je 0x1a24
cmpl $0x2f, %ecx
je 0x1a24
movb %cl, -0x1(%rax)
movb $0x0, (%rax)
incq %rax
incq %r15
jmp 0x1b10
leaq 0xbec6(%rip), %rdi      # 0xda00
movq %rdi, 0xbf47(%rip)      # 0xda88
callq 0x1220
movq 0xbf3b(%rip), %rax      # 0xda88
cmpb $0x5c, (%rax)
jne 0x1b7b
movq 0xbf2f(%rip), %rax      # 0xda88
cmpb $0x0, (%rax)
je 0x1b7b
movb 0x1(%rax), %cl
movb %cl, (%rax)
movq 0xbf1e(%rip), %rcx      # 0xda88
leaq 0x1(%rcx), %rax
movq %rax, 0xbf13(%rip)      # 0xda88
cmpb $0x0, 0x1(%rcx)
jne 0x1b5e
leaq 0xbd4e(%rip), %rbx      # 0xd8d0
leaq 0xbe77(%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, 0xbc74(%rip)      # 0xd820
je 0x1be5
leaq 0xbc7b(%rip), %rdi      # 0xd830
leaq 0x860a(%rip), %rsi      # 0xa1c6
callq 0x11c0
movq %rax, 0xbc60(%rip)      # 0xd828
testq %rax, %rax
jne 0x1be5
leaq 0x85f4(%rip), %rdi      # 0xa1c8
leaq 0xbc55(%rip), %rsi      # 0xd830
movl $0x4, %edx
callq 0x1e94
cmpl $0x0, 0xbcd0(%rip)      # 0xd8bc
je 0x1c21
leaq 0x85d1(%rip), %rsi      # 0xa1c6
leaq 0x10(%rsp), %rdi
callq 0x11c0
movq %rax, 0xbe8a(%rip)      # 0xda90
testq %rax, %rax
jne 0x1c21
leaq 0x85d3(%rip), %rdi      # 0xa1e5
leaq 0x10(%rsp), %rsi
movl $0x4, %edx
callq 0x1e94
leaq 0xbca8(%rip), %rdi      # 0xd8d0
leaq 0x84a0(%rip), %rsi      # 0xa0cf
callq 0x11c0
movq %rax, 0xbb0d(%rip)      # 0xd748
testq %rax, %rax
jne 0x1c58
leaq 0x85b9(%rip), %rdi      # 0xa200
leaq 0x8ee9(%rip), %rsi      # 0xab37
movl $0x4, %edx
callq 0x1e94
movq 0xba51(%rip), %rbx      # 0xd6b0
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x1c94
callq 0x1230
movq (%rax), %rcx
movsbq %bpl, %rdx
testb $0x20, 0x1(%rcx,%rdx,2)
jne 0x1c94
cmpb $0x2c, %bpl
jne 0x1c83
movb $0x0, (%rbx)
cmpb $0x2f, (%rbx)
je 0x1c94
movb 0x1(%rbx), %bpl
incq %rbx
testb %bpl, %bpl
jne 0x1c6c
movw $0x0, (%rbx)
movq 0xba10(%rip), %rax      # 0xd6b0
cmpb $0x0, (%rax)
jne 0x1cbd
leaq 0x856f(%rip), %rdi      # 0xa21b
leaq 0x8e84(%rip), %rsi      # 0xab37
movl $0x2, %edx
callq 0x1e94
movl $0x41414141, 0xbb55(%rip) # imm = 0x41414141
xorl %eax, %eax
movl %eax, 0xbdc9(%rip)      # 0xda98
movl %eax, 0xbdc7(%rip)      # 0xda9c
movl %eax, 0xbdc5(%rip)      # 0xdaa0
movq %rax, 0xbdc6(%rip)      # 0xdaa8
movq %rax, 0xbdc7(%rip)      # 0xdab0
movl $0x1, %ecx
movl %ecx, 0xbb00(%rip)      # 0xd7f4
movl %eax, 0xbb02(%rip)      # 0xd7fc
movl %eax, 0xbb00(%rip)      # 0xd800
movl %eax, 0xbafe(%rip)      # 0xd804
movl %eax, 0xbafc(%rip)      # 0xd808
movq %rax, 0xbad5(%rip)      # 0xd7e8
movq %rax, 0xbd9e(%rip)      # 0xdab8
movl %eax, 0xbaf8(%rip)      # 0xd818
movl %eax, 0xbd9a(%rip)      # 0xdac0
movl %eax, 0xbd98(%rip)      # 0xdac4
movb $0x0, 0xbd9d(%rip)      # 0xdad0
movq %rax, 0xbad6(%rip)      # 0xd810
movl %eax, 0xbe18(%rip)      # 0xdb58
movl %eax, 0xbe16(%rip)      # 0xdb5c
movl %eax, 0xbe14(%rip)      # 0xdb60
movl $0xa, 0xbe0e(%rip)      # 0xdb64
movl %ecx, 0xbe0c(%rip)      # 0xdb68
movl %ecx, 0xbe0a(%rip)      # 0xdb6c
movl %ecx, 0xbe08(%rip)      # 0xdb70
movl %ecx, 0xbe06(%rip)      # 0xdb74
movl %ecx, 0xbe04(%rip)      # 0xdb78
movl %ecx, 0xbe02(%rip)      # 0xdb7c
movl $0x37, 0xbdfc(%rip)     # 0xdb80
movl $0x49414d2e, 0xbe02(%rip) # imm = 0x49414D2E
movl $0x2e4e49, 0xbdfb(%rip) # imm = 0x2E4E49
movb $0x20, 0xbe77(%rip)     # 0xdc16
movw $0x41, 0xbe78(%rip)     # 0xdc20
leaq 0xbe71(%rip), %rdi      # 0xdc20
xorl %esi, %esi
movl $0x1, %edx
movl $0x1, %r8d
callq 0x8b5e
movq 0xbe78(%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 0xbe5f(%rip), %rbx      # 0xdc50
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1080
movq %rbx, %rdi
callq 0x10b0
movq %rax, %r14
decl %r14d
je 0x1e2d
callq 0x1230
movq (%rax), %rcx
movslq %r14d, %r14
movsbq (%r14,%rbx), %rdx
testb $0x20, 0x1(%rcx,%rdx,2)
je 0x1e2d
movb $0x0, (%r14,%rbx)
decl %r14d
jne 0x1e11
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
callq 0x4d84
xorl %edi, %edi
callq 0x1200