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

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getppid();
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void do_child(void) {
  struct timeval tv;
  int retval;
  tv.tv_sec = 3 + 3 + 3 + 1;
  tv.tv_usec = 0;
  retval = select(0, NULL, NULL, NULL, &tv);
  if (kill(getppid(), SIGUSR1) < 0)
    perror("Failed to send signal");
  exit(0);
}


x86 assembly (clang, -O0):
<do_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xa,-0x10(%rbp)
movq   $0x0,-0x8(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <select@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1030 <kill@plt>
cmp    $0x0,%rax
jge    11ac <do_child+0x5c>
lea    0xe59(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<do_child>:
sub    $0x18,%rsp
movl   $0xa,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <select@plt>
xor    %eax,%eax
call   1060 <getppid@plt>
mov    0x2e63(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1030 <kill@plt>
test   %rax,%rax
jns    119f <do_child+0x4f>
lea    0xe66(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@SIGUSR1 = global i32 0
@.str = [22 x i8] c"Failed to send signal\00"
define void @do_child() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
store i32 10, i32* %3
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
store i64 0, i64* %4
%5 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %1)
store i32 %5, i32* %2
%6 = call i32 (...) @getppid()
%7 = load i32, i32* @SIGUSR1
%8 = call i64 @kill(i32 %6, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@SIGUSR1 = global i32 0
@.str = [22 x i8] c"Failed to send signal\00"
define void @do_child() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 10, i32* %3
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 0, i64* %4
%5 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %1)
%6 = call i32 (...) @getppid()
%7 = load i32, i32* @SIGUSR1
%8 = call i64 @kill(i32 %6, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32 @exit(i32 0)
unreachable
}