// File: /workspace/github_c_makefile_star2_O0/ryuichiueda[P]glueutils/src_con12/con12safe.cpp
// Function: main
int main(int argc, char * argv[])
{
	if(argc < 2){
		usage();
		exit(1);
	}

	int pips[2];
	if(pipe(pips) < 0){
		fputs("Error: pipe open error", stderr);
		exit(1);
	}

	int epips[2];
	if(pipe(epips) < 0){
		fputs("Error: pipe open error", stderr);
		exit(1);
	}

	int opips[2];
	if(pipe(opips) < 0){
		fputs("Error: pipe open error", stderr);
		exit(1);
	}

	int pid = fork();
	if(pid != 0){//parent proc
		try_close(0);
		try_close(pips[1]);
		if(dup2(pips[0], 0) == -1){
			fprintf(stderr, "Error: %s\n", strerror(errno));
			exit(1);
		}
		try_close(pips[0]);

	}else{//child proc
		close(2);
		dup2(epips[1], 2);
		close(epips[1]);
		try_close(pips[1]);

		close(1);
		dup2(opips[1], 1);
	//	close(opips[1]);
		try_close(opips[1]);

		return -execvp(argv[1], &argv[1]);
	}

	pthread_t pthread;
	pthread_create(&pthread, NULL, thread_read, &epips[0]);

	pthread_t pthread2;
	pthread_create(&pthread2, NULL, thread_read, &opips[0]);

	/*
	pthread_join(pthread2,NULL);
	*/

	int wstatus;
	int wpid;
	int lasterror = 0;
	if((wpid = waitpid(pid, &wstatus, 0)) > 0){
		if(WIFEXITED(wstatus) && WEXITSTATUS(wstatus)){
			lasterror = WEXITSTATUS(wstatus);
		}
	}


	exit(lasterror);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x15ab
callq 0x12b0
movl $0x1, %edi
callq 0x1110
leaq -0x18(%rbp), %rdi
callq 0x1130
cmpl $0x0, %eax
jge 0x15d9
movq 0x2a20(%rip), %rax      # 0x3fe0
movq (%rax), %rsi
leaq 0xb16(%rip), %rdi       # 0x20e0
callq 0x10f0
movl $0x1, %edi
callq 0x1110
leaq -0x20(%rbp), %rdi
callq 0x1130
cmpl $0x0, %eax
jge 0x1607
movq 0x29f2(%rip), %rax      # 0x3fe0
movq (%rax), %rsi
leaq 0xae8(%rip), %rdi       # 0x20e0
callq 0x10f0
movl $0x1, %edi
callq 0x1110
leaq -0x28(%rbp), %rdi
callq 0x1130
cmpl $0x0, %eax
jge 0x1635
movq 0x29c4(%rip), %rax      # 0x3fe0
movq (%rax), %rsi
leaq 0xaba(%rip), %rdi       # 0x20e0
callq 0x10f0
movl $0x1, %edi
callq 0x1110
callq 0x1050
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x16a4
xorl %edi, %edi
callq 0x1330
movl -0x14(%rbp), %edi
callq 0x1330
movl -0x18(%rbp), %edi
xorl %esi, %esi
callq 0x10e0
cmpl $-0x1, %eax
jne 0x169a
movq 0x2978(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x1060
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0xa36(%rip), %rsi       # 0x20bf
movb $0x0, %al
callq 0x1150
movl $0x1, %edi
callq 0x1110
movl -0x18(%rbp), %edi
callq 0x1330
jmp 0x170b
movl $0x2, %edi
callq 0x11a0
movl -0x1c(%rbp), %edi
movl $0x2, %esi
callq 0x10e0
movl -0x1c(%rbp), %edi
callq 0x11a0
movl -0x14(%rbp), %edi
callq 0x1330
movl $0x1, %edi
callq 0x11a0
movl -0x24(%rbp), %edi
movl $0x1, %esi
callq 0x10e0
movl -0x24(%rbp), %edi
callq 0x1330
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x10c0
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
addq $0x60, %rsp
popq %rbp
retq
leaq -0x20(%rbp), %rcx
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x39e(%rip), %rdx      # 0x1380
callq 0x1190
leaq -0x28(%rbp), %rcx
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x3b6(%rip), %rdx      # 0x1380
callq 0x1190
movl $0x0, -0x4c(%rbp)
movl -0x2c(%rbp), %edi
leaq -0x44(%rbp), %rsi
xorl %edx, %edx
callq 0x10d0
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
jle 0x1783
movl -0x44(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x1781
movl -0x44(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
cmpl $0x0, %eax
je 0x1781
movl -0x44(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1783
movl -0x4c(%rbp), %edi
callq 0x1110
nopl (%rax,%rax)