// File: ryuichiueda[P]GlueLang/src/Pipeline.cc
// Function: Pipeline::execWait()
int Pipeline::execWait(void)
{
	auto *c = (Executable *)m_nodes[0];
	c->eval();
	auto argv = c->makeArgv();
	
	int i = 1;
	while(argv[i] != NULL){
		DataJob *p = NULL;
		int pid = 0;
		
		while(pid == 0){ // not forked
			if(p == NULL){
				try{
					string s(argv[i]);
					p = (DataJob *)m_env->getData(&m_scopes,&s);
				}catch(...){
					m_error_msg = "Bug of backgound process";
					m_exit_status = 2;
					throw this;
				}
			}
			pid = p->m_pid;
			//pid = m_env->getBG(argv[i]);
		}
		if(pid < 0){
			m_error_msg = "Unknown background process";
			m_exit_status = 4;
			throw this;
		}
		m_pids.push_back(pid);
		p->m_pid = 0;
		i++;
	}

	for(auto pid : m_pids)
		waitCommands(pid);

	if(m_env->m_v_opt)
		cerr << "+ pid " << m_env->m_pid << " wait done" << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x90(%rbp)
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x14640
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x10(%rbp), %rdi
callq 0x15be0
movq %rax, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x1a95b
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x1a8d6
cmpq $0x0, -0x28(%rbp)
jne 0x1a8c7
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x6710
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x7940
jmp 0x1a7df
leaq -0x51(%rbp), %rdi
callq 0x6480
movq -0x90(%rbp), %rsi
movq 0x10(%rsi), %rdi
addq $0x48, %rsi
leaq -0x50(%rbp), %rdx
callq 0xec10
movq %rax, -0xa8(%rbp)
jmp 0x1a809
movq -0xa8(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x6280
jmp 0x1a8c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x6480
jmp 0x1a84e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x6280
movq -0x60(%rbp), %rdi
callq 0x6180
movq -0x90(%rbp), %rdi
addq $0x60, %rdi
leaq 0x2e3a(%rip), %rsi      # 0x1d6a3
callq 0x6580
jmp 0x1a870
movq -0x90(%rbp), %rax
movl $0x2, 0x80(%rax)
movl $0x8, %edi
callq 0x6200
movq %rax, %rdi
movq -0x90(%rbp), %rax
movq %rax, (%rdi)
leaq 0xe311(%rip), %rsi      # 0x28bb0
xorl %eax, %eax
movl %eax, %edx
callq 0x66d0
jmp 0x1aa41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x6690
jmp 0x1a8c0
jmp 0x1aa30
jmp 0x1a8c7
movq -0x28(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1a78e
cmpl $0x0, -0x2c(%rbp)
jge 0x1a92b
movq -0x90(%rbp), %rdi
addq $0x60, %rdi
leaq 0x2e04(%rip), %rsi      # 0x1d6f2
callq 0x6580
movq -0x90(%rbp), %rax
movl $0x4, 0x80(%rax)
movl $0x8, %edi
callq 0x6200
movq %rax, %rdi
movq -0x90(%rbp), %rax
movq %rax, (%rdi)
leaq 0xe28e(%rip), %rsi      # 0x28bb0
xorl %eax, %eax
movl %eax, %edx
callq 0x66d0
movq -0x90(%rbp), %rdi
addq $0x90, %rdi
leaq -0x2c(%rbp), %rsi
callq 0xbfa0
movq -0x28(%rbp), %rax
movl $0x0, 0x48(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1a76c
movq -0x90(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0xc930
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0xa760
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x1ad20
testb $0x1, %al
jne 0x1a999
jmp 0x1a9c7
leaq -0x78(%rbp), %rdi
callq 0xa7d0
movq -0x90(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %esi
callq 0x1aa50
leaq -0x78(%rbp), %rdi
callq 0x1ad60
jmp 0x1a986
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
testb $0x1, 0xe0(%rax)
je 0x1aa25
movq 0xe606(%rip), %rdi      # 0x28fe8
leaq 0x288a(%rip), %rsi      # 0x1d273
callq 0x6410
movq %rax, %rdi
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
movl 0xe4(%rax), %esi
callq 0x66f0
movq %rax, %rdi
leaq 0x2cfc(%rip), %rsi      # 0x1d70d
callq 0x6410
movq %rax, %rdi
movq 0xe588(%rip), %rsi      # 0x28fa8
callq 0x6460
xorl %eax, %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x6700
movq %rax, %rdi
callq 0x7f90
nopw %cs:(%rax,%rax)