#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long long *);
int isPrime(long long);
int /*<<< orphan*/ printf(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void parallel_execute(int read, int write) {
  fd_set fds;
  struct timeval tv;
  int retval;
  FD_ZERO(&fds);
  FD_SET(read, &fds);
  tv.tv_sec = 5;
  tv.tv_usec = 0;
  retval = select(4000, &fds, NULL, NULL, &tv);
  if (retval == -1) {
    printf("Error! Select error!\n");
    exit(2);
  }
  FILE *fd;
  long long number;
  fd = fdopen(read, "r");
  fscanf(fd, "%lld", &number);
  fclose(fd);
  int result;
  result = isPrime(number);
  FD_ZERO(&fds);
  FD_SET(write, &fds);
  retval = select(4000, NULL, &fds, NULL, &tv);
  if (retval == -1) {
    printf("Error! Select error!\n");
    exit(2);
  }
  fd = fdopen(write, "w");
  fprintf(fd, "%d\n", result);
  fclose(fd);
}


x86 assembly (clang, -O0):
<parallel_execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   10c0 <FD_SET@plt>
movl   $0x5,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0xfa0,%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    120e <parallel_execute+0x6e>
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%edi
lea    0xdfe(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdec(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1060 <isPrime@plt>
mov    %eax,-0x3c(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    $0xfa0,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xc(%rbp),%rdx
lea    -0x20(%rbp),%r8
mov    %rcx,%rsi
call   1090 <select@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    129b <parallel_execute+0xfb>
lea    0xd74(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xd78(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%edx
lea    0xd63(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parallel_execute>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
movl   $0x5,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%r8
mov    $0xfa0,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <select@plt>
cmp    $0xffffffff,%eax
je     1294 <parallel_execute+0xf4>
lea    0xe05(%rip),%rsi
mov    %ebp,%edi
call   10a0 <fdopen@plt>
mov    %rax,%rbx
lea    0xdf6(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1060 <isPrime@plt>
mov    %eax,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
lea    0x10(%rsp),%r8
mov    $0xfa0,%edi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1090 <select@plt>
cmp    $0xffffffff,%eax
je     1294 <parallel_execute+0xf4>
lea    0xda0(%rip),%rsi
mov    %r14d,%edi
call   10a0 <fdopen@plt>
mov    %rax,%rbx
lea    0xd90(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd72(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [22 x i8] c"Error! Select error!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define void @parallel_execute(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%11 = call i32 @FD_ZERO(i32* %5)
%12 = load i32, i32* %3
%13 = call i32 @FD_SET(i32 %12, i32* %5)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 5, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i64 0, i64* %15
%16 = call i32 @select(i32 4000, i32* %5, i32* null, i32* null, %struct.timeval* %6)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 2)
unreachable
22: ; preds = %2
%23 = load i32, i32* %3
%24 = call i32* @fdopen(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %8
%25 = load i32*, i32** %8
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %9)
%27 = load i32*, i32** %8
%28 = call i32 @fclose(i32* %27)
%29 = load i64, i64* %9
%30 = call i32 @isPrime(i64 %29)
store i32 %30, i32* %10
%31 = call i32 @FD_ZERO(i32* %5)
%32 = load i32, i32* %4
%33 = call i32 @FD_SET(i32 %32, i32* %5)
%34 = call i32 @select(i32 4000, i32* null, i32* %5, i32* null, %struct.timeval* %6)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %22
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 2)
unreachable
40: ; preds = %22
%41 = load i32, i32* %4
%42 = call i32* @fdopen(i32 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %42, i32** %8
%43 = load i32*, i32** %8
%44 = load i32, i32* %10
%45 = call i32 @fprintf(i32* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str.5 = [21 x i8] c"Error! Select error!\00"
define void @parallel_execute(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = call i32 @FD_ZERO(i32* %3)
%9 = call i32 @FD_SET(i32 %0, i32* %3)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 5, i32* %10
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %11
%12 = call i32 @select(i32 4000, i32* %3, i32* null, i32* null, %struct.timeval* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %2
%18 = bitcast i64* %5 to i8*
%19 = call i32* @fdopen(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %5)
%21 = call i32 @fclose(i32* %19)
%22 = load i64, i64* %5
%23 = call i32 @isPrime(i64 %22)
%24 = call i32 @FD_ZERO(i32* %3)
%25 = call i32 @FD_SET(i32 %1, i32* %3)
%26 = call i32 @select(i32 4000, i32* null, i32* %3, i32* null, %struct.timeval* %4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%30 = call i32 @exit(i32 2)
unreachable
31: ; preds = %17
%32 = call i32* @fdopen(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%34 = call i32 @fclose(i32* %32)
ret void
}