// File: /workspace/github_c_makefile_star2_O1/alexgirao[P]aimant/subprocess.c
// Function: subprocess_fork0
int subprocess_fork0(struct subprocess *sp)
{
	int child_stdin[2] = {0, 0};
	int child_stdout[2] = {0, 0};
	int child_stderr[2] = {0, 0};

	assert(sp);

	assert(selfpipe_setup() == 0);

	/* cleanup for next execution
	 */

	sp->exit_status = 0;
	sp->pid = 0;
	sp->waitpid_pid = 0;
	sp->is_gone = 0;

	/* pipe: read from [0], write to [1]
	 */

	assert(xpipe(child_stdin) == 0);
	assert(xpipe(child_stdout) == 0);
	assert(xpipe(child_stderr) == 0);

	DEBUG_INFO("child_stdin, child_stdout and child_stderr pipes created");

	/* flush prior to fork, so child does not inherit pending data
	 */

	fflush(stdout);
	fflush(stderr);

	/* fork
	 */

	if ((sp->pid = fork()) == 0) {
		/* prepare standard file descriptors
		 */
		assert(dup2(child_stdin[0], STDIN_FILENO) == STDIN_FILENO);
		assert(dup2(child_stdout[1], STDOUT_FILENO) == STDOUT_FILENO);
		assert(dup2(child_stderr[1], STDERR_FILENO) == STDERR_FILENO);

		/* close parent fds
		 */
		assert(close(child_stdin[1]) == 0);
		assert(close(child_stdout[0]) == 0);
		assert(close(child_stderr[0]) == 0);

		/* close old and already duplicated child fds
		 */
		assert(close(child_stdin[0]) == 0);
		assert(close(child_stdout[1]) == 0);
		assert(close(child_stderr[1]) == 0);

		return 0;
	} else if (sp->pid == -1) {
		perror("fork()");
		return -1;
	}

	DEBUG_INFO("parent pid: %i", (int) getpid());
	DEBUG_INFO("child pid:  %i", (int) sp->pid);

	/* close fds that doesn't concern to us
	 */
	assert(xclose(child_stdin[0]) == 0);
	assert(xclose(child_stdout[1]) == 0);
	assert(xclose(child_stderr[1]) == 0);

	/* set reading ends to non-blocking, i don't want
	 * surprises caused by race-conditions, there maybe
	 * little problem since we test readiness based on
	 * select
	 */

	sp->child_fdin = child_stdin[1];
	sp->child_fdout = child_stdout[0];
	sp->child_fderr = child_stderr[0];

	assert(make_fd_non_blocking(sp->child_fdin) == 0);
	assert(make_fd_non_blocking(sp->child_fdout) == 0);
	assert(make_fd_non_blocking(sp->child_fderr) == 0);

	DEBUG_INFO("sp->child_fdin=%i", sp->child_fdin);
	DEBUG_INFO("sp->child_fdout=%i", sp->child_fdout);
	DEBUG_INFO("sp->child_fderr=%i", sp->child_fderr);

	children_insert(subprocesses, child_new(sp));

	return sp->pid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xb0, %rsp
xorl %eax, %eax
movq %rax, -0x28(%rbp)
movq %rax, -0x20(%rbp)
movq %rax, -0x18(%rbp)
testq %rdi, %rdi
je 0x71db
movq %rdi, %rbx
cmpl $-0x1, 0xa85b(%rip)     # 0x11710
jne 0x700f
leaq -0xc0(%rbp), %r14
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
movl $0x11, %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x20d0
cmpq $0x0, (%r14)
jne 0x7436
leaq 0xa81f(%rip), %rdi      # 0x11710
callq 0x21f0
testl %eax, %eax
jne 0x7257
movl 0xa80c(%rip), %edi      # 0x11710
callq 0x5944
testl %eax, %eax
jne 0x7474
movl 0xa7fd(%rip), %edi      # 0x11714
callq 0x5944
testl %eax, %eax
jne 0x7493
leaq 0xa8bd(%rip), %r14      # 0x117e8
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0xa8af(%rip), %rdi      # 0x117f0
callq 0x2250
leaq 0x1127(%rip), %rax      # 0x8074
movq %rax, 0xa894(%rip)      # 0x117e8
movl $0x4, 0xa912(%rip)      # 0x11870
movl $0x11, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20d0
testl %eax, %eax
jne 0x74b2
leaq 0xa904(%rip), %r14      # 0x11880
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0xa8f6(%rip), %rdi      # 0x11888
callq 0x2250
movq $0x1, 0xa8de(%rip) # 0x11880
movl $0xd, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20d0
testl %eax, %eax
jne 0x74d1
leaq 0xa7a0(%rip), %rdi      # 0x11760
callq 0x2250
testl %eax, %eax
jne 0x74f0
leaq 0xa78c(%rip), %rdi      # 0x11760
movl $0x11, %esi
callq 0x2370
testl %eax, %eax
jne 0x750f
movl $0x1, %edi
movl $0x20, %esi
callq 0x2220
leaq 0x8(%rax), %rcx
movq %rcx, (%rax)
movq %rcx, 0x8(%rax)
andq $-0x2, %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0xa7d1(%rip)      # 0x117e0
movq $0x0, 0x14(%rbx)
xorl %eax, %eax
movl %eax, 0x1c(%rbx)
movl %eax, 0x34(%rbx)
leaq -0x28(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x71fa
leaq -0x20(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x7219
leaq -0x18(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x7238
movq 0x9f7f(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x22b0
movq 0x9f90(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
callq 0x22b0
callq 0x2390
movl %eax, 0x18(%rbx)
testl %eax, %eax
je 0x711a
cmpl $-0x1, %eax
je 0x71c8
movl -0x28(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x7265
movl -0x1c(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x72a3
movl -0x14(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x72e1
movl -0x24(%rbp), %edi
movl %edi, 0x28(%rbx)
movl -0x20(%rbp), %eax
movl %eax, 0x2c(%rbx)
movl -0x18(%rbp), %eax
movl %eax, 0x30(%rbx)
callq 0x5944
testl %eax, %eax
jne 0x731f
movl 0x2c(%rbx), %edi
callq 0x5944
testl %eax, %eax
jne 0x735d
movl 0x30(%rbx), %edi
callq 0x5944
testl %eax, %eax
jne 0x739b
movq 0xa6e1(%rip), %r14      # 0x117e0
movq %rbx, %rdi
callq 0x6685
movq %r14, %rdi
movq %rax, %rsi
callq 0x5c3e
movl 0x18(%rbx), %eax
jmp 0x71bc
movl -0x28(%rbp), %edi
xorl %esi, %esi
callq 0x2150
testl %eax, %eax
jne 0x7284
movl -0x1c(%rbp), %edi
movl $0x1, %esi
callq 0x2150
cmpl $0x1, %eax
jne 0x72c2
movl -0x14(%rbp), %edi
movl $0x2, %esi
callq 0x2150
cmpl $0x2, %eax
jne 0x7300
movl -0x24(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x733e
movl -0x20(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x737c
movl -0x18(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x73ba
movl -0x28(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x73d9
movl -0x1c(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x73f8
movl -0x14(%rbp), %edi
callq 0x21e0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x7417
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x52fe(%rip), %rdi      # 0xc4cd
callq 0x2310
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x71bc
leaq 0x5182(%rip), %rdi      # 0xc364
leaq 0x4d3d(%rip), %rsi      # 0xbf26
leaq 0x5177(%rip), %rcx      # 0xc367
movl $0x356, %edx            # imm = 0x356
callq 0x21b0
leaq 0x5190(%rip), %rdi      # 0xc391
leaq 0x4d1e(%rip), %rsi      # 0xbf26
leaq 0x5158(%rip), %rcx      # 0xc367
movl $0x365, %edx            # imm = 0x365
callq 0x21b0
leaq 0x5189(%rip), %rdi      # 0xc3a9
leaq 0x4cff(%rip), %rsi      # 0xbf26
leaq 0x5139(%rip), %rcx      # 0xc367
movl $0x366, %edx            # imm = 0x366
callq 0x21b0
leaq 0x5183(%rip), %rdi      # 0xc3c2
leaq 0x4ce0(%rip), %rsi      # 0xbf26
leaq 0x511a(%rip), %rcx      # 0xc367
movl $0x367, %edx            # imm = 0x367
callq 0x21b0
cmpl $-0x1, %eax
jne 0x7455
callq 0x2b85
leaq 0x5268(%rip), %rdi      # 0xc4d4
leaq 0x4cb3(%rip), %rsi      # 0xbf26
leaq 0x50ed(%rip), %rcx      # 0xc367
movl $0x392, %edx            # imm = 0x392
callq 0x21b0
leaq 0x5150(%rip), %rdi      # 0xc3db
leaq 0x4c94(%rip), %rsi      # 0xbf26
leaq 0x50ce(%rip), %rcx      # 0xc367
movl $0x377, %edx            # imm = 0x377
callq 0x21b0
leaq 0x5246(%rip), %rdi      # 0xc4f0
leaq 0x4c75(%rip), %rsi      # 0xbf26
leaq 0x50af(%rip), %rcx      # 0xc367
movl $0x393, %edx            # imm = 0x393
callq 0x21b0
leaq 0x5145(%rip), %rdi      # 0xc40e
leaq 0x4c56(%rip), %rsi      # 0xbf26
leaq 0x5090(%rip), %rcx      # 0xc367
movl $0x378, %edx            # imm = 0x378
callq 0x21b0
leaq 0x5225(%rip), %rdi      # 0xc50d
leaq 0x4c37(%rip), %rsi      # 0xbf26
leaq 0x5071(%rip), %rcx      # 0xc367
movl $0x394, %edx            # imm = 0x394
callq 0x21b0
leaq 0x513d(%rip), %rdi      # 0xc444
leaq 0x4c18(%rip), %rsi      # 0xbf26
leaq 0x5052(%rip), %rcx      # 0xc367
movl $0x379, %edx            # imm = 0x379
callq 0x21b0
leaq 0x5204(%rip), %rdi      # 0xc52a
leaq 0x4bf9(%rip), %rsi      # 0xbf26
leaq 0x5033(%rip), %rcx      # 0xc367
movl $0x3a0, %edx            # imm = 0x3A0
callq 0x21b0
leaq 0x5135(%rip), %rdi      # 0xc47a
leaq 0x4bda(%rip), %rsi      # 0xbf26
leaq 0x5014(%rip), %rcx      # 0xc367
movl $0x37d, %edx            # imm = 0x37D
callq 0x21b0
leaq 0x51f0(%rip), %rdi      # 0xc554
leaq 0x4bbb(%rip), %rsi      # 0xbf26
leaq 0x4ff5(%rip), %rcx      # 0xc367
movl $0x3a1, %edx            # imm = 0x3A1
callq 0x21b0
leaq 0x5112(%rip), %rdi      # 0xc495
leaq 0x4b9c(%rip), %rsi      # 0xbf26
leaq 0x4fd6(%rip), %rcx      # 0xc367
movl $0x37e, %edx            # imm = 0x37E
callq 0x21b0
leaq 0x51dd(%rip), %rdi      # 0xc57f
leaq 0x4b7d(%rip), %rsi      # 0xbf26
leaq 0x4fb7(%rip), %rcx      # 0xc367
movl $0x3a2, %edx            # imm = 0x3A2
callq 0x21b0
leaq 0x50f0(%rip), %rdi      # 0xc4b1
leaq 0x4b5e(%rip), %rsi      # 0xbf26
leaq 0x4f98(%rip), %rcx      # 0xc367
movl $0x37f, %edx            # imm = 0x37F
callq 0x21b0
leaq 0x50f5(%rip), %rdi      # 0xc4d5
leaq 0x4b3f(%rip), %rsi      # 0xbf26
leaq 0x4f79(%rip), %rcx      # 0xc367
movl $0x383, %edx            # imm = 0x383
callq 0x21b0
leaq 0x50f2(%rip), %rdi      # 0xc4f1
leaq 0x4b20(%rip), %rsi      # 0xbf26
leaq 0x4f5a(%rip), %rcx      # 0xc367
movl $0x384, %edx            # imm = 0x384
callq 0x21b0
leaq 0x50f0(%rip), %rdi      # 0xc50e
leaq 0x4b01(%rip), %rsi      # 0xbf26
leaq 0x4f3b(%rip), %rcx      # 0xc367
movl $0x385, %edx            # imm = 0x385
callq 0x21b0
leaq 0x5401(%rip), %rdi      # 0xc83e
leaq 0x4ae2(%rip), %rsi      # 0xbf26
leaq 0x540c(%rip), %rcx      # 0xc857
movl $0x13b, %edx            # imm = 0x13B
callq 0x21b0
leaq 0x565b(%rip), %rdi      # 0xcab7
leaq 0x4ac3(%rip), %rsi      # 0xbf26
leaq 0x53ed(%rip), %rcx      # 0xc857
movl $0x143, %edx            # imm = 0x143
callq 0x21b0
leaq 0x5419(%rip), %rdi      # 0xc894
leaq 0x4aa4(%rip), %rsi      # 0xbf26
leaq 0x53ce(%rip), %rcx      # 0xc857
movl $0x14a, %edx            # imm = 0x14A
callq 0x21b0
leaq 0x5421(%rip), %rdi      # 0xc8bb
leaq 0x4a85(%rip), %rsi      # 0xbf26
leaq 0x53af(%rip), %rcx      # 0xc857
movl $0x14b, %edx            # imm = 0x14B
callq 0x21b0
leaq 0x5429(%rip), %rdi      # 0xc8e2
leaq 0x4a66(%rip), %rsi      # 0xbf26
leaq 0x5390(%rip), %rcx      # 0xc857
movl $0x154, %edx            # imm = 0x154
callq 0x21b0
leaq 0x542e(%rip), %rdi      # 0xc906
leaq 0x4a47(%rip), %rsi      # 0xbf26
leaq 0x5371(%rip), %rcx      # 0xc857
movl $0x15c, %edx            # imm = 0x15C
callq 0x21b0
leaq 0x5433(%rip), %rdi      # 0xc92a
leaq 0x4a28(%rip), %rsi      # 0xbf26
leaq 0x5352(%rip), %rcx      # 0xc857
movl $0x161, %edx            # imm = 0x161
callq 0x21b0
leaq 0x5435(%rip), %rdi      # 0xc94b
leaq 0x4a09(%rip), %rsi      # 0xbf26
leaq 0x5333(%rip), %rcx      # 0xc857
movl $0x162, %edx            # imm = 0x162
callq 0x21b0