// File: /workspace/github_cpp_makefile_star2_O3/ryuichiueda[P]GlueLang/src/ExecForEach.cc
// Function: ExecForEach::execChild(DefFile*, DefStr*)
void ExecForEach::execChild(DefFile *f,  DefStr *s)
{
	string tmpdir = m_env->m_tmpdir + "/" + m_name;

	string line;
	while (getline(cin, line)){
		vector<string> ws;
		line += ' ';//add a space at the end of a line
		int from = 0;
		for(size_t i=from;i<line.size();i++){
			if(line.at(i) == ' '){
				ws.push_back(line.substr(from,i-from));
				from = i + 1;
			}
		}

		int pid = fork();
		if(pid < 0)
			exit(4);

		if(pid == 0){//child process (procedures in the loop)
			auto argv = new char* [ws.size()+2];
			argv[0] = (char *)tmpdir.c_str();
			for(size_t i=0;i<ws.size();i++)
				argv[i+1] = (char *)(ws[i].c_str());
			argv[ws.size()+1] = NULL;

			vOptProc(argv[0]);
			ifstream ifs(argv[0]);
			Feeder feeder(&ifs);
		
			m_env->initExecProc((const char**)argv);
			Script scr(&feeder,m_env,NULL);
		
			scr.setSilent();
			scr.parse();
			scr.exec(f,s); // exit in the exec function
		}else{
			int options = 0;
			int status;
			int wpid = waitpid(pid,&status,options);
			if(wpid < 1){
				m_error_msg = "Command wait error";
				m_exit_status = 2;
				throw this;
			}

			if(!WIFEXITED(status)){
				if(WIFSIGNALED(status) && WTERMSIG(status) == 13){//sigpipe
					continue;
				}else if(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR1){
					exit(0);
				}else{
					exit(0);
				}
			}else{
			       	m_exit_status = WEXITSTATUS(status);
			       	if(m_exit_status == 0){
					continue;
				}else if(m_exit_status == 128){
					exit(0);
				}else{
					exit(m_exit_status);
				}
			}
		}
	}
	exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movq %rdx, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, %rbx
movq 0x10(%rdi), %rax
leaq 0x80(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0xc0(%rax), %rsi
movq 0xc8(%rax), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x745a
leaq 0x719a(%rip), %rsi      # 0x1462e
movq %r14, %rdi
callq 0x65d0
movq 0xb0(%rbx), %rsi
movq 0xb8(%rbx), %rdx
leaq 0x70(%rsp), %rdi
callq 0x6100
leaq 0x60(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0xd4d4
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
jmp 0xd4e1
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0xd513
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6330
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xeaaa(%rip), %r14      # 0x1bfd8
movq %rsp, %r13
leaq 0x70(%rsp), %rbp
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6300
movsbl %al, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x65c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xd7c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq %r13, %rdi
movl $0x20, %esi
callq 0x6290
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0xd5ee
xorl %ecx, %ecx
xorl %r15d, %r15d
movq (%rsp), %rdx
cmpb $0x20, (%rdx,%r15)
jne 0xd5e6
movslq %ecx, %rdx
movq %r15, %rcx
subq %rdx, %rcx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x6350
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0xc136
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0xd5dd
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6330
leal 0x1(%r15), %ecx
movq 0x8(%rsp), %rax
incq %r15
cmpq %rax, %r15
jb 0xd597
callq 0x60c0
testl %eax, %eax
js 0xd770
movq %rbx, %r13
je 0xd637
movl %eax, %edi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x6250
testl %eax, %eax
jle 0xd77a
movl 0x70(%rsp), %ecx
movl %ecx, %eax
andl $0x7f, %eax
movq %r13, %rbx
je 0xd74d
cmpl $0xd, %eax
movq %rsp, %r13
je 0xd761
jmp 0xd7b3
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r14
movq %r14, %rbx
subq %r12, %rbx
sarq $0x5, %rbx
leaq 0x2(%rbx), %rax
shrq $0x3d, %rax
leaq 0x10(,%rbx,8), %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x6030
movq %rax, %r15
movq 0x50(%rsp), %rax
movq %rax, (%r15)
cmpq %r12, %r14
je 0xd6a0
cmpq $0x1, %rbx
movq %rbx, %rax
adcq $0x0, %rax
xorl %ecx, %ecx
movq (%r12), %rdx
movq %rdx, 0x8(%r15,%rcx,8)
incq %rcx
addq $0x20, %r12
cmpq %rcx, %rax
jne 0xd68b
movq $0x0, 0x8(%r15,%rbx,8)
movq (%r15), %rsi
movq %r13, %rdi
callq 0xeee8
movq (%r15), %rsi
movq %rbp, %rdi
movl $0x8, %edx
callq 0x65b0
leaq 0x278(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0xefcc
movq %r13, %rbx
movq 0x10(%r13), %rdi
movq %r15, %rsi
callq 0xa8cc
movq 0x10(%rbx), %rdx
leaq 0x2c0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x12680
movb $0x1, 0x345(%rsp)
movq %r15, %rdi
callq 0x126f4
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x12ba2
movq %r15, %rdi
callq 0x1269c
movq %r14, %rdi
callq 0xf0ae
movq %rbp, %rdi
callq 0x60b0
leaq 0x80(%rsp), %r12
movq 0xe890(%rip), %r14      # 0x1bfd8
movq %rsp, %r13
jmp 0xd761
shrl $0x8, %ecx
movzbl %cl, %edi
movl %edi, 0x80(%rbx)
testb %dil, %dil
movq %rsp, %r13
jne 0xd7b8
leaq 0x20(%rsp), %rdi
callq 0xbcb0
jmp 0xd536
movl $0x4, %edi
callq 0x63c0
leaq 0x60(%r13), %rdi
leaq 0x6dc3(%rip), %rsi      # 0x14548
callq 0x6410
movl $0x2, 0x80(%r13)
movl $0x8, %edi
callq 0x6190
movq %r13, (%rax)
leaq 0xdf5f(%rip), %rsi      # 0x1b708
movq %rax, %rdi
xorl %edx, %edx
callq 0x6550
cmpl $0xa, %eax
jmp 0xd7c0
cmpl $0x80, %edi
jne 0xd7c2
xorl %edi, %edi
callq 0x63c0
jmp 0xd7c9
movq %rax, %r14
jmp 0xd7e9
movq %rax, %r14
jmp 0xd7f6
jmp 0xd80b
jmp 0xd80b
jmp 0xd80b
movq %rax, %r14
leaq 0x2c0(%rsp), %rdi
callq 0x1269c
leaq 0x278(%rsp), %rdi
callq 0xf0ae
leaq 0x70(%rsp), %rdi
callq 0x60b0
jmp 0xd82d
jmp 0xd80b
jmp 0xd80b
movq %rax, %r14
jmp 0xd837
movq %rax, %r14
jmp 0xd82d
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0xd82d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6330
leaq 0x20(%rsp), %rdi
callq 0xbcb0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xd852
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6330
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xd887
movq 0x60(%rsp), %rsi
jmp 0xd87f
jmp 0xd86a
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0xd887
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6330
movq %r14, %rdi
callq 0x6580
nop