#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 */
scalar_t__ READ();
int /*<<< orphan*/ e(int);
int /*<<< orphan*/ exit(int);
scalar_t__ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *, struct timeval *);
void test_reattach_child() {
  struct timeval tv;
  if (READ() != 0)
    e(100);
  tv.tv_sec = 2;
  tv.tv_usec = 0;
  if (select(0, NULL, NULL, NULL, &tv) != 0)
    e(101);
  exit(42);
}


x86 assembly (clang, -O0):
<test_reattach_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <READ@plt>
cmp    $0x0,%rax
je     1163 <test_reattach_child+0x23>
mov    $0x64,%edi
call   1050 <e@plt>
movl   $0x2,-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>
cmp    $0x0,%rax
je     119b <test_reattach_child+0x5b>
mov    $0x65,%edi
call   1050 <e@plt>
mov    $0x2a,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<test_reattach_child>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <READ@plt>
test   %rax,%rax
je     115a <test_reattach_child+0x1a>
mov    $0x64,%edi
call   1050 <e@plt>
movl   $0x2,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>
test   %rax,%rax
je     118c <test_reattach_child+0x4c>
mov    $0x65,%edi
call   1050 <e@plt>
mov    $0x2a,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define void @test_reattach_child() {
%1 = alloca %struct.timeval
%2 = call i64 (...) @READ()
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @e(i32 100)
br label %6
6: ; preds = %4, %0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
store i32 2, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
store i64 0, i64* %8
%9 = call i64 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %1)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @e(i32 101)
br label %13
13: ; preds = %11, %6
%14 = call i32 @exit(i32 42)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @test_reattach_child() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = tail call i64 (...) @READ()
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @e(i32 100)
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 2, i32* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 0, i64* %9
%10 = call i64 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = call i32 @e(i32 101)
br label %14
14: ; preds = %12, %7
%15 = call i32 @exit(i32 42)
unreachable
}