// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/asc/asc.c
// Function: main
int main (int argc, char *argv[])
{
int i, k, mc, lastc;
int mode;
char *s, *ppos, oname[256];
FILE *ifile, *ofile;

if ((argc < 2) || (argv[0] == NULL)) {
	printf ("Usage is: asc -muw file [file...]\n");
	exit (0);  }

s = argv[1];
if ((s != NULL) && (*s++ == '-')) {
	++argv; --argc;
	switch (*s) {
 	case 'm': case 'M':
	    mode = MD_MAC;  break;
	case 'u': case 'U':
	    mode = MD_UNIX; break;
        case 'w': case 'W':
	    mode = MD_WIN; break;
	default:
	    fprintf (stderr, "Bad option %c\n", *s);
	return 0;  }
	}
else mode = MD_WIN;

for (i = 1; i < argc; i++) {
	strcpy (oname, argv[i]);
        if (ppos = strrchr (oname, '.')) strcpy (ppos, ".new");
            else strcat (oname, ".new");
	ifile = fopen (argv[i], "rb");
	if (ifile == NULL) {
	    printf ("Error opening file: %s\n", argv[i]);
	    exit (0);  }
	ofile = fopen (oname, "wb");
	if (ofile == NULL) {
	    printf ("Error opening file: %s\n", oname);
	    exit (0);  }

	printf ("Processing file %s\n", argv[i]);
	for (lastc = LAST_ANY;;) {
	    k = getc (ifile);
	    if (k == EOF) break;
	    mc = k & 0177;
	    if (mc && (mc != 0177)) {
		if (mc == 015) {
		    if (lastc == LAST_CR) puteol (mode, ofile);
		    lastc = LAST_CR;  }
		else if (mc == 012) {
		    puteol (mode, ofile);
		    lastc = LAST_LF;  }
		else {
		    if (lastc == LAST_CR) puteol (mode, ofile);
		    putc (mc, ofile);
		    lastc = LAST_ANY;  }
		}
	    }
	if (lastc == LAST_CR) puteol (mode, ofile);
	fclose (ifile);
	fclose (ofile);
	}
return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
cmpl $0x2, %edi
jl 0x1456
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x1456
movq 0x8(%rbx), %rax
movl $0x0, 0xc(%rsp)
testq %rax, %rax
je 0x12ce
cmpb $0x2d, (%rax)
jne 0x12ce
movzbl 0x1(%rax), %eax
leal -0x4d(%rax), %ecx
cmpl $0x2a, %ecx
ja 0x1294
addq $0x8, %rbx
decl %edi
movabsq $0x100000001, %rdx      # imm = 0x100000001
btq %rcx, %rdx
jb 0x12c7
movabsq $0x10000000100, %rdx    # imm = 0x10000000100
btq %rcx, %rdx
jb 0x12c3
movabsq $0x40000000400, %rdx    # imm = 0x40000000400
btq %rcx, %rdx
jb 0x12ce
movsbl %al, %edx
movq 0x2d5a(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xd5c(%rip), %rsi       # 0x2004
xorl %eax, %eax
callq 0x10a0
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
jmp 0x12c9
pushq $0x2
popq %rax
movl %eax, 0xc(%rsp)
movl %edi, %eax
movq %rax, 0x18(%rsp)
pushq $0x1
popq %rbp
leaq 0x20(%rsp), %r14
movq %rbx, 0x10(%rsp)
cmpq 0x18(%rsp), %rbp
jae 0x12af
movq (%rbx,%rbp,8), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1030
movq %r14, %rdi
pushq $0x2e
popq %rsi
callq 0x1080
testq %rax, %rax
je 0x1318
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq (%rbx,%rbp,8), %r15
jmp 0x132d
movq %r14, %rdi
callq 0x1060
movl $0x77656e2e, 0x20(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x24(%rsp,%rax)
movq %r15, %rdi
leaq 0xce1(%rip), %rsi       # 0x2018
callq 0x10b0
testq %rax, %rax
je 0x142a
movq %rax, %r12
movq %r14, %rbx
movq %r14, %rdi
leaq 0xcde(%rip), %rsi       # 0x2033
callq 0x10b0
testq %rax, %rax
je 0x143c
movq %rax, %r13
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rsi
xorl %r14d, %r14d
leaq 0xcbd(%rip), %rdi       # 0x2036
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
callq 0x10d0
cmpl $-0x1, %eax
je 0x13f8
movl %eax, %r15d
andl $0x7f, %r15d
je 0x1380
cmpl $0x7f, %r15d
je 0x1380
cmpl $0xa, %r15d
je 0x13c4
cmpl $0xd, %r15d
jne 0x13d6
cmpl $0x1, %r14d
pushq $0x1
popq %r14
jne 0x1380
movl 0xc(%rsp), %edi
movq %r13, %rsi
callq 0x11dc
pushq $0x1
popq %r14
jmp 0x1380
movl 0xc(%rsp), %edi
movq %r13, %rsi
callq 0x11dc
pushq $0x2
popq %r14
jmp 0x1380
cmpl $0x1, %r14d
jne 0x13e8
movl 0xc(%rsp), %edi
movq %r13, %rsi
callq 0x11dc
movl %r15d, %edi
movq %r13, %rsi
callq 0x1090
xorl %r14d, %r14d
jmp 0x1380
cmpl $0x1, %r14d
jne 0x140a
movl 0xc(%rsp), %edi
movq %r13, %rsi
callq 0x11dc
movq %r12, %rdi
callq 0x1050
movq %r13, %rdi
callq 0x1050
incq %rbp
movq %rbx, %r14
movq 0x10(%rsp), %rbx
jmp 0x12e2
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rsi
leaq 0xbe1(%rip), %rdi       # 0x201b
jmp 0x1448
leaq 0xbd8(%rip), %rdi       # 0x201b
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10c0
leaq 0xbed(%rip), %rdi       # 0x204a
callq 0x1040
jmp 0x144f