// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/strsub/strsub.c
// Function: main
int main (int argc, char *argv[])
{
int i, rmvlen;
char *ppos, *fpos, *tpos, *rmv, *ins, oname[256], line[256];
FILE *ifile, *ofile;

if ((argc < 4) || (argv[0] == NULL)) {
	printf ("Usage is: strsub s1 s2 file [file...]\n");
	exit (0);  }

rmv = argv[1];
rmvlen = strlen (rmv);
ins = argv[2];
for (i = 3; i < argc; i++) {
	strcpy (oname, argv[i]);
        if (ppos = strrchr (oname, '.')) strcpy (ppos, ".new");
            else strcat (oname, ".new");
	ifile = fopen (argv[i], "r");
	if (ifile == NULL) {
	    printf ("Error opening file: %s\n", argv[i]);
	    exit (0);  }
	ofile = fopen (oname, "w");
	if (ofile == NULL) {
	    printf ("Error opening file: %s\n", oname);
	    exit (0);  }

	printf ("Processing file %s\n", argv[i]);
	while (fgets (line, 255, ifile) != NULL) {
	    tpos = strstr (line, rmv);
	    if (tpos) {
                *tpos = 0;
                fputs (line, ofile);
		fputs (ins, ofile);
		fpos = tpos + rmvlen;
		fputs (fpos, ofile);
		}
	    else fputs (line, ofile);
	    }
	fclose (ifile);
	fclose (ofile);
	}
return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
cmpl $0x4, %edi
jl 0x13a4
movq %rsi, %r15
cmpq $0x0, (%rsi)
je 0x13a4
movl %edi, %ebx
movq 0x8(%r15), %r14
movq %r14, %rdi
callq 0x1060
movq %r15, 0x10(%rsp)
movq 0x10(%r15), %rcx
movq %rcx, 0x28(%rsp)
movslq %eax, %r15
movl %ebx, %eax
movq %rax, 0x18(%rsp)
pushq $0x3
popq %r13
leaq 0x30(%rsp), %rbx
leaq 0x130(%rsp), %rbp
cmpq 0x18(%rsp), %r13
je 0x1364
movq 0x10(%rsp), %r12
movq (%r12,%r13,8), %rsi
movq %rbx, %rdi
movq %rsi, 0x20(%rsp)
callq 0x1030
movq %rbx, %rdi
pushq $0x2e
popq %rsi
callq 0x1080
testq %rax, %rax
movq %r13, 0x8(%rsp)
je 0x1283
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq (%r12,%r13,8), %rdi
movq %r12, %rbx
jmp 0x12a0
movq %rbx, %rdi
callq 0x1060
movl $0x77656e2e, 0x30(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x34(%rsp,%rax)
movq %r12, %rbx
movq 0x20(%rsp), %rdi
leaq 0xd62(%rip), %rsi       # 0x2009
callq 0x10b0
testq %rax, %rax
je 0x1378
movq %rax, %r13
leaq 0x30(%rsp), %rdi
leaq 0xd43(%rip), %rsi       # 0x2007
callq 0x10b0
testq %rax, %rax
je 0x138a
movq %rax, %r12
movq 0x8(%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xd3e(%rip), %rdi       # 0x2023
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x10a0
testq %rax, %rax
je 0x1342
movq %rbp, %rdi
movq %r14, %rsi
callq 0x10d0
movq %rbp, %rdi
testq %rax, %rax
je 0x1338
movq %rax, %rbx
movb $0x0, (%rax)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1090
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x1090
addq %r15, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1090
jmp 0x12ec
movq %r13, %rdi
callq 0x1050
movq %r12, %rdi
callq 0x1050
movq 0x8(%rsp), %r13
incq %r13
leaq 0x30(%rsp), %rbx
jmp 0x123a
xorl %eax, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xc83(%rip), %rdi       # 0x200b
jmp 0x1396
leaq 0xc7a(%rip), %rdi       # 0x200b
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10c0
leaq 0xc8c(%rip), %rdi       # 0x2037
callq 0x1040
jmp 0x139d