// File: /workspace/github_c_makefile_star2_O2/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 0x12002
callq 0x12076
callq 0x1212d
movq 0x2ff1b(%rip), %rdi     # 0x43180
movq 0x2ff1c(%rip), %rsi     # 0x43188
callq 0x121bd
movq 0x240f8(%rip), %rbx     # 0x37370
testq %rbx, %rbx
je 0x1349e
movq 0x2ff00(%rip), %rcx     # 0x43188
testq %rcx, %rcx
je 0x13336
cmpq $0x0, 0x2fef7(%rip)     # 0x43190
je 0x13336
leaq 0x2378a(%rip), %rax     # 0x36a30
movl (%rax), %edx
testl %edx, %edx
je 0x132c4
leaq 0x1084e(%rip), %rsi     # 0x23b01
movq %rbx, %rdi
xorl %eax, %eax
callq 0x41c0
movq 0x240ac(%rip), %rbx     # 0x37370
leaq 0x10b15(%rip), %rdi     # 0x23de0
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x42c0
movq 0x24090(%rip), %rdi     # 0x37370
movq 0x2fea1(%rip), %rcx     # 0x43188
leaq 0x1083b(%rip), %rsi     # 0x23b29
movq %rcx, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x41c0
leaq 0x260ce(%rip), %r14     # 0x393d0
movq 0x2fe7f(%rip), %rbx     # 0x43188
movq (%r14), %r14
testq %r14, %r14
je 0x1342e
movq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x41b0
testl %eax, %eax
jne 0x13330
cmpl $0x2, 0x30(%r14)
je 0x13408
addq $0x38, %r14
jmp 0x13309
leaq 0x24057(%rip), %rdi     # 0x37394
pushq $0x29
popq %rsi
callq 0x4130
testq %rax, %rax
je 0x133a6
movb $0x0, (%rax)
incq %rax
pushq $0x22
popq %rsi
movq %rax, %rdi
callq 0x4130
testq %rax, %rax
je 0x133a6
movq %rax, %r14
incq %r14
pushq $0x22
popq %rsi
movq %r14, %rdi
callq 0x4130
testq %rax, %rax
je 0x133a6
movb $0x0, (%rax)
leaq 0x24014(%rip), %rdx     # 0x37394
xorl %eax, %eax
cmpb $0x28, 0x2400b(%rip)    # 0x37394
sete %al
leal (%rax,%rax,8), %ecx
addl $0x20, %ecx
leaq 0x10848(%rip), %rsi     # 0x23be1
movq %rbx, %rdi
movq %r14, %r8
xorl %eax, %eax
callq 0x41c0
cmpb $0x0, 0x23fd3(%rip)     # 0x37380
je 0x13497
movq 0x20c3e(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movq 0x2fdc4(%rip), %rcx     # 0x43188
testq %rcx, %rcx
leaq 0xe6cc(%rip), %rax      # 0x21a9a
cmoveq %rax, %rcx
movq 0x2fdb7(%rip), %r8      # 0x43190
testq %r8, %r8
cmoveq %rax, %r8
movq 0x2fd99(%rip), %r9      # 0x43180
testq %r9, %r9
cmoveq %rax, %r9
leaq 0x10801(%rip), %rsi     # 0x23bf6
leaq 0x23f84(%rip), %rdx     # 0x37380
xorl %eax, %eax
callq 0x41c0
jmp 0x13497
movq 0x23f61(%rip), %rdi     # 0x37370
movq 0x2fd7a(%rip), %rcx     # 0x43190
leaq 0x1074a(%rip), %rsi     # 0x23b67
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41c0
movq 0x2fd5a(%rip), %rbx     # 0x43188
movq 0x23f3b(%rip), %rdi     # 0x37370
leaq 0x1074c(%rip), %rsi     # 0x23b88
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41c0
movq 0x23f23(%rip), %rcx     # 0x37370
leaq 0x1074a(%rip), %rdi     # 0x23b9e
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
callq 0x42c0
movq 0x23f0a(%rip), %rdi     # 0x37370
movq 0x2fd1b(%rip), %rdx     # 0x43188
leaq 0x1072e(%rip), %rsi     # 0x23ba2
xorl %eax, %eax
callq 0x41c0
movq 0x23eee(%rip), %rdi     # 0x37370
movq 0x2fcff(%rip), %rdx     # 0x43188
leaq 0x1072b(%rip), %rsi     # 0x23bbb
xorl %eax, %eax
callq 0x41c0
movb $0x0, 0x23ee2(%rip)     # 0x37380
addq $0x8, %rsp
popq %rbx
popq %r14
retq