// File: /workspace/github_c_makefile_star2_O1/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, 0x2ac64(%rip)     # 0x3fabc
jne 0x15122
movl $0x0, 0x33f80(%rip)     # 0x48de8
leaq 0x24bb1(%rip), %rax     # 0x39a20
cmpl $0x0, (%rax)
je 0x14e8c
movq 0x254e5(%rip), %rdi     # 0x3a360
leaq 0x1204d(%rip), %rsi     # 0x26ecf
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41c0
movq 0x254cd(%rip), %rcx     # 0x3a360
leaq 0x12044(%rip), %rdi     # 0x26ede
movl $0xc, %esi
movl $0x1, %edx
callq 0x42b0
movq 0x254b0(%rip), %rdi     # 0x3a360
leaq 0x12034(%rip), %rsi     # 0x26eeb
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x41c0
movq 0x25495(%rip), %rdi     # 0x3a360
leaq 0x12044(%rip), %rsi     # 0x26f16
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41c0
movq 0x30(%r14), %rdi
movq 0x38(%r14), %rsi
callq 0x153ca
movq 0x25470(%rip), %rdi     # 0x3a360
leaq 0x12045(%rip), %rsi     # 0x26f3c
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41c0
movq 0x25458(%rip), %rcx     # 0x3a360
leaq 0x11d8f(%rip), %rdi     # 0x26c9e
movl $0x3, %esi
movl $0x1, %edx
callq 0x42b0
movq 0x2543b(%rip), %rdi     # 0x3a360
leaq 0x12037(%rip), %rsi     # 0x26f63
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41c0
movl $0x3a41, %eax           # imm = 0x3A41
xorl 0x32e9f(%rip), %eax     # 0x47de0
movzbl 0x32e9a(%rip), %ecx     # 0x47de2
xorl $0x20, %ecx
orw %ax, %cx
je 0x14f98
movl $0x3a43, %eax           # imm = 0x3A43
xorl 0x32e85(%rip), %eax     # 0x47de0
movzbl 0x32e80(%rip), %ecx     # 0x47de2
xorl $0x20, %ecx
orw %ax, %cx
je 0x15014
movl $0x3a44, %eax           # imm = 0x3A44
xorl 0x32e67(%rip), %eax     # 0x47de0
movzbl 0x32e62(%rip), %ecx     # 0x47de2
xorl $0x20, %ecx
orw %ax, %cx
jne 0x14fce
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5064
jmp 0x150b1
leaq 0x32e41(%rip), %r15     # 0x47de0
movq %r15, %rdi
movl $0x5b, %esi
callq 0x4150
movq %rax, %r12
movq %r15, %rdi
movl $0x5d, %esi
callq 0x4150
testq %r12, %r12
je 0x15087
cmpq %rax, %r12
jbe 0x15087
leaq 0x32e0b(%rip), %r12     # 0x47de0
movq %r12, %rdi
movl $0x5b, %esi
callq 0x4150
movq %rax, %r15
movq %r12, %rdi
movl $0x5d, %esi
callq 0x4150
testq %r15, %r15
je 0x150b1
cmpq %rax, %r15
jbe 0x150b1
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5132
jmp 0x15104
leaq 0x32dc5(%rip), %r15     # 0x47de0
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 0x4280
movq 0x25314(%rip), %rdi     # 0x3a360
leaq 0x11cf3(%rip), %rsi     # 0x26d46
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41c0
leaq 0x24a08(%rip), %rax     # 0x39a6c
testb $0x2, (%rax)
je 0x15104
testb $0x1, 0x33d78(%rip)     # 0x48dec
je 0x15104
movq %r14, %rdi
movq %rbx, %rsi
callq 0x50e3
jmp 0x15104
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 0x4280
leaq 0x32d28(%rip), %r14     # 0x47de0
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 0x4280
movq %r14, %rdi
callq 0x4110
movabsq $0x30203d207465725f, %rcx # imm = 0x30203D207465725F
movq %rcx, (%rax,%r14)
movb $0x0, 0x8(%rax,%r14)
leaq 0x25265(%rip), %rdi     # 0x3a370
leaq 0x32cce(%rip), %rsi     # 0x47de0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x40b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ffe
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq