#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;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int do_child(void) {
  int fd, retval;
  struct timeval tv;
  if ((fd = open("/dev/ttypf", O_WRONLY)) == -1) {
    printf("Error opening %s for writing, signalling parent to quit\n",
           "/dev/ttypf");
    perror(NULL);
    printf("Please make sure that %s is not in use while running this test\n",
           "/dev/ttypf");
    exit(-1);
  }
  tv.tv_sec = 2;
  tv.tv_usec = 0;
  select(0, NULL, NULL, NULL, &tv);
  retval = write(fd, "minixrocks", strlen("minixrocks"));
  close(fd);
  tv.tv_usec = 1000000;
  retval = select(0, NULL, NULL, NULL, &tv);
  exit(0);
}


x86 assembly (clang, -O0):
<do_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11e2 <do_child+0x62>
lea    0xe5b(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
lea    0xe78(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movl   $0x2,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1070 <select@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0xe72(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%edx
lea    0xe61(%rip),%rsi
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
movl   $0xf4240,-0xc(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1070 <select@plt>
mov    %eax,-0x8(%rbp)
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<do_child>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    11d9 <do_child+0x59>
lea    0xe61(%rip),%rdi
lea    0xe4f(%rip),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <perror@plt>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %eax,%ebx
movq   $0x2,0x8(%rsp)
lea    0x8(%rsp),%r14
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <select@plt>
lea    0xe84(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
movl   $0xf4240,0xc(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <select@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [11 x i8] c"/dev/ttypf\00"
@O_WRONLY = global i32 0
@.str.1 = [57 x i8] c"Error opening %s for writing, signalling parent to quit\0A\00"
@.str.2 = [64 x i8] c"Please make sure that %s is not in use while running this test\0A\00"
@.str.3 = [11 x i8] c"minixrocks\00"
define i32 @do_child() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = load i32, i32* @O_WRONLY
%5 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @perror(i32* null)
%10 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 2, i32* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 0, i32* %14
%15 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
%16 = load i32, i32* %1
%17 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @write(i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %1
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 1000000, i32* %21
%22 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
store i32 %22, i32* %2
%23 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [11 x i8] c"/dev/ttypf\00"
@O_WRONLY = global i32 0
@.str.1 = [57 x i8] c"Error opening %s for writing, signalling parent to quit\0A\00"
@.str.2 = [64 x i8] c"Please make sure that %s is not in use while running this test\0A\00"
@.str.3 = [11 x i8] c"minixrocks\00"
define i32 @do_child() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @perror(i32* null)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 2, i32* %12
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i32 0, i32* %13
%14 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %1)
%15 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @write(i32 %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i32 @close(i32 %4)
store i32 1000000, i32* %13
%18 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %1)
%19 = call i32 @exit(i32 0)
unreachable
}