#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  int sin_family;
  TYPE_1__ sin_addr;
  void *sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sin1;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ from;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
void *INADDR_ANY;
int MSG_DONTWAIT;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int getpid();
void *htonl(int);
void *htons(int);
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ recvfrom(int, char *, size_t, int, struct sockaddr *, int *);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/, struct timeval *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ start_server(struct sockaddr_in *);
int main() {
  int s, fd_null;
  struct sockaddr_in sin1, sin2, sin4, from;
  pid_t pid = 0;
  char buf[1024];
  fd_set rdfds;
  struct timeval timeout;
  socklen_t fromlen;
  sin1.sin_family = AF_INET;
  sin1.sin_port = htons((getpid() % 32768) + 11000);
  sin1.sin_addr.s_addr = INADDR_ANY;
  pid = start_server(&sin1);
  sin2.sin_family = AF_INET;
  sin2.sin_port = htons((getpid() % 32768) + 10000);
  sin2.sin_addr.s_addr = INADDR_ANY;
  sin4.sin_family = 47;
  sin4.sin_port = 0;
  sin4.sin_addr.s_addr = htonl(0x0AFFFEFD);
  fromlen = sizeof(from);
  fd_null = open("/dev/null", O_WRONLY);
  recvfrom(-1, buf, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen);
  recvfrom(fd_null, buf, sizeof(buf), MSG_DONTWAIT, (struct sockaddr *)&from,
           &fromlen);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  FD_ZERO(&rdfds);
  FD_SET(s, &rdfds);
  timeout.tv_sec = 2;
  timeout.tv_usec = 0;
  select(s + 1, &rdfds, 0, 0, &timeout);
  recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)-1, &fromlen);
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  FD_ZERO(&rdfds);
  FD_SET(s, &rdfds);
  timeout.tv_sec = 2;
  timeout.tv_usec = 0;
  select(s + 1, &rdfds, 0, 0, &timeout);
  recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&from, (socklen_t *)-1);
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  FD_ZERO(&rdfds);
  FD_SET(s, &rdfds);
  timeout.tv_sec = 2;
  timeout.tv_usec = 0;
  select(s + 1, &rdfds, 0, 0, &timeout);
  recvfrom(s, (void *)-1, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen);
  recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen);
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  FD_ZERO(&rdfds);
  FD_SET(s, &rdfds);
  timeout.tv_sec = 2;
  timeout.tv_usec = 0;
  select(s + 1, &rdfds, 0, 0, &timeout);
  recvfrom(s, buf, sizeof(buf), -1, (struct sockaddr *)&from, &fromlen);
  recvfrom(s, buf, (size_t)-1, MSG_DONTWAIT, (struct sockaddr *)&from,
           &fromlen);
  close(s);
  close(fd_null);
  if (pid > 0)
    (void)kill(pid, SIGKILL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x78(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    $0x8000,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x2af8,%edi
call   1040 <htons@plt>
mov    %rax,-0x18(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   10e0 <start_server@plt>
mov    %rax,-0x78(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    $0x8000,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x2710,%edi
call   1040 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
movl   $0x2f,-0x58(%rbp)
movq   $0x0,-0x48(%rbp)
mov    $0xafffefd,%edi
call   1050 <htonl@plt>
mov    %rax,-0x50(%rbp)
movl   $0x18,-0x49c(%rbp)
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
lea    0xd5c(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0xc(%rbp)
lea    -0x480(%rbp),%rsi
lea    -0x70(%rbp),%r8
mov    $0xffffffff,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x49c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    -0xc(%rbp),%edi
lea    -0x480(%rbp),%rsi
mov    0x2ce0(%rip),%rax
mov    (%rax),%ecx
lea    -0x70(%rbp),%r8
mov    $0x400,%edx
lea    -0x49c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
mov    0x2cc9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
lea    -0x484(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x484(%rbp),%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,-0x498(%rbp)
movq   $0x0,-0x490(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x484(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x498(%rbp),%r8
mov    %ecx,%edx
call   1090 <select@plt>
mov    -0x8(%rbp),%edi
lea    -0x480(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0xffffffffffffffff,%r8
lea    -0x49c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
mov    0x2c23(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
lea    -0x484(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x484(%rbp),%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,-0x498(%rbp)
movq   $0x0,-0x490(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x484(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x498(%rbp),%r8
mov    %ecx,%edx
call   1090 <select@plt>
mov    -0x8(%rbp),%edi
lea    -0x480(%rbp),%rsi
lea    -0x70(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0xffffffffffffffff,%r9
call   10a0 <recvfrom@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2b81(%rip),%rax
mov    (%rax),%edi
mov    0x2b80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
lea    -0x484(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x484(%rbp),%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,-0x498(%rbp)
movq   $0x0,-0x490(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x484(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x498(%rbp),%r8
mov    %ecx,%edx
call   1090 <select@plt>
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%r8
mov    $0xffffffffffffffff,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x49c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    -0x8(%rbp),%edi
lea    -0x480(%rbp),%rsi
lea    -0x70(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x49c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2abd(%rip),%rax
mov    (%rax),%edi
mov    0x2abc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
lea    -0x484(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x484(%rbp),%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,-0x498(%rbp)
movq   $0x0,-0x490(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x484(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x498(%rbp),%r8
mov    %ecx,%edx
call   1090 <select@plt>
mov    -0x8(%rbp),%edi
lea    -0x480(%rbp),%rsi
lea    -0x70(%rbp),%r8
mov    $0x400,%edx
mov    $0xffffffff,%ecx
lea    -0x49c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    -0x8(%rbp),%edi
lea    -0x480(%rbp),%rsi
mov    0x2a0d(%rip),%rax
mov    (%rax),%ecx
lea    -0x70(%rbp),%r8
mov    $0xffffffffffffffff,%rdx
lea    -0x49c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmpq   $0x0,-0x78(%rbp)
jle    15f9 <main+0x429>
mov    -0x78(%rbp),%rdi
mov    0x29c6(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
xor    %eax,%eax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0x7fff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffff8000,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x2af8,%edi
call   1040 <htons@plt>
mov    %rax,0x38(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
lea    0x28(%rsp),%r14
mov    %r14,%rdi
call   10e0 <start_server@plt>
mov    %rax,0x20(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0x7fff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffff8000,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x2710,%edi
call   1040 <htons@plt>
mov    $0xafffefd,%edi
call   1050 <htonl@plt>
movl   $0x18,0x4(%rsp)
mov    0x2d2b(%rip),%rax
mov    (%rax),%esi
lea    0xd7a(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
mov    %eax,0x1c(%rsp)
lea    0x60(%rsp),%r12
lea    0x48(%rsp),%rbx
lea    0x4(%rsp),%r15
mov    $0x400,%edx
mov    $0xffffffff,%edi
mov    %r12,%rsi
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r15,%r9
call   10a0 <recvfrom@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%edx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rbx,%r8
mov    %r15,%r9
mov    %r15,%rbx
call   10a0 <recvfrom@plt>
mov    0x2ce6(%rip),%r12
mov    (%r12),%edi
mov    0x2ce3(%rip),%r13
mov    0x0(%r13),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
lea    0x44(%rsp),%r14
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x1(%rbp),%edi
lea    0x8(%rsp),%r15
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1090 <select@plt>
mov    $0x400,%edx
mov    %ebp,%edi
lea    0x60(%rsp),%rsi
xor    %ecx,%ecx
mov    $0xffffffffffffffff,%r8
mov    %rbx,%r9
call   10a0 <recvfrom@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
mov    %r13,%rbx
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
lea    0x28(%rsp),%rsi
mov    %rsi,%r13
mov    $0x18,%edx
call   10c0 <connect@plt>
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x1(%rbp),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1090 <select@plt>
mov    $0x400,%edx
mov    %ebp,%edi
lea    0x60(%rsp),%rsi
xor    %ecx,%ecx
lea    0x48(%rsp),%r15
mov    %r15,%r8
mov    $0xffffffffffffffff,%r9
call   10a0 <recvfrom@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%r12),%edi
mov    (%rbx),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r13,%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x1(%rbp),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x8(%rsp),%r8
call   1090 <select@plt>
mov    $0x400,%edx
mov    %ebp,%edi
mov    $0xffffffffffffffff,%rsi
xor    %ecx,%ecx
mov    %r15,%r8
lea    0x4(%rsp),%r13
mov    %r13,%r9
call   10a0 <recvfrom@plt>
mov    $0x400,%edx
mov    %ebp,%edi
lea    0x60(%rsp),%rsi
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r13,%r9
call   10a0 <recvfrom@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2b3a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%r12d
mov    %eax,%edi
lea    0x28(%rsp),%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
movl   $0x2,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x1(%r12),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x8(%rsp),%r8
call   1090 <select@plt>
mov    $0x400,%edx
mov    %r12d,%edi
lea    0x60(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xffffffff,%ecx
mov    %r15,%r8
mov    %r13,%r9
call   10a0 <recvfrom@plt>
mov    0x2ab2(%rip),%rax
mov    (%rax),%ecx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xffffffffffffffff,%rdx
mov    %r15,%r8
mov    %r13,%r9
call   10a0 <recvfrom@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    0x1c(%rsp),%edi
call   1060 <close@plt>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
jle    1551 <main+0x381>
mov    0x2a6e(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
xor    %eax,%eax
add    $0x468,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i8* null
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@MSG_DONTWAIT = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SIGKILL = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i64
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca %struct.timeval
%12 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %8
%13 = load i8*, i8** @AF_INET
%14 = ptrtoint i8* %13 to i32
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %14, i32* %15
%16 = call i32 (...) @getpid()
%17 = srem i32 %16, 32768
%18 = add nsw i32 %17, 11000
%19 = call i8* @htons(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i8* %19, i8** %20
%21 = load i8*, i8** @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i8* %21, i8** %23
%24 = call i64 @start_server(%struct.sockaddr_in* %4)
store i64 %24, i64* %8
%25 = load i8*, i8** @AF_INET
%26 = ptrtoint i8* %25 to i32
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %26, i32* %27
%28 = call i32 (...) @getpid()
%29 = srem i32 %28, 32768
%30 = add nsw i32 %29, 10000
%31 = call i8* @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i8* %31, i8** %32
%33 = load i8*, i8** @INADDR_ANY
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i8* %33, i8** %35
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 47, i32* %36
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* null, i8** %37
%38 = call i8* @htonl(i32 184549117)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i8* %38, i8** %40
store i32 24, i32* %12
%41 = load i32, i32* @O_WRONLY
%42 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %41)
store i32 %42, i32* %3
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%45 = call i32 @recvfrom(i32 -1, i8* %43, i64 1024, i32 0, %struct.sockaddr* %44, i32* %12)
%46 = load i32, i32* %3
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%48 = load i32, i32* @MSG_DONTWAIT
%49 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%50 = call i32 @recvfrom(i32 %46, i8* %47, i64 1024, i32 %48, %struct.sockaddr* %49, i32* %12)
%51 = load i32, i32* @PF_INET
%52 = load i32, i32* @SOCK_STREAM
%53 = call i32 @socket(i32 %51, i32 %52, i32 0)
store i32 %53, i32* %2
%54 = load i32, i32* %2
%55 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%56 = call i32 @connect(i32 %54, %struct.sockaddr* %55, i32 24)
%57 = call i32 @FD_ZERO(i32* %10)
%58 = load i32, i32* %2
%59 = call i32 @FD_SET(i32 %58, i32* %10)
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 2, i32* %60
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
store i64 0, i64* %61
%62 = load i32, i32* %2
%63 = add nsw i32 %62, 1
%64 = call i32 @select(i32 %63, i32* %10, i32 0, i32 0, %struct.timeval* %11)
%65 = load i32, i32* %2
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%67 = call i32 @recvfrom(i32 %65, i8* %66, i64 1024, i32 0, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32* %12)
%68 = load i32, i32* %2
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* @PF_INET
%71 = load i32, i32* @SOCK_STREAM
%72 = call i32 @socket(i32 %70, i32 %71, i32 0)
store i32 %72, i32* %2
%73 = load i32, i32* %2
%74 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%75 = call i32 @connect(i32 %73, %struct.sockaddr* %74, i32 24)
%76 = call i32 @FD_ZERO(i32* %10)
%77 = load i32, i32* %2
%78 = call i32 @FD_SET(i32 %77, i32* %10)
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 2, i32* %79
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
store i64 0, i64* %80
%81 = load i32, i32* %2
%82 = add nsw i32 %81, 1
%83 = call i32 @select(i32 %82, i32* %10, i32 0, i32 0, %struct.timeval* %11)
%84 = load i32, i32* %2
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%86 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%87 = call i32 @recvfrom(i32 %84, i8* %85, i64 1024, i32 0, %struct.sockaddr* %86, i32* inttoptr (i64 -1 to i32*))
%88 = load i32, i32* %2
%89 = call i32 @close(i32 %88)
%90 = load i32, i32* @PF_INET
%91 = load i32, i32* @SOCK_STREAM
%92 = call i32 @socket(i32 %90, i32 %91, i32 0)
store i32 %92, i32* %2
%93 = load i32, i32* %2
%94 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%95 = call i32 @connect(i32 %93, %struct.sockaddr* %94, i32 24)
%96 = call i32 @FD_ZERO(i32* %10)
%97 = load i32, i32* %2
%98 = call i32 @FD_SET(i32 %97, i32* %10)
%99 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 2, i32* %99
%100 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
store i64 0, i64* %100
%101 = load i32, i32* %2
%102 = add nsw i32 %101, 1
%103 = call i32 @select(i32 %102, i32* %10, i32 0, i32 0, %struct.timeval* %11)
%104 = load i32, i32* %2
%105 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%106 = call i32 @recvfrom(i32 %104, i8* inttoptr (i64 -1 to i8*), i64 1024, i32 0, %struct.sockaddr* %105, i32* %12)
%107 = load i32, i32* %2
%108 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%109 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%110 = call i32 @recvfrom(i32 %107, i8* %108, i64 1024, i32 0, %struct.sockaddr* %109, i32* %12)
%111 = load i32, i32* %2
%112 = call i32 @close(i32 %111)
%113 = load i32, i32* @PF_INET
%114 = load i32, i32* @SOCK_STREAM
%115 = call i32 @socket(i32 %113, i32 %114, i32 0)
store i32 %115, i32* %2
%116 = load i32, i32* %2
%117 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%118 = call i32 @connect(i32 %116, %struct.sockaddr* %117, i32 24)
%119 = call i32 @FD_ZERO(i32* %10)
%120 = load i32, i32* %2
%121 = call i32 @FD_SET(i32 %120, i32* %10)
%122 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 2, i32* %122
%123 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
store i64 0, i64* %123
%124 = load i32, i32* %2
%125 = add nsw i32 %124, 1
%126 = call i32 @select(i32 %125, i32* %10, i32 0, i32 0, %struct.timeval* %11)
%127 = load i32, i32* %2
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%129 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%130 = call i32 @recvfrom(i32 %127, i8* %128, i64 1024, i32 -1, %struct.sockaddr* %129, i32* %12)
%131 = load i32, i32* %2
%132 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%133 = load i32, i32* @MSG_DONTWAIT
%134 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%135 = call i32 @recvfrom(i32 %131, i8* %132, i64 -1, i32 %133, %struct.sockaddr* %134, i32* %12)
%136 = load i32, i32* %2
%137 = call i32 @close(i32 %136)
%138 = load i32, i32* %3
%139 = call i32 @close(i32 %138)
%140 = load i64, i64* %8
%141 = icmp sgt i64 %140, 0
br i1 %141, label %142, label %146
142: ; preds = %0
%143 = load i64, i64* %8
%144 = load i32, i32* @SIGKILL
%145 = call i32 @kill(i64 %143, i32 %144)
br label %146
146: ; preds = %142, %0
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i8* null
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@MSG_DONTWAIT = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SIGKILL = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %1 to i8*
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
%11 = bitcast %struct.timeval* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = load i8*, i8** @AF_INET
%14 = ptrtoint i8* %13 to i64
%15 = trunc i64 %14 to i32
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %15, i32* %16
%17 = tail call i32 (...) @getpid()
%18 = srem i32 %17, 32768
%19 = add nsw i32 %18, 11000
%20 = tail call i8* @htons(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %20, i8** %21
%22 = load i8*, i8** @INADDR_ANY
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i8* %22, i8** %23
%24 = call i64 @start_server(%struct.sockaddr_in* %1)
%25 = call i32 (...) @getpid()
%26 = srem i32 %25, 32768
%27 = add nsw i32 %26, 10000
%28 = call i8* @htons(i32 %27)
%29 = call i8* @htonl(i32 184549117)
store i32 24, i32* %6
%30 = load i32, i32* @O_WRONLY
%31 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%33 = call i32 @recvfrom(i32 -1, i8* %9, i64 1024, i32 0, %struct.sockaddr* %32, i32* %6)
%34 = load i32, i32* @MSG_DONTWAIT
%35 = call i32 @recvfrom(i32 %31, i8* %9, i64 1024, i32 %34, %struct.sockaddr* %32, i32* %6)
%36 = load i32, i32* @PF_INET
%37 = load i32, i32* @SOCK_STREAM
%38 = call i32 @socket(i32 %36, i32 %37, i32 0)
%39 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%40 = call i32 @connect(i32 %38, %struct.sockaddr* %39, i32 24)
%41 = call i32 @FD_ZERO(i32* %4)
%42 = call i32 @FD_SET(i32 %38, i32* %4)
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 2, i32* %43
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 0, i64* %44
%45 = add nsw i32 %38, 1
%46 = call i32 @select(i32 %45, i32* %4, i32 0, i32 0, %struct.timeval* %5)
%47 = call i32 @recvfrom(i32 %38, i8* %9, i64 1024, i32 0, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32* %6)
%48 = call i32 @close(i32 %38)
%49 = load i32, i32* @PF_INET
%50 = load i32, i32* @SOCK_STREAM
%51 = call i32 @socket(i32 %49, i32 %50, i32 0)
%52 = call i32 @connect(i32 %51, %struct.sockaddr* %39, i32 24)
%53 = call i32 @FD_ZERO(i32* %4)
%54 = call i32 @FD_SET(i32 %51, i32* %4)
store i32 2, i32* %43
store i64 0, i64* %44
%55 = add nsw i32 %51, 1
%56 = call i32 @select(i32 %55, i32* %4, i32 0, i32 0, %struct.timeval* %5)
%57 = call i32 @recvfrom(i32 %51, i8* %9, i64 1024, i32 0, %struct.sockaddr* %32, i32* inttoptr (i64 -1 to i32*))
%58 = call i32 @close(i32 %51)
%59 = load i32, i32* @PF_INET
%60 = load i32, i32* @SOCK_STREAM
%61 = call i32 @socket(i32 %59, i32 %60, i32 0)
%62 = call i32 @connect(i32 %61, %struct.sockaddr* %39, i32 24)
%63 = call i32 @FD_ZERO(i32* %4)
%64 = call i32 @FD_SET(i32 %61, i32* %4)
store i32 2, i32* %43
store i64 0, i64* %44
%65 = add nsw i32 %61, 1
%66 = call i32 @select(i32 %65, i32* %4, i32 0, i32 0, %struct.timeval* %5)
%67 = call i32 @recvfrom(i32 %61, i8* inttoptr (i64 -1 to i8*), i64 1024, i32 0, %struct.sockaddr* %32, i32* %6)
%68 = call i32 @recvfrom(i32 %61, i8* %9, i64 1024, i32 0, %struct.sockaddr* %32, i32* %6)
%69 = call i32 @close(i32 %61)
%70 = load i32, i32* @PF_INET
%71 = load i32, i32* @SOCK_STREAM
%72 = call i32 @socket(i32 %70, i32 %71, i32 0)
%73 = call i32 @connect(i32 %72, %struct.sockaddr* %39, i32 24)
%74 = call i32 @FD_ZERO(i32* %4)
%75 = call i32 @FD_SET(i32 %72, i32* %4)
store i32 2, i32* %43
store i64 0, i64* %44
%76 = add nsw i32 %72, 1
%77 = call i32 @select(i32 %76, i32* %4, i32 0, i32 0, %struct.timeval* %5)
%78 = call i32 @recvfrom(i32 %72, i8* %9, i64 1024, i32 -1, %struct.sockaddr* %32, i32* %6)
%79 = load i32, i32* @MSG_DONTWAIT
%80 = call i32 @recvfrom(i32 %72, i8* %9, i64 -1, i32 %79, %struct.sockaddr* %32, i32* %6)
%81 = call i32 @close(i32 %72)
%82 = call i32 @close(i32 %31)
%83 = icmp sgt i64 %24, 0
br i1 %83, label %84, label %87
84: ; preds = %0
%85 = load i32, i32* @SIGKILL
%86 = call i32 @kill(i64 %24, i32 %85)
br label %87
87: ; preds = %84, %0
ret i32 0
}