// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x1239
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x124e
leaq 0xdc4(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10b0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1331
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x1331
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
decl %eax
movl %eax, -0x8(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x154(%rbp)
subl $0x4d, %eax
je 0x12e9
jmp 0x12a8
movl -0x154(%rbp), %eax
subl $0x55, %eax
je 0x12f2
jmp 0x12b5
movl -0x154(%rbp), %eax
subl $0x57, %eax
je 0x12fb
jmp 0x12c2
movl -0x154(%rbp), %eax
subl $0x6d, %eax
je 0x12e9
jmp 0x12cf
movl -0x154(%rbp), %eax
subl $0x75, %eax
je 0x12f2
jmp 0x12dc
movl -0x154(%rbp), %eax
subl $0x77, %eax
je 0x12fb
jmp 0x1304
movl $0x2, -0x24(%rbp)
jmp 0x132f
movl $0x1, -0x24(%rbp)
jmp 0x132f
movl $0x0, -0x24(%rbp)
jmp 0x132f
movq 0x2ced(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movsbl (%rax), %edx
leaq 0xd0b(%rip), %rsi       # 0x2027
movb $0x0, %al
callq 0x1080
movl $0x0, -0x4(%rbp)
jmp 0x1535
jmp 0x1338
movl $0x0, -0x24(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x152e
leaq -0x140(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1030
leaq -0x140(%rbp), %rdi
movl $0x2e, %esi
callq 0x1060
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x1390
movq -0x38(%rbp), %rdi
leaq 0xcad(%rip), %rsi       # 0x2036
callq 0x1030
jmp 0x13a3
leaq -0x140(%rbp), %rdi
leaq 0xc98(%rip), %rsi       # 0x2036
callq 0x10a0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xc85(%rip), %rsi       # 0x203b
callq 0x1090
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x148(%rbp)
jne 0x13ed
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xc5f(%rip), %rdi       # 0x203e
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10b0
leaq -0x140(%rbp), %rdi
leaq 0xc5b(%rip), %rsi       # 0x2056
callq 0x1090
movq %rax, -0x150(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x142d
leaq -0x140(%rbp), %rsi
leaq 0xc1f(%rip), %rdi       # 0x203e
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10b0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xc19(%rip), %rdi       # 0x2059
movb $0x0, %al
callq 0x1050
movl $0x0, -0x20(%rbp)
movq -0x148(%rbp), %rdi
callq 0x10c0
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x1468
jmp 0x14f3
movl -0x18(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x14ee
cmpl $0x7f, -0x1c(%rbp)
je 0x14ee
cmpl $0xd, -0x1c(%rbp)
jne 0x14a1
cmpl $0x1, -0x20(%rbp)
jne 0x1498
movl -0x24(%rbp), %edi
movq -0x150(%rbp), %rsi
callq 0x11d0
movl $0x1, -0x20(%rbp)
jmp 0x14ec
cmpl $0xa, -0x1c(%rbp)
jne 0x14bf
movl -0x24(%rbp), %edi
movq -0x150(%rbp), %rsi
callq 0x11d0
movl $0x2, -0x20(%rbp)
jmp 0x14ea
cmpl $0x1, -0x20(%rbp)
jne 0x14d4
movl -0x24(%rbp), %edi
movq -0x150(%rbp), %rsi
callq 0x11d0
movl -0x1c(%rbp), %edi
movq -0x150(%rbp), %rsi
callq 0x1070
movl $0x0, -0x20(%rbp)
jmp 0x14ec
jmp 0x14ee
jmp 0x144e
cmpl $0x1, -0x20(%rbp)
jne 0x1508
movl -0x24(%rbp), %edi
movq -0x150(%rbp), %rsi
callq 0x11d0
movq -0x148(%rbp), %rdi
callq 0x1040
movq -0x150(%rbp), %rdi
callq 0x1040
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x133f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq