#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;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int sock1, sock2;
  if ((sock1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return (EXIT_FAILURE);
  if ((sock2 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return (EXIT_FAILURE);
  fd_set fdset;
  FD_ZERO(&fdset);
  FD_SET(sock1, &fdset);
  FD_SET(sock2, &fdset);
  struct timeval timeout;
  timeout.tv_sec = 1;
  timeout.tv_usec = 1;
  close(sock2);
  if (select(sock2 + 1, &fdset, NULL, NULL, &timeout) != -1)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    119c <main+0x4c>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <main+0x100>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11d9 <main+0x89>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <main+0x100>
lea    -0x10(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_SET@plt>
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
cmp    $0xffffffff,%eax
je     1244 <main+0xf4>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <main+0x100>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e87(%rip),%r14
mov    (%r14),%edi
mov    0x2e65(%rip),%r15
mov    (%r15),%esi
mov    0x2e6b(%rip),%rbx
mov    (%rbx),%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11f0 <main+0xa0>
mov    %eax,%ebp
mov    (%r14),%edi
mov    (%r15),%esi
mov    (%rbx),%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11f0 <main+0xa0>
mov    %eax,%ebx
lea    0x14(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
movabs $0x100000001,%rax
mov    %rax,0x8(%rsp)
mov    %ebx,%edi
call   1030 <close@plt>
add    $0x1,%ebx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
cmp    $0xffffffff,%eax
jne    11f0 <main+0xa0>
mov    0x2dd2(%rip),%rax
jmp    11f7 <main+0xa7>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = load i32, i32* @IPPROTO_TCP
%9 = call i32 @socket(i32 %6, i32 %7, i32 %8)
store i32 %9, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %1
br label %39
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = load i32, i32* @IPPROTO_TCP
%17 = call i32 @socket(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %1
br label %39
21: ; preds = %13
%22 = call i32 @FD_ZERO(i32* %4)
%23 = load i32, i32* %2
%24 = call i32 @FD_SET(i32 %23, i32* %4)
%25 = load i32, i32* %3
%26 = call i32 @FD_SET(i32 %25, i32* %4)
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 1, i32* %27
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 1, i32* %28
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
%33 = call i32 @select(i32 %32, i32* %4, i32* null, i32* null, %struct.timeval* %5)
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %21
%36 = load i32, i32* @EXIT_FAILURE
store i32 %36, i32* %1
br label %39
37: ; preds = %21
%38 = load i32, i32* @EXIT_SUCCESS
store i32 %38, i32* %1
br label %39
39: ; preds = %37, %35, %19, %11
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = load i32, i32* @IPPROTO_TCP
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i32, i32* @EXIT_FAILURE
br label %33
10: ; preds = %0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = load i32, i32* @IPPROTO_TCP
%14 = tail call i32 @socket(i32 %11, i32 %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = load i32, i32* @EXIT_FAILURE
br label %33
18: ; preds = %10
%19 = bitcast i32* %1 to i8*
%20 = call i32 @FD_ZERO(i32* %1)
%21 = call i32 @FD_SET(i32 %6, i32* %1)
%22 = call i32 @FD_SET(i32 %14, i32* %1)
%23 = bitcast %struct.timeval* %2 to i8*
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 1, i32* %24
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 1, i32* %25
%26 = call i32 @close(i32 %14)
%27 = add nuw nsw i32 %14, 1
%28 = call i32 @select(i32 %27, i32* %1, i32* null, i32* null, %struct.timeval* %2)
%29 = icmp eq i32 %28, -1
%30 = load i32, i32* @EXIT_SUCCESS
%31 = load i32, i32* @EXIT_FAILURE
%32 = select i1 %29, i32 %30, i32 %31
br label %33
33: ; preds = %18, %16, %8
%34 = phi i32 [ %9, %8 ], [ %17, %16 ], [ %32, %18 ]
ret i32 %34
}