// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
jl 0x1209
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x121e
leaq 0xdf4(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10c0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1050
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x3, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1413
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 0x1070
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x129a
movq -0x20(%rbp), %rdi
leaq 0xd98(%rip), %rsi       # 0x202b
callq 0x1030
jmp 0x12ad
leaq -0x140(%rbp), %rdi
leaq 0xd83(%rip), %rsi       # 0x202b
callq 0x10b0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xd70(%rip), %rsi       # 0x2030
callq 0x10a0
movq %rax, -0x248(%rbp)
cmpq $0x0, -0x248(%rbp)
jne 0x12f7
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd49(%rip), %rdi       # 0x2032
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10c0
leaq -0x140(%rbp), %rdi
leaq 0xd29(%rip), %rsi       # 0x202e
callq 0x10a0
movq %rax, -0x250(%rbp)
cmpq $0x0, -0x250(%rbp)
jne 0x1337
leaq -0x140(%rbp), %rsi
leaq 0xd09(%rip), %rdi       # 0x2032
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10c0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd00(%rip), %rdi       # 0x204a
movb $0x0, %al
callq 0x1060
leaq -0x240(%rbp), %rdi
movq -0x248(%rbp), %rdx
movl $0xff, %esi
callq 0x1090
cmpq $0x0, %rax
je 0x13ed
leaq -0x240(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x10d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x13d5
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
leaq -0x240(%rbp), %rdi
movq -0x250(%rbp), %rsi
callq 0x1080
movq -0x40(%rbp), %rdi
movq -0x250(%rbp), %rsi
callq 0x1080
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x250(%rbp), %rsi
callq 0x1080
jmp 0x13e8
leaq -0x240(%rbp), %rdi
movq -0x250(%rbp), %rsi
callq 0x1080
jmp 0x1351
movq -0x248(%rbp), %rdi
callq 0x1040
movq -0x250(%rbp), %rdi
callq 0x1040
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1249
xorl %eax, %eax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq