// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x21c0
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x21c0
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x21c0
cmpq $0x0, -0x10(%rbp)
je 0x9815
jmp 0x9834
leaq 0x7bba(%rip), %rdi      # 0x113d6
leaq 0x7775(%rip), %rsi      # 0x10f98
movl $0x356, %edx            # imm = 0x356
leaq 0x7baa(%rip), %rcx      # 0x113d9
callq 0x21a0
callq 0xb230
cmpl $0x0, %eax
jne 0x9840
jmp 0x985f
leaq 0x7bbc(%rip), %rdi      # 0x11403
leaq 0x774a(%rip), %rsi      # 0x10f98
movl $0x358, %edx            # imm = 0x358
leaq 0x7b7f(%rip), %rcx      # 0x113d9
callq 0x21a0
movq -0x10(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x34(%rax)
leaq -0x18(%rbp), %rdi
callq 0x9ca0
cmpl $0x0, %eax
jne 0x989b
jmp 0x98ba
leaq 0x7b77(%rip), %rdi      # 0x11419
leaq 0x76ef(%rip), %rsi      # 0x10f98
movl $0x365, %edx            # imm = 0x365
leaq 0x7b24(%rip), %rcx      # 0x113d9
callq 0x21a0
leaq -0x20(%rbp), %rdi
callq 0x9ca0
cmpl $0x0, %eax
jne 0x98ca
jmp 0x98e9
leaq 0x7b60(%rip), %rdi      # 0x11431
leaq 0x76c0(%rip), %rsi      # 0x10f98
movl $0x366, %edx            # imm = 0x366
leaq 0x7af5(%rip), %rcx      # 0x113d9
callq 0x21a0
leaq -0x28(%rbp), %rdi
callq 0x9ca0
cmpl $0x0, %eax
jne 0x98f9
jmp 0x9918
leaq 0x7b4a(%rip), %rdi      # 0x1144a
leaq 0x7691(%rip), %rsi      # 0x10f98
movl $0x367, %edx            # imm = 0x367
leaq 0x7ac6(%rip), %rcx      # 0x113d9
callq 0x21a0
movq 0xc6b9(%rip), %rax      # 0x15fd8
movq (%rax), %rdi
callq 0x22b0
movq 0xc6ca(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
callq 0x22b0
callq 0x2390
movq -0x10(%rbp), %rcx
movl %eax, 0x18(%rcx)
cmpl $0x0, %eax
jne 0x9b01
movl -0x18(%rbp), %edi
xorl %esi, %esi
callq 0x2140
cmpl $0x0, %eax
jne 0x995c
jmp 0x997b
leaq 0x7b00(%rip), %rdi      # 0x11463
leaq 0x762e(%rip), %rsi      # 0x10f98
movl $0x377, %edx            # imm = 0x377
leaq 0x7a63(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x1c(%rbp), %edi
movl $0x1, %esi
callq 0x2140
cmpl $0x1, %eax
jne 0x998f
jmp 0x99ae
leaq 0x7b00(%rip), %rdi      # 0x11496
leaq 0x75fb(%rip), %rsi      # 0x10f98
movl $0x378, %edx            # imm = 0x378
leaq 0x7a30(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x24(%rbp), %edi
movl $0x2, %esi
callq 0x2140
cmpl $0x2, %eax
jne 0x99c2
jmp 0x99e1
leaq 0x7b03(%rip), %rdi      # 0x114cc
leaq 0x75c8(%rip), %rsi      # 0x10f98
movl $0x379, %edx            # imm = 0x379
leaq 0x79fd(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x14(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
jne 0x99f0
jmp 0x9a0f
leaq 0x7b0b(%rip), %rdi      # 0x11502
leaq 0x759a(%rip), %rsi      # 0x10f98
movl $0x37d, %edx            # imm = 0x37D
leaq 0x79cf(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x20(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
jne 0x9a1e
jmp 0x9a3d
leaq 0x7af8(%rip), %rdi      # 0x1151d
leaq 0x756c(%rip), %rsi      # 0x10f98
movl $0x37e, %edx            # imm = 0x37E
leaq 0x79a1(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x28(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
jne 0x9a4c
jmp 0x9a6b
leaq 0x7ae6(%rip), %rdi      # 0x11539
leaq 0x753e(%rip), %rsi      # 0x10f98
movl $0x37f, %edx            # imm = 0x37F
leaq 0x7973(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x18(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
jne 0x9a7a
jmp 0x9a99
leaq 0x7adc(%rip), %rdi      # 0x1155d
leaq 0x7510(%rip), %rsi      # 0x10f98
movl $0x383, %edx            # imm = 0x383
leaq 0x7945(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x1c(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
jne 0x9aa8
jmp 0x9ac7
leaq 0x7aca(%rip), %rdi      # 0x11579
leaq 0x74e2(%rip), %rsi      # 0x10f98
movl $0x384, %edx            # imm = 0x384
leaq 0x7917(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x24(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
jne 0x9ad6
jmp 0x9af5
leaq 0x7ab9(%rip), %rdi      # 0x11596
leaq 0x74b4(%rip), %rsi      # 0x10f98
movl $0x385, %edx            # imm = 0x385
leaq 0x78e9(%rip), %rcx      # 0x113d9
callq 0x21a0
movl $0x0, -0x4(%rbp)
jmp 0x9c8d
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x18(%rax)
jne 0x9b23
leaq 0x7a43(%rip), %rdi      # 0x11555
callq 0x2310
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9c8d
jmp 0x9b25
movl -0x18(%rbp), %edi
callq 0x9260
cmpl $0x0, %eax
jne 0x9b34
jmp 0x9b53
leaq 0x7a21(%rip), %rdi      # 0x1155c
leaq 0x7456(%rip), %rsi      # 0x10f98
movl $0x392, %edx            # imm = 0x392
leaq 0x788b(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x1c(%rbp), %edi
callq 0x9260
cmpl $0x0, %eax
jne 0x9b62
jmp 0x9b81
leaq 0x7a0f(%rip), %rdi      # 0x11578
leaq 0x7428(%rip), %rsi      # 0x10f98
movl $0x393, %edx            # imm = 0x393
leaq 0x785d(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x24(%rbp), %edi
callq 0x9260
cmpl $0x0, %eax
jne 0x9b90
jmp 0x9baf
leaq 0x79fe(%rip), %rdi      # 0x11595
leaq 0x73fa(%rip), %rsi      # 0x10f98
movl $0x394, %edx            # imm = 0x394
leaq 0x782f(%rip), %rcx      # 0x113d9
callq 0x21a0
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edi
callq 0x6d50
cmpl $0x0, %eax
jne 0x9be0
jmp 0x9bff
leaq 0x79cb(%rip), %rdi      # 0x115b2
leaq 0x73aa(%rip), %rsi      # 0x10f98
movl $0x3a0, %edx            # imm = 0x3A0
leaq 0x77df(%rip), %rcx      # 0x113d9
callq 0x21a0
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %edi
callq 0x6d50
cmpl $0x0, %eax
jne 0x9c12
jmp 0x9c31
leaq 0x79c3(%rip), %rdi      # 0x115dc
leaq 0x7378(%rip), %rsi      # 0x10f98
movl $0x3a1, %edx            # imm = 0x3A1
leaq 0x77ad(%rip), %rcx      # 0x113d9
callq 0x21a0
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edi
callq 0x6d50
cmpl $0x0, %eax
jne 0x9c44
jmp 0x9c63
leaq 0x79bc(%rip), %rdi      # 0x11607
leaq 0x7346(%rip), %rsi      # 0x10f98
movl $0x3a2, %edx            # imm = 0x3A2
leaq 0x777b(%rip), %rcx      # 0x113d9
callq 0x21a0
movq 0xcba6(%rip), %rax      # 0x16810
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8e40
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x7460
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)