// File: /workspace/github_c_makefile_star2_O1/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 $0x228, %rsp            # imm = 0x228
cmpl $0x4, %edi
jl 0x138c
cmpq $0x0, (%rsi)
je 0x138c
movl %edi, %ebx
movq 0x8(%rsi), %r14
movq %rsi, 0x10(%rsp)
movq 0x10(%rsi), %rax
movq %rax, 0x18(%rsp)
movq %r14, %rdi
callq 0x1060
movslq %eax, %r15
movl %ebx, %eax
movq %rax, 0x8(%rsp)
movl $0x3, %r12d
leaq 0x20(%rsp), %r13
leaq 0x120(%rsp), %rbp
movq 0x10(%rsp), %rbx
movq (%rbx,%r12,8), %rsi
movq %r13, %rdi
callq 0x1030
movq %r13, %rdi
movl $0x2e, %esi
callq 0x1080
testq %rax, %rax
je 0x1268
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
jmp 0x127d
movq %r13, %rdi
callq 0x1060
movl $0x77656e2e, 0x20(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x24(%rsp,%rax)
movq %r12, (%rsp)
movq (%rbx,%r12,8), %rdi
leaq 0xd7d(%rip), %rsi       # 0x2009
callq 0x10b0
testq %rax, %rax
je 0x1361
movq %rax, %r13
leaq 0x20(%rsp), %rdi
leaq 0xd5e(%rip), %rsi       # 0x2007
callq 0x10b0
testq %rax, %rax
je 0x1372
movq %rax, %r12
movq (%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xd5a(%rip), %rdi       # 0x2023
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x10a0
testq %rax, %rax
je 0x1326
movq %rbp, %rdi
movq %r14, %rsi
callq 0x10d0
movq %rbp, %rdi
testq %rax, %rax
je 0x131c
movq %rax, %rbx
movb $0x0, (%rax)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1090
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x1090
addq %r15, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1090
jmp 0x12d0
movq %r13, %rdi
callq 0x1050
movq %r12, %rdi
callq 0x1050
movq (%rsp), %r12
incq %r12
cmpq 0x8(%rsp), %r12
leaq 0x20(%rsp), %r13
jne 0x1239
xorl %eax, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xc9b(%rip), %rdi       # 0x200b
jmp 0x137e
leaq 0xc92(%rip), %rdi       # 0x200b
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10c0
leaq 0xca4(%rip), %rdi       # 0x2037
callq 0x1040
jmp 0x1385