// File: /workspace/github_c_makefile_star2_O0/alexgirao[P]aimant/subprocess.c
// Function: subprocess_fork
int subprocess_fork(struct subprocess *sp)
{
	int pid;

	assert(sp);
	assert(sp->argv);
	assert(sp->argv[0]);

	if (sp->envp && sp->search_path) {
		DEBUG_INFO("it is not allowed to use search path while specifying environment variables");
		return -1;
	}

	if ((pid = subprocess_fork0(sp)) == 0) {
		char buf[1024];
		char *execve_frontend = NULL;

		/* execute
		 */
		if (sp->envp) {
			execve(sp->argv[0], sp->argv, sp->envp);
			execve_frontend = "execve";
		} else if (sp->search_path) {
			execvp(sp->argv[0], sp->argv);
			execve_frontend = "execvp";
		} else {
			execv(sp->argv[0], sp->argv);
			execve_frontend = "execv";
		}

		snprintf(buf, sizeof(buf), "%s(%s)", execve_frontend, sp->argv[0]);
		perror(buf);
		fflush(stderr);

		close(STDIN_FILENO);
		close(STDOUT_FILENO);
		close(STDERR_FILENO);

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

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x9ce8
jmp 0x9d07
leaq 0x76e7(%rip), %rdi      # 0x113d6
leaq 0x72a2(%rip), %rsi      # 0x10f98
movl $0x3b3, %edx            # imm = 0x3B3
leaq 0x7930(%rip), %rcx      # 0x11632
callq 0x21a0
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x9d13
jmp 0x9d32
leaq 0x7941(%rip), %rdi      # 0x1165b
leaq 0x7277(%rip), %rsi      # 0x10f98
movl $0x3b4, %edx            # imm = 0x3B4
leaq 0x7905(%rip), %rcx      # 0x11632
callq 0x21a0
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
je 0x9d41
jmp 0x9d60
leaq 0x791c(%rip), %rdi      # 0x11664
leaq 0x7249(%rip), %rsi      # 0x10f98
movl $0x3b5, %edx            # imm = 0x3B5
leaq 0x78d7(%rip), %rcx      # 0x11632
callq 0x21a0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x9d81
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x9d81
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9ebe
movq -0x10(%rbp), %rdi
callq 0x97d0
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jne 0x9e96
movq $0x0, -0x428(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x9dda
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x2200
leaq 0x789f(%rip), %rax      # 0x11670
movq %rax, -0x428(%rbp)
jmp 0x9e30
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x9e0a
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x2330
leaq 0x7876(%rip), %rax      # 0x11677
movq %rax, -0x428(%rbp)
jmp 0x9e2e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x2380
leaq 0x7857(%rip), %rax      # 0x1167e
movq %rax, -0x428(%rbp)
jmp 0x9e30
leaq -0x420(%rbp), %rdi
movq -0x428(%rbp), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %r8
movl $0x400, %esi            # imm = 0x400
leaq 0x7830(%rip), %rdx      # 0x11684
movb $0x0, %al
callq 0x2170
leaq -0x420(%rbp), %rdi
callq 0x2310
movq 0xc18a(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
callq 0x22b0
xorl %edi, %edi
callq 0x21d0
movl $0x1, %edi
callq 0x21d0
movl $0x2, %edi
callq 0x21d0
callq 0x2060
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x18(%rax)
jne 0x9eb5
leaq 0x77e4(%rip), %rdi      # 0x1168b
callq 0x2310
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9ebe
jmp 0x9eb7
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
nopw (%rax,%rax)