// File: /workspace/github_c_makefile_star2_O3/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 0x13a0
cmpq $0x0, (%rsi)
je 0x13a0
movl %edi, %ebx
movq 0x8(%rsi), %r14
movq %rsi, 0x18(%rsp)
movq 0x10(%rsi), %rax
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x1060
movslq %eax, %r15
movl %ebx, %eax
movq %rax, 0x10(%rsp)
movl $0x3, %r13d
leaq 0x30(%rsp), %rbx
leaq 0x130(%rsp), %rbp
movq 0x18(%rsp), %r12
movq (%r12,%r13,8), %rsi
movq %rbx, %rdi
movq %rsi, 0x20(%rsp)
callq 0x1030
movq %rbx, %rdi
movl $0x2e, %esi
callq 0x1080
testq %rax, %rax
movq %r13, 0x8(%rsp)
je 0x1279
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq (%r12,%r13,8), %rdi
movq %r12, %rbx
jmp 0x1296
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 0xd6c(%rip), %rsi       # 0x2009
callq 0x10b0
testq %rax, %rax
je 0x1374
movq %rax, %r13
leaq 0x30(%rsp), %rdi
leaq 0xd4d(%rip), %rsi       # 0x2007
callq 0x10b0
testq %rax, %rax
je 0x1386
movq %rax, %r12
movq 0x8(%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xd48(%rip), %rdi       # 0x2023
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x10a0
testq %rax, %rax
je 0x1338
movq %rbp, %rdi
movq %r14, %rsi
callq 0x10d0
movq %rbp, %rdi
testq %rax, %rax
je 0x132e
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 0x12e2
movq %r13, %rdi
callq 0x1050
movq %r12, %rdi
callq 0x1050
movq 0x8(%rsp), %r13
incq %r13
cmpq 0x10(%rsp), %r13
leaq 0x30(%rsp), %rbx
jne 0x1239
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 0xc87(%rip), %rdi       # 0x200b
jmp 0x1392
leaq 0xc7e(%rip), %rdi       # 0x200b
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10c0
leaq 0xc90(%rip), %rdi       # 0x2037
callq 0x1040
jmp 0x1399