// File: /workspace/github_c_makefile_star2_O3/nimble-code[P]Modex/Src/xtract.c
// Function: handle_pthread_create
static void
handle_pthread_create(int which)
{
	// F:  pthread_create(&(t2),0,"thr2",0);
	set_create_id();
	set_thread_id();
	set_thread_arg();
	remember(join_id, thread_id);

	if (!fp) return;

	// fprintf(stderr, "handle %d: %s\n", which, OutBuf);

	if (0)
	{	fprintf(stderr, "join_id '%s', thread_id '%s', thread_arg '%s'\n",
			join_id?join_id:"?",
			thread_id?thread_id:"?",
			thread_arg?thread_arg:"?");
	}

	if (thread_id && thread_arg)
	{	if (dynamic)
		{	fprintf(fp, "\tatomic { _nr_pr < %d -> run p_%s() };\n",
				dynamic, thread_id);
		}
		fprintf(fp, "\tatomic {\n");
		fprintf(fp, "\t	lck_p_%s == 0 && empty(req_cll_p_%s) -> req_cll_p_%s!_pid;\n",
			thread_id, thread_id, thread_id);

		if (thread_has_params(thread_id))
		{	fprintf(fp, "\t	c_code { now.par0_%s = %s; };\n",
				thread_id, thread_arg);
		}
		fprintf(fp, "\t	exc_cll_p_%s!_pid;\n", thread_id);
		fprintf(fp, "\t}\n");
		fprintf(fp, "//\tret_p_%s?eval(_pid);\n", thread_id);
		fprintf(fp, "//\tc_code { now.lck_p_%s_ret = 0; };\n", thread_id);
	} else
	{	char *q, *r, *s, *t;
		q = &OutBuf[strlen("F: pthread_create(&(")];
					if (!q) goto bad;
		r = strchr(q, ')');	if (!r) goto bad;
		*r = '\0';
		s = strchr((r+1), '"');	if (!s) goto bad;
		t = strchr((s+1), '"');	if (!t) goto bad;
		*t = '\0';
		fprintf(fp, "\t%s%c = run p_%s();\n",
			q,
			(*q == '(')?')':' ',
			s+1);
bad:
		if (strlen(OutBuf) > 0)
		{	fprintf(stderr, "warning: unhandled type of %s (%s/%s/%s)\n",
				OutBuf,
				thread_id?thread_id:"--",
				thread_arg?thread_arg:"--",
				join_id?join_id:"--");
		}
	}
	OutBuf[0] = '\0';
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
callq 0x139b7
callq 0x13a32
callq 0x13af6
movq 0x30560(%rip), %rbx     # 0x45180
movq 0x30561(%rip), %r14     # 0x45188
movl $0x18, %edi
callq 0x6321
movq %rbx, (%rax)
movq %r14, 0x8(%rax)
movq 0x30559(%rip), %rcx     # 0x45198
movq %rcx, 0x10(%rax)
movq %rax, 0x3054e(%rip)     # 0x45198
movq 0x2471f(%rip), %rbx     # 0x39370
testq %rbx, %rbx
je 0x14e37
movq 0x30527(%rip), %rcx     # 0x45188
testq %rcx, %rcx
je 0x14d10
cmpq $0x0, 0x3051e(%rip)     # 0x45190
je 0x14d10
leaq 0x23db1(%rip), %rax     # 0x38a30
movl (%rax), %edx
testl %edx, %edx
je 0x14c9d
leaq 0x10f75(%rip), %rsi     # 0x25c01
movq %rbx, %rdi
xorl %eax, %eax
callq 0x41d0
movq 0x246d3(%rip), %rbx     # 0x39370
leaq 0x1123c(%rip), %rdi     # 0x25ee0
movl $0xa, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x42c0
movq 0x246b3(%rip), %rdi     # 0x39370
movq 0x304c4(%rip), %rcx     # 0x45188
leaq 0x10f5e(%rip), %rsi     # 0x25c29
movq %rcx, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x41d0
movq 0x304a9(%rip), %rbx     # 0x45188
movq 0x266ea(%rip), %r14     # 0x3b3d0
testq %r14, %r14
je 0x14dc3
movq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x41c0
testl %eax, %eax
jne 0x14d0a
cmpl $0x2, 0x30(%r14)
je 0x14d9d
movq 0x38(%r14), %r14
jmp 0x14ce6
leaq 0x2467d(%rip), %rdi     # 0x39394
movl $0x29, %esi
callq 0x4130
testq %rax, %rax
je 0x14d86
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
movl $0x22, %esi
callq 0x4130
testq %rax, %rax
je 0x14d86
movq %rax, %r14
incq %r14
movq %r14, %rdi
movl $0x22, %esi
callq 0x4130
testq %rax, %rax
je 0x14d86
movb $0x0, (%rax)
leaq 0x24634(%rip), %rdx     # 0x39394
xorl %eax, %eax
cmpb $0x28, 0x2462b(%rip)    # 0x39394
sete %al
leal (%rax,%rax,8), %ecx
addl $0x20, %ecx
leaq 0x10f68(%rip), %rsi     # 0x25ce1
movq %rbx, %rdi
movq %r14, %r8
xorl %eax, %eax
callq 0x41d0
cmpb $0x0, 0x245f3(%rip)     # 0x39380
je 0x14e30
callq 0x4f49
jmp 0x14e30
movq 0x245cc(%rip), %rdi     # 0x39370
movq 0x303e5(%rip), %rcx     # 0x45190
leaq 0x10eb5(%rip), %rsi     # 0x25c67
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41d0
movq 0x303c5(%rip), %rbx     # 0x45188
movq 0x245a6(%rip), %rdi     # 0x39370
leaq 0x10eb7(%rip), %rsi     # 0x25c88
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41d0
movq 0x2458e(%rip), %rcx     # 0x39370
leaq 0x10eb5(%rip), %rdi     # 0x25c9e
movl $0x3, %esi
movl $0x1, %edx
callq 0x42c0
movq 0x24571(%rip), %rdi     # 0x39370
movq 0x30382(%rip), %rdx     # 0x45188
leaq 0x10e95(%rip), %rsi     # 0x25ca2
xorl %eax, %eax
callq 0x41d0
movq 0x24555(%rip), %rdi     # 0x39370
movq 0x30366(%rip), %rdx     # 0x45188
leaq 0x10e92(%rip), %rsi     # 0x25cbb
xorl %eax, %eax
callq 0x41d0
movb $0x0, 0x24549(%rip)     # 0x39380
addq $0x8, %rsp
popq %rbx
popq %r14
retq