// File: /workspace/github_c_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
cmpl $0x2, %edi
jl 0x145c
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x145c
movq 0x8(%rbx), %rax
xorl %ebp, %ebp
testq %rax, %rax
je 0x12ba
cmpb $0x2d, (%rax)
jne 0x12ba
movzbl 0x1(%rax), %eax
leal -0x4d(%rax), %ecx
cmpl $0x2a, %ecx
ja 0x128e
addq $0x8, %rbx
decl %edi
movabsq $0x100000001, %rdx      # imm = 0x100000001
btq %rcx, %rdx
jb 0x12b5
movabsq $0x10000000100, %rdx    # imm = 0x10000000100
btq %rcx, %rdx
jb 0x12ae
movabsq $0x40000000400, %rdx    # imm = 0x40000000400
btq %rcx, %rdx
jb 0x12ba
movsbl %al, %edx
movq 0x2d60(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xd62(%rip), %rsi       # 0x2004
xorl %eax, %eax
callq 0x10a0
jmp 0x1421
movl $0x1, %ebp
jmp 0x12ba
movl $0x2, %ebp
cmpl $0x2, %edi
jl 0x1421
movl %edi, %eax
movq %rax, 0x8(%rsp)
movl $0x1, %r14d
leaq 0x10(%rsp), %r12
movq %rbx, (%rsp)
movq (%rbx,%r14,8), %rsi
movq %r12, %rdi
callq 0x1030
movq %r12, %rdi
movl $0x2e, %esi
callq 0x1080
testq %rax, %rax
je 0x1303
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
jmp 0x1318
movq %r12, %rdi
callq 0x1060
movl $0x77656e2e, 0x10(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x14(%rsp,%rax)
movq (%rbx,%r14,8), %rdi
leaq 0xcf5(%rip), %rsi       # 0x2018
callq 0x10b0
testq %rax, %rax
je 0x1435
movq %rax, %r15
movq %r12, %rdi
leaq 0xcf5(%rip), %rsi       # 0x2033
callq 0x10b0
testq %rax, %rax
je 0x1442
movq %rax, %r12
movq (%rbx,%r14,8), %rsi
leaq 0xcdc(%rip), %rdi       # 0x2036
xorl %eax, %eax
callq 0x1070
movq %r15, %rdi
callq 0x10d0
cmpl $-0x1, %eax
je 0x13fe
movl %eax, %r13d
xorl %ebx, %ebx
andl $0x7f, %r13d
cmpl $0xc, %r13d
jg 0x139d
testl %r13d, %r13d
je 0x13db
cmpl $0xa, %r13d
jne 0x13bf
movl %ebp, %edi
movq %r12, %rsi
callq 0x11dc
movl $0x2, %ebx
jmp 0x13db
cmpl $0x7f, %r13d
je 0x13db
cmpl $0xd, %r13d
jne 0x13bf
cmpl $0x1, %ebx
jne 0x13b8
movl %ebp, %edi
movq %r12, %rsi
callq 0x11dc
movl $0x1, %ebx
jmp 0x13db
cmpl $0x1, %ebx
jne 0x13ce
movl %ebp, %edi
movq %r12, %rsi
callq 0x11dc
movl %r13d, %edi
movq %r12, %rsi
callq 0x1090
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x10d0
movl %eax, %r13d
cmpl $-0x1, %eax
jne 0x1377
cmpl $0x1, %ebx
movq (%rsp), %rbx
jne 0x13fe
movl %ebp, %edi
movq %r12, %rsi
callq 0x11dc
movq %r15, %rdi
callq 0x1050
movq %r12, %rdi
callq 0x1050
incq %r14
cmpq 0x8(%rsp), %r14
leaq 0x10(%rsp), %r12
jne 0x12d9
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx,%r14,8), %rsi
leaq 0xbdb(%rip), %rdi       # 0x201b
jmp 0x144e
leaq 0xbd2(%rip), %rdi       # 0x201b
leaq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10c0
leaq 0xbe7(%rip), %rdi       # 0x204a
callq 0x1040
jmp 0x1455