// File: /workspace/github_cpp_makefile_star2_O3/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 0x745a
leaq 0x5f40(%rip), %rsi      # 0x1462e
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 0xe72e
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
jmp 0xe73b
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 0xe76d
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 0xe792
movl $0x4, %edi
callq 0x63c0
leaq 0x78(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0x280(%rsp), %r14
testl %eax, %eax
je 0xe7d9
movl %eax, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x6250
testl %eax, %eax
jle 0xe87b
movl 0x78(%rsp), %ecx
movl %ecx, %eax
andl $0x7f, %eax
je 0xe858
cmpl $0xd, %eax
je 0xe869
jmp 0xe8bf
movq (%r12), %rsi
movq %rbx, %rdi
callq 0xeee8
movq (%r12), %rsi
movq %r13, %rdi
movl $0x8, %edx
callq 0x65b0
movq %rbp, %rdi
movq %r13, %rsi
callq 0xefcc
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0xa8cc
movq 0x10(%rbx), %rdx
movq %r14, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0x12680
movb $0x1, 0x305(%rsp)
movq %r14, %rdi
callq 0x126f4
movq %r14, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x12ba2
movq %r14, %rdi
callq 0x1269c
movq %rbp, %rdi
callq 0xf0ae
movq %r13, %rdi
callq 0x60b0
jmp 0xe869
shrl $0x8, %ecx
movzbl %cl, %edi
movl %edi, 0x80(%rbx)
testb %dil, %dil
jne 0xe8c4
callq 0x60c0
testl %eax, %eax
jns 0xe7a4
jmp 0xe788
leaq 0x60(%rbx), %rdi
movq 0x68(%rbx), %rdx
leaq 0x5cbe(%rip), %rcx      # 0x14548
movl $0x12, %r8d
xorl %esi, %esi
callq 0x64c0
movl $0x2, 0x80(%rbx)
movl $0x8, %edi
callq 0x6190
movq %rbx, (%rax)
leaq 0xd053(%rip), %rsi      # 0x1b908
movq %rax, %rdi
xorl %edx, %edx
callq 0x6550
cmpl $0xa, %eax
jmp 0xe8c9
cmpl $0x1, %edi
jne 0xe8cb
xorl %edi, %edi
callq 0x63c0
jmp 0xe8d2
movq %rax, %rbx
jmp 0xe8f7
movq %rax, %rbx
jmp 0xe901
jmp 0xe8e2
jmp 0xe8e2
jmp 0xe8e2
movq %rax, %rbx
jmp 0xe90b
movq %rax, %rbx
leaq 0x280(%rsp), %rdi
callq 0x1269c
leaq 0x30(%rsp), %rdi
callq 0xf0ae
leaq 0x78(%rsp), %rdi
callq 0x60b0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xe940
movq 0x20(%rsp), %rsi
jmp 0xe938
jmp 0xe923
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0xe940
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6330
movq %rbx, %rdi
callq 0x6580