// File: /workspace/github_c_makefile_star2_O3/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 0x146b
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x146b
movq 0x8(%rbx), %rax
xorl %ebp, %ebp
testq %rax, %rax
je 0x12af
cmpb $0x2d, (%rax)
jne 0x12af
movzbl 0x1(%rax), %eax
leal -0x4d(%rax), %ecx
cmpl $0x2a, %ecx
ja 0x1427
movabsq $0x100000001, %rdx      # imm = 0x100000001
btq %rcx, %rdx
jb 0x129b
movabsq $0x10000000100, %rdx    # imm = 0x10000000100
btq %rcx, %rdx
jb 0x1294
movabsq $0x40000000400, %rdx    # imm = 0x40000000400
btq %rcx, %rdx
jae 0x1427
xorl %ebp, %ebp
jmp 0x12a0
movl $0x1, %ebp
jmp 0x12a0
movl $0x2, %ebp
decl %edi
cmpl $0x2, %edi
jb 0x1413
addq $0x8, %rbx
movl %edi, %eax
movq %rax, 0x8(%rsp)
movl $0x1, %r14d
leaq 0x10(%rsp), %r12
movq %rbx, (%rsp)
movq (%rbx,%r14,8), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x1030
movq %r12, %rdi
movl $0x2e, %esi
callq 0x1080
testq %rax, %rax
je 0x12f6
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq (%rbx,%r14,8), %r15
jmp 0x130b
movq %r12, %rdi
callq 0x1060
movl $0x77656e2e, 0x10(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x14(%rsp,%rax)
movq %r15, %rdi
leaq 0xd03(%rip), %rsi       # 0x2018
callq 0x10b0
testq %rax, %rax
je 0x1444
movq %rax, %r15
movq %r12, %rdi
leaq 0xd03(%rip), %rsi       # 0x2033
callq 0x10b0
testq %rax, %rax
je 0x1451
movq %rax, %r12
movq (%rbx,%r14,8), %rsi
leaq 0xcea(%rip), %rdi       # 0x2036
xorl %eax, %eax
callq 0x1070
movq %r15, %rdi
callq 0x10d0
cmpl $-0x1, %eax
je 0x13f0
movl %eax, %r13d
xorl %ebx, %ebx
andl $0x7f, %r13d
cmpl $0xc, %r13d
jg 0x138f
testl %r13d, %r13d
je 0x13cd
cmpl $0xa, %r13d
jne 0x13b1
movl %ebp, %edi
movq %r12, %rsi
callq 0x11dc
movl $0x2, %ebx
jmp 0x13cd
cmpl $0x7f, %r13d
je 0x13cd
cmpl $0xd, %r13d
jne 0x13b1
cmpl $0x1, %ebx
jne 0x13aa
movl %ebp, %edi
movq %r12, %rsi
callq 0x11dc
movl $0x1, %ebx
jmp 0x13cd
cmpl $0x1, %ebx
jne 0x13c0
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 0x1369
cmpl $0x1, %ebx
movq (%rsp), %rbx
jne 0x13f0
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 0x12c5
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl %al, %edx
movq 0x2bc7(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xbc9(%rip), %rsi       # 0x2004
xorl %eax, %eax
callq 0x10a0
jmp 0x1413
movq (%rbx,%r14,8), %rsi
leaq 0xbcc(%rip), %rdi       # 0x201b
jmp 0x145d
leaq 0xbc3(%rip), %rdi       # 0x201b
leaq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10c0
leaq 0xbd8(%rip), %rdi       # 0x204a
callq 0x1040
jmp 0x1464