// File: /workspace/github_cpp_makefile_star2_O2/ryuichiueda[P]GlueLang/src/ExecWhile.cc
// Function: ExecWhile::execChild(DefFile*, DefStr*)
void ExecWhile::execChild(DefFile *f,  DefStr *s)
{
	auto argv = new char* [2];
	string tmpdir = m_env->m_tmpdir + "/" + m_name;
	argv[0] = (char *)tmpdir.c_str();
	argv[1] = NULL;

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

		if(pid == 0){//child process (procedures in the loop)
			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 != 1){
					exit(m_exit_status);
				}else{
					exit(0);
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
pushq $0x10
popq %rdi
callq 0x6030
movq %rax, %r12
movl $0xc0, %esi
addq 0x10(%rbx), %rsi
leaq 0x539d(%rip), %rdx      # 0x115ee
leaq 0x100(%rsp), %r14
movq %r14, %rdi
callq 0x70c7
leaq 0xb0(%rbx), %rdx
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x75a1
leaq 0x100(%rsp), %r13
movq %r13, %rdi
callq 0x6150
movq 0x10(%rsp), %rax
movq %rax, (%r12)
andq $0x0, 0x8(%r12)
leaq 0x30(%rsp), %rbp
leaq 0x78(%rsp), %r14
callq 0x60d0
testl %eax, %eax
js 0xc37c
je 0xc2dd
movl %eax, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x6260
testl %eax, %eax
jle 0xc384
movl 0x100(%rsp), %ecx
movl %ecx, %eax
andl $0x7f, %eax
je 0xc35d
cmpl $0xd, %eax
je 0xc29e
jmp 0xc3ba
movq (%r12), %rsi
movq %rbx, %rdi
callq 0xc8da
movq (%r12), %rsi
movq %r13, %rdi
pushq $0x8
popq %rdx
callq 0x6590
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc95c
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x977a
movq 0x10(%rbx), %rdx
movq %r14, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xf490
movb $0x1, 0xfd(%rsp)
movq %r14, %rdi
callq 0xf504
movq %r14, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0xf8b8
movq %r14, %rdi
callq 0xf4ac
movq %rbp, %rdi
callq 0xca02
movq %r13, %rdi
callq 0x60c0
jmp 0xc29e
shrl $0x8, %ecx
movzbl %cl, %edi
movl %edi, 0x80(%rbx)
testb %dil, %dil
je 0xc29e
cmpl $0x1, %edi
je 0xc3bd
callq 0x63a0
pushq $0x4
popq %rdi
callq 0x63a0
leaq 0x60(%rbx), %rdi
leaq 0x5179(%rip), %rsi      # 0x11508
callq 0x65b0
movl $0x2, 0x80(%rbx)
pushq $0x8
popq %rdi
callq 0x6190
movq %rbx, (%rax)
leaq 0xd558(%rip), %rsi      # 0x19908
movq %rax, %rdi
xorl %edx, %edx
callq 0x6540
cmpl $0xa, %eax
xorl %edi, %edi
callq 0x63a0
jmp 0xc3c6
movq %rax, %rbx
jmp 0xc3e8
movq %rax, %rbx
jmp 0xc3f2
jmp 0xc3d6
jmp 0xc3d6
jmp 0xc3d6
movq %rax, %rbx
jmp 0xc3ff
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xf4ac
leaq 0x30(%rsp), %rdi
callq 0xca02
leaq 0x100(%rsp), %rdi
callq 0x60c0
leaq 0x10(%rsp), %rdi
jmp 0xc411
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x6150
movq %rbx, %rdi
callq 0x6560
nop