// File: /workspace/github_c_makefile_star2_O3/nimble-code[P]Modex/Src/xtract.c
// Function: handle_instrumented
static void
handle_instrumented(treenode *root, char *my_fname)
{	int noreset = 0;

	if (in_pars == 1)	/* parentheses */
	{	par_cnt = 0;

		setup_fct_call(root, my_fname);

		// handle a possible return value from the call

		if (strncmp(OrigBuf, "A: ", 3) == 0)	// called in assignment
		{	char *pq1, *pq2;
			pq1 = strrchr(OrigBuf, '[');
			pq2 = strrchr(OrigBuf, ']');
			if (pq1 && (!pq2 || pq1 > pq2))
			{	goto here;
			}

			strcat(OrigBuf, " now.res_p_");
			strcat(OrigBuf, my_fname);
		} else if (strncmp(OrigBuf, "C: ", 3) == 0) // called in condition
		{	strcat(OrigBuf, " now.res_p_");
			strcat(OrigBuf, my_fname);

			// already generated the return value of the call
			// fprintf(fp, " ret_%s?eval(_pid);\n", my_fname);
			// reset the return lock early -- it is otherwise done below
			// this risks a race-condition if another caller of the function
			// completes, and sets the return value to a different value
			// before this caller can read the current one
			// we have to reset early though, because this cannot appear inside
			// the condition

			fprintf(fp, " lck_p_%s_ret = 0;\n", my_fname);
			noreset = 1;	// dont reset again
			if ((Verbose&2) && is_do_condition)
			{	fprintf(stderr, "%s: %s:%d: warning, calling instrumented ",
					progname, root->hdr.fnm, root->hdr.line);
				fprintf(stderr, "function %s() in a loop-condition\n", my_fname);

			}

		} else if (strncmp(OrigBuf, "D: ", 3) == 0) // called in declaration
		{	strcat(OrigBuf, " now.res_p_");
			strcat(OrigBuf, my_fname);
			
			fprintf(stderr, "%s: %s:%d: error, cannot use instrumented ",
				progname, root->hdr.fnm, root->hdr.line);
			fprintf(stderr, "function call %s() inside a declaration\n",
				my_fname);
		} else if (strncmp(OrigBuf, "R: ", 3) == 0)	// called in return stmnt */
		{	// fprintf(stderr, "No problem: %s\n", OrigBuf);
			goto here;
		} else	/* F: */
		{	char *p1, *p2;
here:			p1 = strrchr(OrigBuf, '[');
			p2 = strrchr(OrigBuf, ']');
			if (p1 && (!p2 || p1 > p2))
			{
				fprintf(stderr, "%s: %s:%d: warning, using instrumented ",
					progname, root->hdr.fnm, root->hdr.line);
				fprintf(stderr, "function call %s() in array index (%s)\n",
					my_fname, OrigBuf);

				fprintf(fp, " lck_p_%s_ret = 0;\n", my_fname);
				noreset = 1;	// dont reset again

				/* assuming there's just one function call... */
				strcat(OrigBuf, " now.res_p_");
				strcat(OrigBuf, my_fname);
				strcat(OrigBuf, " ");
			}
		//	strcat(OrigBuf, " /* ");
		//	strcat(OrigBuf, my_fname); /* no return val */
		//	strcat(OrigBuf, "()  */");
		}

		// lck_ is set when the function returns a value
		// the lock should be reset, whether or not the return
		// value is picked up by the caller, i.e., for both A: and F:

		if (!noreset)	// if not already done
		{	strcat(OrigBuf, "; now.lck_p_");
			strcat(OrigBuf, my_fname);
			strcat(OrigBuf, "_ret = 0");
		}
		strcpy(OutBuf, OrigBuf);
	} else
	{	fprintf(fp, "\t/* fct call in paramlist: %s */", my_fname);
		fprintf(stderr, "%s: %s:%d: error, cannot use call to ",
			progname, root->hdr.fnm, root->hdr.line);
		fprintf(stderr, "instrumented fct %s() in a param list\n", my_fname);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x1, 0x29b04(%rip)     # 0x3eacc
jne 0x15292
movl $0x0, 0x32e20(%rip)     # 0x47df8
leaq 0x23a51(%rip), %rax     # 0x38a30
cmpl $0x0, (%rax)
je 0x14ffc
movq 0x24385(%rip), %rdi     # 0x39370
leaq 0x10edd(%rip), %rsi     # 0x25ecf
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41d0
movq 0x2436d(%rip), %rcx     # 0x39370
leaq 0x10ed4(%rip), %rdi     # 0x25ede
movl $0xc, %esi
movl $0x1, %edx
callq 0x42c0
movq 0x24350(%rip), %rdi     # 0x39370
leaq 0x10ec4(%rip), %rsi     # 0x25eeb
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x41d0
movq 0x24335(%rip), %rdi     # 0x39370
leaq 0x10ed4(%rip), %rsi     # 0x25f16
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41d0
movq 0x30(%r14), %rdi
movq 0x38(%r14), %rsi
callq 0x1553a
movq 0x24310(%rip), %rdi     # 0x39370
leaq 0x10ed5(%rip), %rsi     # 0x25f3c
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41d0
movq 0x242f8(%rip), %rcx     # 0x39370
leaq 0x10c1f(%rip), %rdi     # 0x25c9e
movl $0x3, %esi
movl $0x1, %edx
callq 0x42c0
movq 0x242db(%rip), %rdi     # 0x39370
leaq 0x10ec7(%rip), %rsi     # 0x25f63
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41d0
movl $0x3a41, %eax           # imm = 0x3A41
xorl 0x31d3f(%rip), %eax     # 0x46df0
movzbl 0x31d3a(%rip), %ecx     # 0x46df2
xorl $0x20, %ecx
orw %ax, %cx
je 0x15108
movl $0x3a43, %eax           # imm = 0x3A43
xorl 0x31d25(%rip), %eax     # 0x46df0
movzbl 0x31d20(%rip), %ecx     # 0x46df2
xorl $0x20, %ecx
orw %ax, %cx
je 0x15184
movl $0x3a44, %eax           # imm = 0x3A44
xorl 0x31d07(%rip), %eax     # 0x46df0
movzbl 0x31d02(%rip), %ecx     # 0x46df2
xorl $0x20, %ecx
orw %ax, %cx
jne 0x1513e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4fff
jmp 0x15221
leaq 0x31ce1(%rip), %r15     # 0x46df0
movq %r15, %rdi
movl $0x5b, %esi
callq 0x4150
movq %rax, %r12
movq %r15, %rdi
movl $0x5d, %esi
callq 0x4150
testq %r12, %r12
je 0x151f7
cmpq %rax, %r12
jbe 0x151f7
leaq 0x31cab(%rip), %r12     # 0x46df0
movq %r12, %rdi
movl $0x5b, %esi
callq 0x4150
movq %rax, %r15
movq %r12, %rdi
movl $0x5d, %esi
callq 0x4150
testq %r15, %r15
je 0x15221
cmpq %rax, %r15
jbe 0x15221
movq %r14, %rdi
movq %rbx, %rsi
callq 0x50cd
jmp 0x15274
leaq 0x31c65(%rip), %r15     # 0x46df0
movq %r15, %rdi
callq 0x4110
movabsq $0x7365722e776f6e20, %rcx # imm = 0x7365722E776F6E20
movq %rcx, (%rax,%r15)
movl $0x5f705f, 0x8(%rax,%r15) # imm = 0x5F705F
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4290
movq 0x241b4(%rip), %rdi     # 0x39370
leaq 0x10b83(%rip), %rsi     # 0x25d46
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41d0
leaq 0x238a8(%rip), %rax     # 0x38a7c
testb $0x2, (%rax)
je 0x15274
testb $0x1, 0x32c18(%rip)     # 0x47dfc
je 0x15274
movq %r14, %rdi
movq %rbx, %rsi
callq 0x507e
jmp 0x15274
movq %r15, %rdi
callq 0x4110
movabsq $0x7365722e776f6e20, %rcx # imm = 0x7365722E776F6E20
movq %rcx, (%rax,%r15)
movl $0x5f705f, 0x8(%rax,%r15) # imm = 0x5F705F
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4290
leaq 0x31bc8(%rip), %r14     # 0x46df0
movq %r14, %rdi
callq 0x4110
movabsq $0x636c2e776f6e203b, %rcx # imm = 0x636C2E776F6E203B
movq %rcx, (%rax,%r14)
movabsq $0x5f705f6b636c2e, %rcx # imm = 0x5F705F6B636C2E
movq %rcx, 0x5(%rax,%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4290
movq %r14, %rdi
callq 0x4110
movabsq $0x30203d207465725f, %rcx # imm = 0x30203D207465725F
movq %rcx, (%rax,%r14)
movb $0x0, 0x8(%rax,%r14)
leaq 0x24105(%rip), %rdi     # 0x39380
leaq 0x31b6e(%rip), %rsi     # 0x46df0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x40b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f99
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq