// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/indent/indent.c
// Function: main
int main (int argc, char *argv[])
{
int i, j, fill, itc, incomm, in8tab, ip, op;
char *ppos, iline[256], oline[256], oname[256];
FILE *ifile, *ofile;

if ((argc < 2) || (argv[0] == NULL)) {
	printf ("Usage is: asc file [file...]\n");
	exit (0);  }

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], "ra");
	if (ifile == NULL) {
	    printf ("Error opening file: %s\n", argv[i]);
	    exit (0);  }
	ofile = fopen (oname, "wa");
	if (ofile == NULL) {
	    printf ("Error opening file: %s\n", oname);
	    exit (0);  }

	printf ("Processing file %s\n", argv[i]);
	for (incomm = in8tab = 0;;) {
	    for (j = 0; j < 256; j++) iline[j] = oline[j] = 0;
	    if (fgets (iline, 256, ifile) == NULL) break;
	    ip = 0;
	    if (!incomm) {
		    if (strncmp (iline, "    ", 4) == 0) in8tab = 1;
		    else if (!isspace (iline[0]) && (iline[0] != '#') && strncmp (iline, "/*", 2)) in8tab = 0;
		    if ((strncmp (iline, "else {\t", 7) == 0) &&
		        !isspace (iline[7])) {
		        fputs ("else {\n", ofile);
		        ip = 6;
		        }
		    else if ((strncmp (iline, "do {\t", 5) == 0) &&
		        !isspace (iline[5])) {
		        fputs ("do {\n", ofile);
		        ip = 4;
		        }
		    }
	    for (itc = op = 0; iline[ip]; ip++) {
		    if (!incomm && (op == 0)) {
		        if (iline[ip] == '\t') {
			        itc++;
			        continue;
			        }
		        else if (itc) {
			        fill = (itc * 8) - (in8tab? 0: 4);
			        while (fill--) oline[op++] = ' ';
			        }
		        }
		    switch (iline[ip]) {
		    case '/':
		        if (!incomm && (iline[ip + 1] == '*')) {
			    incomm = 1;
			    if (ip != 0) {
			        while (op < COMM_POS) oline[op++] = ' ';
			        }
			    }
		        oline[op++] = iline[ip];
		        break;
		    case '*':
		        if (incomm && (iline[ip + 1] == '/')) incomm = 0;
		        oline[op++] = iline[ip];
		        break;
		    case '\t':
		        fill = 8 - (op % 8);
		        while (fill--) oline[op++] = ' ';
		        break;
		    case '\r':
		        break;
		    default:
		        oline[op++] = iline[ip];
		        break;
		        }
		    }
	    if (op) fputs (oline, ofile);
	    }
	fclose (ifile);
	fclose (ofile);
	}
return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
cmpl $0x2, %edi
jl 0x15c4
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x15c4
movl %edi, %eax
movq %rax, 0x20(%rsp)
pushq $0x1
popq %r14
leaq 0x230(%rsp), %r13
xorl %r12d, %r12d
movq %rbx, 0x18(%rsp)
cmpq 0x20(%rsp), %r14
je 0x1586
movq (%rbx,%r14,8), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0x1030
movq %r13, %rdi
pushq $0x2e
popq %rsi
callq 0x1080
testq %rax, %rax
je 0x1278
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq (%rbx,%r14,8), %r15
jmp 0x1293
movq %r13, %rdi
callq 0x1060
movl $0x77656e2e, 0x230(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x234(%rsp,%rax)
movq %r15, %rdi
leaq 0xd6c(%rip), %rsi       # 0x2009
callq 0x10d0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x159a
movq %r13, %rdi
leaq 0xd6a(%rip), %rsi       # 0x2024
callq 0x10d0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x15a7
movq %r14, 0x28(%rsp)
movq (%rbx,%r14,8), %rsi
xorl %r13d, %r13d
leaq 0xd47(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1070
xorl %ebx, %ebx
leaq 0x30(%rsp), %rdi
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x130a
movb %r12b, 0x130(%rsp,%rax)
movb %r12b, 0x30(%rsp,%rax)
incq %rax
jmp 0x12f0
movl $0x100, %esi            # imm = 0x100
movq 0x10(%rsp), %rdx
callq 0x10b0
testq %rax, %rax
je 0x1558
testl %r13d, %r13d
je 0x132f
movl %ebx, %r15d
jmp 0x13ea
movl 0x30(%rsp), %r14d
pushq $0x1
popq %r15
cmpl $0x20202020, %r14d      # imm = 0x20202020
je 0x136e
callq 0x10f0
movq (%rax), %rax
movsbq %r14b, %rcx
cmpw $0x2a2f, %r14w          # imm = 0x2A2F
movl $0x0, %r15d
cmovel %ebx, %r15d
testb $0x20, 0x1(%rax,%rcx,2)
cmovnel %ebx, %r15d
cmpb $0x23, %r14b
cmovel %ebx, %r15d
leaq 0x30(%rsp), %rdi
leaq 0xcc1(%rip), %rsi       # 0x203b
pushq $0x7
popq %rdx
callq 0x10c0
testl %eax, %eax
jne 0x13a6
callq 0x10f0
movq (%rax), %rax
movsbq 0x37(%rsp), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
leaq 0xca3(%rip), %rdi       # 0x2043
pushq $0x6
popq %r14
je 0x13de
leaq 0x30(%rsp), %rdi
leaq 0xc99(%rip), %rsi       # 0x204b
pushq $0x5
popq %rdx
callq 0x10c0
testl %eax, %eax
jne 0x13ea
callq 0x10f0
movq (%rax), %rax
movsbq 0x35(%rsp), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
leaq 0xc79(%rip), %rdi       # 0x2051
pushq $0x4
popq %r14
jne 0x13ea
movq 0x8(%rsp), %rsi
callq 0x1090
jmp 0x13ed
xorl %r14d, %r14d
leaq 0x30(%rsp), %rdi
pushq $0x8
popq %r8
xorl %eax, %eax
testl %r15d, %r15d
setne %al
leal -0x4(,%rax,4), %ebx
xorl %ebp, %ebp
xorl %esi, %esi
movzbl 0x30(%rsp,%r14), %eax
testl %eax, %eax
je 0x152e
movl %r13d, %ecx
orl %esi, %ecx
jne 0x144a
cmpb $0x9, %al
jne 0x142e
incl %ebp
xorl %r13d, %r13d
xorl %esi, %esi
jmp 0x1526
testl %ebp, %ebp
je 0x1448
leal (%rbx,%rbp,8), %ecx
xorl %esi, %esi
cmpl %esi, %ecx
je 0x144a
movb $0x20, 0x130(%rsp,%rsi)
incq %rsi
jmp 0x1437
xorl %esi, %esi
movslq %esi, %rcx
cmpl $0x9, %eax
je 0x148e
cmpl $0xd, %eax
je 0x1526
cmpl $0x2a, %eax
je 0x1473
cmpl $0x2f, %eax
jne 0x14ba
testl %r13d, %r13d
je 0x14c5
pushq $0x1
popq %r13
jmp 0x1509
testl %r13d, %r13d
je 0x1518
xorl %r13d, %r13d
cmpb $0x2f, 0x1(%r14,%rdi)
setne %r13b
jmp 0x151b
movl %ecx, %eax
cltd
idivl %r8d
leaq (%rsp,%rcx), %rax
addq $0x130, %rax            # imm = 0x130
negl %edx
movslq %edx, %rcx
addq $0x8, %rcx
xorl %edx, %edx
cmpl %edx, %ecx
je 0x14b6
movb $0x20, (%rax,%rdx)
incq %rdx
jmp 0x14a9
addl %edx, %esi
jmp 0x1526
incl %esi
movb %al, 0x130(%rsp,%rcx)
jmp 0x1526
xorl %r13d, %r13d
cmpb $0x2a, 0x1(%r14,%rdi)
jne 0x1509
testq %r14, %r14
je 0x146a
cmpl $0x37, %esi
jg 0x146a
leaq (%rsp,%rcx), %rdi
addq $0x130, %rdi            # imm = 0x130
pushq $0x37
popq %rax
movl %eax, %edx
subl %esi, %edx
incq %rdx
pushq $0x20
popq %rsi
callq 0x10a0
pushq $0x8
popq %r8
leaq 0x30(%rsp), %rdi
pushq $0x1
popq %r13
pushq $0x38
popq %rax
movl %eax, %esi
movslq %esi, %rax
incl %esi
movb $0x2f, 0x130(%rsp,%rax)
jmp 0x1526
xorl %r13d, %r13d
leal 0x1(%rcx), %esi
movb $0x2a, 0x130(%rsp,%rcx)
incq %r14
jmp 0x1409
movl %r15d, %ebx
testl %esi, %esi
je 0x12ee
leaq 0x130(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1090
leaq 0x30(%rsp), %rdi
movl %r15d, %ebx
jmp 0x12ee
movq 0x10(%rsp), %rdi
callq 0x1050
movq 0x8(%rsp), %rdi
callq 0x1050
movq 0x28(%rsp), %r14
incq %r14
movq 0x18(%rsp), %rbx
leaq 0x230(%rsp), %r13
jmp 0x123e
xorl %eax, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx,%r14,8), %rsi
leaq 0xa67(%rip), %rdi       # 0x200c
jmp 0x15b6
leaq 0xa5e(%rip), %rdi       # 0x200c
leaq 0x230(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10e0
leaq 0xa8c(%rip), %rdi       # 0x2057
callq 0x1040
jmp 0x15bd