// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x10, %edi
callq 0x6030
movq %rax, %r12
movq 0x10(%rbx), %rax
leaq 0x88(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0xc0(%rax), %rsi
movq 0xc8(%rax), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x7456
leaq 0x5ee9(%rip), %rsi      # 0x14611
movq %r14, %rdi
callq 0x65d0
movq 0xb0(%rbx), %rsi
movq 0xb8(%rbx), %rdx
leaq 0x78(%rsp), %rdi
callq 0x6100
leaq 0x20(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0xe768
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
jmp 0xe775
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0xe7a7
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6330
movq 0x10(%rsp), %rax
movq %rax, (%r12)
movq $0x0, 0x8(%r12)
callq 0x60c0
testl %eax, %eax
jns 0xe7cc
movl $0x4, %edi
callq 0x63c0
leaq 0x78(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0x280(%rsp), %r14
testl %eax, %eax
je 0xe813
movl %eax, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x6250
testl %eax, %eax
jle 0xe8b5
movl 0x78(%rsp), %ecx
movl %ecx, %eax
andl $0x7f, %eax
je 0xe892
cmpl $0xd, %eax
je 0xe8a3
jmp 0xe8f9
movq (%r12), %rsi
movq %rbx, %rdi
callq 0xeeee
movq (%r12), %rsi
movq %r13, %rdi
movl $0x8, %edx
callq 0x65b0
movq %rbp, %rdi
movq %r13, %rsi
callq 0xefd4
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0xa8e8
movq 0x10(%rbx), %rdx
movq %r14, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0x128ac
movb $0x1, 0x305(%rsp)
movq %r14, %rdi
callq 0x12920
movq %r14, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x12dce
movq %r14, %rdi
callq 0x128c8
movq %rbp, %rdi
callq 0xf0b6
movq %r13, %rdi
callq 0x60b0
jmp 0xe8a3
shrl $0x8, %ecx
movzbl %cl, %edi
movl %edi, 0x80(%rbx)
testb %dil, %dil
jne 0xe8fe
callq 0x60c0
testl %eax, %eax
jns 0xe7de
jmp 0xe7c2
leaq 0x60(%rbx), %rdi
movq 0x68(%rbx), %rdx
leaq 0x5c64(%rip), %rcx      # 0x14528
movl $0x12, %r8d
xorl %esi, %esi
callq 0x64c0
movl $0x2, 0x80(%rbx)
movl $0x8, %edi
callq 0x6190
movq %rbx, (%rax)
leaq 0xd019(%rip), %rsi      # 0x1b908
movq %rax, %rdi
xorl %edx, %edx
callq 0x6550
cmpl $0xa, %eax
jmp 0xe903
cmpl $0x1, %edi
jne 0xe905
xorl %edi, %edi
callq 0x63c0
jmp 0xe90c
movq %rax, %rbx
jmp 0xe931
movq %rax, %rbx
jmp 0xe93b
jmp 0xe91c
jmp 0xe91c
jmp 0xe91c
movq %rax, %rbx
jmp 0xe945
movq %rax, %rbx
leaq 0x280(%rsp), %rdi
callq 0x128c8
leaq 0x30(%rsp), %rdi
callq 0xf0b6
leaq 0x78(%rsp), %rdi
callq 0x60b0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xe97a
movq 0x20(%rsp), %rsi
jmp 0xe972
jmp 0xe95d
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0xe97a
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6330
movq %rbx, %rdi
callq 0x6580
nop