// File: /workspace/github_c_makefile_star2_O3/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 0x6f9e
movq %rdi, %rbx
cmpl $-0x1, 0xaa98(%rip)     # 0x11710
jne 0x6dd2
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 0x71f9
leaq 0xaa5c(%rip), %rdi      # 0x11710
callq 0x21f0
testl %eax, %eax
jne 0x701a
movl 0xaa49(%rip), %edi      # 0x11710
callq 0x5784
testl %eax, %eax
jne 0x7237
movl 0xaa3a(%rip), %edi      # 0x11714
callq 0x5784
testl %eax, %eax
jne 0x7256
leaq 0xaafa(%rip), %r14      # 0x117e8
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0xaaec(%rip), %rdi      # 0x117f0
callq 0x2240
leaq 0x110b(%rip), %rax      # 0x7e1b
movq %rax, 0xaad1(%rip)      # 0x117e8
movl $0x4, 0xab4f(%rip)      # 0x11870
movl $0x11, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20d0
testl %eax, %eax
jne 0x7275
leaq 0xab41(%rip), %r14      # 0x11880
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0xab33(%rip), %rdi      # 0x11888
callq 0x2240
movq $0x1, 0xab1b(%rip) # 0x11880
movl $0xd, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20d0
testl %eax, %eax
jne 0x7294
leaq 0xa9dd(%rip), %rdi      # 0x11760
callq 0x2240
testl %eax, %eax
jne 0x72b3
leaq 0xa9c9(%rip), %rdi      # 0x11760
movl $0x11, %esi
callq 0x2360
testl %eax, %eax
jne 0x72d2
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, 0xaa0e(%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 0x6fbd
leaq -0x20(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x6fdc
leaq -0x18(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x6ffb
movq 0xa1bc(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x22a0
movq 0xa1cd(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
callq 0x22a0
callq 0x2380
movl %eax, 0x18(%rbx)
testl %eax, %eax
je 0x6edd
cmpl $-0x1, %eax
je 0x6f8b
movl -0x28(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x7028
movl -0x1c(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x7066
movl -0x14(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x70a4
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 0x5784
testl %eax, %eax
jne 0x70e2
movl 0x2c(%rbx), %edi
callq 0x5784
testl %eax, %eax
jne 0x7120
movl 0x30(%rbx), %edi
callq 0x5784
testl %eax, %eax
jne 0x715e
movq 0xa91e(%rip), %r14      # 0x117e0
movq %rbx, %rdi
callq 0x646a
movq %r14, %rdi
movq %rax, %rsi
callq 0x5a49
movl 0x18(%rbx), %eax
jmp 0x6f7f
movl -0x28(%rbp), %edi
xorl %esi, %esi
callq 0x2150
testl %eax, %eax
jne 0x7047
movl -0x1c(%rbp), %edi
movl $0x1, %esi
callq 0x2150
cmpl $0x1, %eax
jne 0x7085
movl -0x14(%rbp), %edi
movl $0x2, %esi
callq 0x2150
cmpl $0x2, %eax
jne 0x70c3
movl -0x24(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x7101
movl -0x20(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x713f
movl -0x18(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x717d
movl -0x28(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x719c
movl -0x1c(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x71bb
movl -0x14(%rbp), %edi
callq 0x21e0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x71da
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x552e(%rip), %rdi      # 0xc4c0
callq 0x2300
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x6f7f
leaq 0x53b2(%rip), %rdi      # 0xc357
leaq 0x4f6d(%rip), %rsi      # 0xbf19
leaq 0x53a7(%rip), %rcx      # 0xc35a
movl $0x356, %edx            # imm = 0x356
callq 0x21b0
leaq 0x53c0(%rip), %rdi      # 0xc384
leaq 0x4f4e(%rip), %rsi      # 0xbf19
leaq 0x5388(%rip), %rcx      # 0xc35a
movl $0x365, %edx            # imm = 0x365
callq 0x21b0
leaq 0x53b9(%rip), %rdi      # 0xc39c
leaq 0x4f2f(%rip), %rsi      # 0xbf19
leaq 0x5369(%rip), %rcx      # 0xc35a
movl $0x366, %edx            # imm = 0x366
callq 0x21b0
leaq 0x53b3(%rip), %rdi      # 0xc3b5
leaq 0x4f10(%rip), %rsi      # 0xbf19
leaq 0x534a(%rip), %rcx      # 0xc35a
movl $0x367, %edx            # imm = 0x367
callq 0x21b0
cmpl $-0x1, %eax
jne 0x7218
callq 0x2b47
leaq 0x5498(%rip), %rdi      # 0xc4c7
leaq 0x4ee3(%rip), %rsi      # 0xbf19
leaq 0x531d(%rip), %rcx      # 0xc35a
movl $0x392, %edx            # imm = 0x392
callq 0x21b0
leaq 0x5380(%rip), %rdi      # 0xc3ce
leaq 0x4ec4(%rip), %rsi      # 0xbf19
leaq 0x52fe(%rip), %rcx      # 0xc35a
movl $0x377, %edx            # imm = 0x377
callq 0x21b0
leaq 0x5476(%rip), %rdi      # 0xc4e3
leaq 0x4ea5(%rip), %rsi      # 0xbf19
leaq 0x52df(%rip), %rcx      # 0xc35a
movl $0x393, %edx            # imm = 0x393
callq 0x21b0
leaq 0x5375(%rip), %rdi      # 0xc401
leaq 0x4e86(%rip), %rsi      # 0xbf19
leaq 0x52c0(%rip), %rcx      # 0xc35a
movl $0x378, %edx            # imm = 0x378
callq 0x21b0
leaq 0x5455(%rip), %rdi      # 0xc500
leaq 0x4e67(%rip), %rsi      # 0xbf19
leaq 0x52a1(%rip), %rcx      # 0xc35a
movl $0x394, %edx            # imm = 0x394
callq 0x21b0
leaq 0x536d(%rip), %rdi      # 0xc437
leaq 0x4e48(%rip), %rsi      # 0xbf19
leaq 0x5282(%rip), %rcx      # 0xc35a
movl $0x379, %edx            # imm = 0x379
callq 0x21b0
leaq 0x5434(%rip), %rdi      # 0xc51d
leaq 0x4e29(%rip), %rsi      # 0xbf19
leaq 0x5263(%rip), %rcx      # 0xc35a
movl $0x3a0, %edx            # imm = 0x3A0
callq 0x21b0
leaq 0x5365(%rip), %rdi      # 0xc46d
leaq 0x4e0a(%rip), %rsi      # 0xbf19
leaq 0x5244(%rip), %rcx      # 0xc35a
movl $0x37d, %edx            # imm = 0x37D
callq 0x21b0
leaq 0x5420(%rip), %rdi      # 0xc547
leaq 0x4deb(%rip), %rsi      # 0xbf19
leaq 0x5225(%rip), %rcx      # 0xc35a
movl $0x3a1, %edx            # imm = 0x3A1
callq 0x21b0
leaq 0x5342(%rip), %rdi      # 0xc488
leaq 0x4dcc(%rip), %rsi      # 0xbf19
leaq 0x5206(%rip), %rcx      # 0xc35a
movl $0x37e, %edx            # imm = 0x37E
callq 0x21b0
leaq 0x540d(%rip), %rdi      # 0xc572
leaq 0x4dad(%rip), %rsi      # 0xbf19
leaq 0x51e7(%rip), %rcx      # 0xc35a
movl $0x3a2, %edx            # imm = 0x3A2
callq 0x21b0
leaq 0x5320(%rip), %rdi      # 0xc4a4
leaq 0x4d8e(%rip), %rsi      # 0xbf19
leaq 0x51c8(%rip), %rcx      # 0xc35a
movl $0x37f, %edx            # imm = 0x37F
callq 0x21b0
leaq 0x5325(%rip), %rdi      # 0xc4c8
leaq 0x4d6f(%rip), %rsi      # 0xbf19
leaq 0x51a9(%rip), %rcx      # 0xc35a
movl $0x383, %edx            # imm = 0x383
callq 0x21b0
leaq 0x5322(%rip), %rdi      # 0xc4e4
leaq 0x4d50(%rip), %rsi      # 0xbf19
leaq 0x518a(%rip), %rcx      # 0xc35a
movl $0x384, %edx            # imm = 0x384
callq 0x21b0
leaq 0x5320(%rip), %rdi      # 0xc501
leaq 0x4d31(%rip), %rsi      # 0xbf19
leaq 0x516b(%rip), %rcx      # 0xc35a
movl $0x385, %edx            # imm = 0x385
callq 0x21b0
leaq 0x5619(%rip), %rdi      # 0xc819
leaq 0x4d12(%rip), %rsi      # 0xbf19
leaq 0x5624(%rip), %rcx      # 0xc832
movl $0x13b, %edx            # imm = 0x13B
callq 0x21b0
leaq 0x5880(%rip), %rdi      # 0xca9f
leaq 0x4cf3(%rip), %rsi      # 0xbf19
leaq 0x5605(%rip), %rcx      # 0xc832
movl $0x143, %edx            # imm = 0x143
callq 0x21b0
leaq 0x5631(%rip), %rdi      # 0xc86f
leaq 0x4cd4(%rip), %rsi      # 0xbf19
leaq 0x55e6(%rip), %rcx      # 0xc832
movl $0x14a, %edx            # imm = 0x14A
callq 0x21b0
leaq 0x5639(%rip), %rdi      # 0xc896
leaq 0x4cb5(%rip), %rsi      # 0xbf19
leaq 0x55c7(%rip), %rcx      # 0xc832
movl $0x14b, %edx            # imm = 0x14B
callq 0x21b0
leaq 0x5641(%rip), %rdi      # 0xc8bd
leaq 0x4c96(%rip), %rsi      # 0xbf19
leaq 0x55a8(%rip), %rcx      # 0xc832
movl $0x154, %edx            # imm = 0x154
callq 0x21b0
leaq 0x5646(%rip), %rdi      # 0xc8e1
leaq 0x4c77(%rip), %rsi      # 0xbf19
leaq 0x5589(%rip), %rcx      # 0xc832
movl $0x15c, %edx            # imm = 0x15C
callq 0x21b0
leaq 0x564b(%rip), %rdi      # 0xc905
leaq 0x4c58(%rip), %rsi      # 0xbf19
leaq 0x556a(%rip), %rcx      # 0xc832
movl $0x161, %edx            # imm = 0x161
callq 0x21b0
leaq 0x564d(%rip), %rdi      # 0xc926
leaq 0x4c39(%rip), %rsi      # 0xbf19
leaq 0x554b(%rip), %rcx      # 0xc832
movl $0x162, %edx            # imm = 0x162
callq 0x21b0