// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, -0x28(%rbp)
andq $0x0, -0x20(%rbp)
andq $0x0, -0x18(%rbp)
testq %rdi, %rdi
je 0x65de
movq %rdi, %rbx
cmpl $-0x1, 0xa433(%rip)     # 0x10710
jne 0x641b
leaq -0xc0(%rbp), %r14
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
pushq $0x11
popq %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x20d0
cmpq $0x0, (%r14)
jne 0x6870
leaq 0xa3f9(%rip), %rdi      # 0x10710
callq 0x21f0
testl %eax, %eax
jne 0x665a
movl 0xa3e6(%rip), %edi      # 0x10710
callq 0x4ee8
testl %eax, %eax
jne 0x68ae
movl 0xa3d7(%rip), %edi      # 0x10714
callq 0x4ee8
testl %eax, %eax
jne 0x68cd
leaq 0xa497(%rip), %r14      # 0x107e8
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0xa489(%rip), %rdi      # 0x107f0
callq 0x2240
leaq 0x1199(%rip), %rax      # 0x750c
movq %rax, 0xa46e(%rip)      # 0x107e8
movl $0x4, 0xa4ec(%rip)      # 0x10870
pushq $0x11
popq %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20d0
testl %eax, %eax
jne 0x68ec
leaq 0xa4e0(%rip), %r14      # 0x10880
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0xa4d2(%rip), %rdi      # 0x10888
callq 0x2240
movq $0x1, 0xa4ba(%rip) # 0x10880
pushq $0xd
popq %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20d0
testl %eax, %eax
jne 0x690b
leaq 0xa37e(%rip), %rdi      # 0x10760
callq 0x2240
testl %eax, %eax
jne 0x692a
leaq 0xa36a(%rip), %rdi      # 0x10760
pushq $0x11
popq %rsi
callq 0x2360
testl %eax, %eax
jne 0x6949
callq 0x5aa0
movq %rax, 0xa3ce(%rip)      # 0x107e0
testq %rax, %rax
je 0x6968
andq $0x0, 0x14(%rbx)
andl $0x0, 0x1c(%rbx)
andl $0x0, 0x34(%rbx)
leaq -0x28(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x65fd
leaq -0x20(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x661c
leaq -0x18(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
jne 0x663b
movq 0x9b76(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x22a0
movq 0x9b87(%rip), %rax      # 0xfff8
movq (%rax), %rdi
callq 0x22a0
callq 0x2380
movl %eax, 0x18(%rbx)
testl %eax, %eax
je 0x6523
cmpl $-0x1, %eax
je 0x65cd
movl -0x28(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x669f
movl -0x1c(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x66dd
movl -0x14(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x671b
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 0x4ee8
testl %eax, %eax
jne 0x6759
movl 0x2c(%rbx), %edi
callq 0x4ee8
testl %eax, %eax
jne 0x6797
movl 0x30(%rbx), %edi
callq 0x4ee8
testl %eax, %eax
jne 0x67d5
movq 0xa2d8(%rip), %r14      # 0x107e0
movq %rbx, %rdi
callq 0x5b1c
movq %r14, %rdi
movq %rax, %rsi
callq 0x5189
movl 0x18(%rbx), %eax
jmp 0x65c1
movl -0x28(%rbp), %edi
xorl %esi, %esi
callq 0x2150
testl %eax, %eax
jne 0x66be
movl -0x1c(%rbp), %edi
pushq $0x1
popq %rsi
callq 0x2150
cmpl $0x1, %eax
jne 0x66fc
movl -0x14(%rbp), %edi
pushq $0x2
popq %rsi
callq 0x2150
cmpl $0x2, %eax
jne 0x673a
movl -0x24(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x6778
movl -0x20(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x67b6
movl -0x18(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x67f4
movl -0x28(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x6813
movl -0x1c(%rbp), %edi
callq 0x21e0
testl %eax, %eax
jne 0x6832
movl -0x14(%rbp), %edi
callq 0x21e0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x6851
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x4eec(%rip), %rdi      # 0xb4c0
callq 0x2300
pushq $-0x1
popq %rax
jmp 0x65c1
leaq 0x4d72(%rip), %rdi      # 0xb357
leaq 0x492d(%rip), %rsi      # 0xaf19
leaq 0x4d67(%rip), %rcx      # 0xb35a
movl $0x356, %edx            # imm = 0x356
callq 0x21b0
leaq 0x4d80(%rip), %rdi      # 0xb384
leaq 0x490e(%rip), %rsi      # 0xaf19
leaq 0x4d48(%rip), %rcx      # 0xb35a
movl $0x365, %edx            # imm = 0x365
callq 0x21b0
leaq 0x4d79(%rip), %rdi      # 0xb39c
leaq 0x48ef(%rip), %rsi      # 0xaf19
leaq 0x4d29(%rip), %rcx      # 0xb35a
movl $0x366, %edx            # imm = 0x366
callq 0x21b0
leaq 0x4d73(%rip), %rdi      # 0xb3b5
leaq 0x48d0(%rip), %rsi      # 0xaf19
leaq 0x4d0a(%rip), %rcx      # 0xb35a
movl $0x367, %edx            # imm = 0x367
callq 0x21b0
cmpl $-0x1, %eax
jne 0x688f
callq 0x2080
movq %rax, %rbx
movl (%rax), %r14d
leaq 0x48a4(%rip), %rdi      # 0xaf19
leaq 0x51e3(%rip), %rdx      # 0xb85f
movl $0x144, %esi            # imm = 0x144
movl %r14d, %ecx
xorl %eax, %eax
callq 0x8e04
movl %r14d, (%rbx)
leaq 0x51e3(%rip), %rdi      # 0xb878
callq 0x2300
callq 0x2070
leaq 0x4e21(%rip), %rdi      # 0xb4c7
leaq 0x486c(%rip), %rsi      # 0xaf19
leaq 0x4ca6(%rip), %rcx      # 0xb35a
movl $0x392, %edx            # imm = 0x392
callq 0x21b0
leaq 0x4d09(%rip), %rdi      # 0xb3ce
leaq 0x484d(%rip), %rsi      # 0xaf19
leaq 0x4c87(%rip), %rcx      # 0xb35a
movl $0x377, %edx            # imm = 0x377
callq 0x21b0
leaq 0x4dff(%rip), %rdi      # 0xb4e3
leaq 0x482e(%rip), %rsi      # 0xaf19
leaq 0x4c68(%rip), %rcx      # 0xb35a
movl $0x393, %edx            # imm = 0x393
callq 0x21b0
leaq 0x4cfe(%rip), %rdi      # 0xb401
leaq 0x480f(%rip), %rsi      # 0xaf19
leaq 0x4c49(%rip), %rcx      # 0xb35a
movl $0x378, %edx            # imm = 0x378
callq 0x21b0
leaq 0x4dde(%rip), %rdi      # 0xb500
leaq 0x47f0(%rip), %rsi      # 0xaf19
leaq 0x4c2a(%rip), %rcx      # 0xb35a
movl $0x394, %edx            # imm = 0x394
callq 0x21b0
leaq 0x4cf6(%rip), %rdi      # 0xb437
leaq 0x47d1(%rip), %rsi      # 0xaf19
leaq 0x4c0b(%rip), %rcx      # 0xb35a
movl $0x379, %edx            # imm = 0x379
callq 0x21b0
leaq 0x4dbd(%rip), %rdi      # 0xb51d
leaq 0x47b2(%rip), %rsi      # 0xaf19
leaq 0x4bec(%rip), %rcx      # 0xb35a
movl $0x3a0, %edx            # imm = 0x3A0
callq 0x21b0
leaq 0x4cee(%rip), %rdi      # 0xb46d
leaq 0x4793(%rip), %rsi      # 0xaf19
leaq 0x4bcd(%rip), %rcx      # 0xb35a
movl $0x37d, %edx            # imm = 0x37D
callq 0x21b0
leaq 0x4da9(%rip), %rdi      # 0xb547
leaq 0x4774(%rip), %rsi      # 0xaf19
leaq 0x4bae(%rip), %rcx      # 0xb35a
movl $0x3a1, %edx            # imm = 0x3A1
callq 0x21b0
leaq 0x4ccb(%rip), %rdi      # 0xb488
leaq 0x4755(%rip), %rsi      # 0xaf19
leaq 0x4b8f(%rip), %rcx      # 0xb35a
movl $0x37e, %edx            # imm = 0x37E
callq 0x21b0
leaq 0x4d96(%rip), %rdi      # 0xb572
leaq 0x4736(%rip), %rsi      # 0xaf19
leaq 0x4b70(%rip), %rcx      # 0xb35a
movl $0x3a2, %edx            # imm = 0x3A2
callq 0x21b0
leaq 0x4ca9(%rip), %rdi      # 0xb4a4
leaq 0x4717(%rip), %rsi      # 0xaf19
leaq 0x4b51(%rip), %rcx      # 0xb35a
movl $0x37f, %edx            # imm = 0x37F
callq 0x21b0
leaq 0x4cae(%rip), %rdi      # 0xb4c8
leaq 0x46f8(%rip), %rsi      # 0xaf19
leaq 0x4b32(%rip), %rcx      # 0xb35a
movl $0x383, %edx            # imm = 0x383
callq 0x21b0
leaq 0x4cab(%rip), %rdi      # 0xb4e4
leaq 0x46d9(%rip), %rsi      # 0xaf19
leaq 0x4b13(%rip), %rcx      # 0xb35a
movl $0x384, %edx            # imm = 0x384
callq 0x21b0
leaq 0x4ca9(%rip), %rdi      # 0xb501
leaq 0x46ba(%rip), %rsi      # 0xaf19
leaq 0x4af4(%rip), %rcx      # 0xb35a
movl $0x385, %edx            # imm = 0x385
callq 0x21b0
leaq 0x4fba(%rip), %rdi      # 0xb831
leaq 0x469b(%rip), %rsi      # 0xaf19
leaq 0x4fc5(%rip), %rcx      # 0xb84a
movl $0x13b, %edx            # imm = 0x13B
callq 0x21b0
leaq 0x522e(%rip), %rdi      # 0xbac4
leaq 0x467c(%rip), %rsi      # 0xaf19
leaq 0x4fa6(%rip), %rcx      # 0xb84a
movl $0x143, %edx            # imm = 0x143
callq 0x21b0
leaq 0x4fd2(%rip), %rdi      # 0xb887
leaq 0x465d(%rip), %rsi      # 0xaf19
leaq 0x4f87(%rip), %rcx      # 0xb84a
movl $0x14a, %edx            # imm = 0x14A
callq 0x21b0
leaq 0x4fda(%rip), %rdi      # 0xb8ae
leaq 0x463e(%rip), %rsi      # 0xaf19
leaq 0x4f68(%rip), %rcx      # 0xb84a
movl $0x14b, %edx            # imm = 0x14B
callq 0x21b0
leaq 0x4fe2(%rip), %rdi      # 0xb8d5
leaq 0x461f(%rip), %rsi      # 0xaf19
leaq 0x4f49(%rip), %rcx      # 0xb84a
movl $0x154, %edx            # imm = 0x154
callq 0x21b0
leaq 0x4fe7(%rip), %rdi      # 0xb8f9
leaq 0x4600(%rip), %rsi      # 0xaf19
leaq 0x4f2a(%rip), %rcx      # 0xb84a
movl $0x15c, %edx            # imm = 0x15C
callq 0x21b0
leaq 0x4fec(%rip), %rdi      # 0xb91d
leaq 0x45e1(%rip), %rsi      # 0xaf19
leaq 0x4f0b(%rip), %rcx      # 0xb84a
movl $0x161, %edx            # imm = 0x161
callq 0x21b0
leaq 0x4fee(%rip), %rdi      # 0xb93e
leaq 0x45c2(%rip), %rsi      # 0xaf19
leaq 0x4eec(%rip), %rcx      # 0xb84a
movl $0x162, %edx            # imm = 0x162
callq 0x21b0
leaq 0x4ff7(%rip), %rdi      # 0xb966
leaq 0x45a3(%rip), %rsi      # 0xaf19
leaq 0x4ecd(%rip), %rcx      # 0xb84a
movl $0x168, %edx            # imm = 0x168
callq 0x21b0