#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 dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sin1;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int MSG_DONTWAIT;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int getpid();
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
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;
  pid_t pid = 0;
  char buf[1024];
  fd_set rdfds;
  struct timeval timeout;
  sin1.sin_family = AF_INET;
  sin1.sin_port = htons((getpid() % 32768) + 11000);
  sin1.sin_addr.s_addr = INADDR_ANY;
  signal(SIGPIPE, SIG_IGN);
  pid = start_server(&sin1);
  fd_null = open("/dev/null", O_WRONLY);
  send(-1, buf, sizeof(buf), 0);
  send(fd_null, buf, sizeof(buf), MSG_DONTWAIT);
  s = socket(PF_INET, SOCK_DGRAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  send(s, (void *)-1, sizeof(buf), 0);
  send(s, (void *)buf, -1, 0);
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  send(s, buf, sizeof(buf), MSG_DONTWAIT);
  send(s, buf, sizeof(buf), -1);
  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    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%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    %eax,-0x14(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
lea    -0x18(%rbp),%rdi
call   10b0 <start_server@plt>
mov    %rax,-0x20(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
lea    0xddb(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
lea    -0x420(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    0x2d52(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%edx
call   1050 <send@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
mov    0x2ced(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    0x2ca7(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%edx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmpq   $0x0,-0x20(%rbp)
jle    1353 <main+0x1b3>
mov    -0x20(%rbp),%rdi
mov    0x2c54(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%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    %eax,0x4(%rsp)
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   10b0 <start_server@plt>
mov    %rax,%r15
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
lea    0xdd5(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rbx
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%ecx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <send@plt>
mov    0x2d44(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %ebp,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x0(%r13),%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r12d,%edi
call   1060 <close@plt>
test   %r15,%r15
jle    1334 <main+0x194>
mov    0x2c76(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1080 <kill@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@MSG_DONTWAIT = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = 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 i64
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca %struct.timeval
store i32 0, i32* %1
store i64 0, i64* %5
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %9, i32* %10
%11 = call i32 (...) @getpid()
%12 = srem i32 %11, 32768
%13 = add nsw i32 %12, 11000
%14 = call i32 @htons(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* @SIGPIPE
%20 = load i32, i32* @SIG_IGN
%21 = call i32 @signal(i32 %19, i32 %20)
%22 = call i64 @start_server(%struct.sockaddr_in* %4)
store i64 %22, i64* %5
%23 = load i32, i32* @O_WRONLY
%24 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 %24, i32* %3
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i32 @send(i32 -1, i8* %25, i32 1024, i32 0)
%27 = load i32, i32* %3
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = load i32, i32* @MSG_DONTWAIT
%30 = call i32 @send(i32 %27, i8* %28, i32 1024, i32 %29)
%31 = load i32, i32* @PF_INET
%32 = load i32, i32* @SOCK_DGRAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%36 = call i32 @connect(i32 %34, %struct.sockaddr* %35, i32 12)
%37 = load i32, i32* %2
%38 = call i32 @send(i32 %37, i8* inttoptr (i64 -1 to i8*), i32 1024, i32 0)
%39 = load i32, i32* %2
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = call i32 @send(i32 %39, i8* %40, i32 -1, i32 0)
%42 = load i32, i32* %2
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* @PF_INET
%45 = load i32, i32* @SOCK_STREAM
%46 = call i32 @socket(i32 %44, i32 %45, i32 0)
store i32 %46, i32* %2
%47 = load i32, i32* %2
%48 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%49 = call i32 @connect(i32 %47, %struct.sockaddr* %48, i32 12)
%50 = load i32, i32* %2
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = load i32, i32* @MSG_DONTWAIT
%53 = call i32 @send(i32 %50, i8* %51, i32 1024, i32 %52)
%54 = load i32, i32* %2
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%56 = call i32 @send(i32 %54, i8* %55, i32 1024, i32 -1)
%57 = load i32, i32* %2
%58 = call i32 @close(i32 %57)
%59 = load i32, i32* %3
%60 = call i32 @close(i32 %59)
%61 = load i64, i64* %5
%62 = icmp sgt i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %0
%64 = load i64, i64* %5
%65 = load i32, i32* @SIGKILL
%66 = call i32 @kill(i64 %64, i32 %65)
br label %67
67: ; preds = %63, %0
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@MSG_DONTWAIT = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOCK_STREAM = global i32 0
@SIGKILL = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1024 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %5, i32* %6
%7 = tail call i32 (...) @getpid()
%8 = srem i32 %7, 32768
%9 = add nsw i32 %8, 11000
%10 = tail call i32 @htons(i32 %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @SIGPIPE
%15 = load i32, i32* @SIG_IGN
%16 = tail call i32 @signal(i32 %14, i32 %15)
%17 = call i64 @start_server(%struct.sockaddr_in* %1)
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @send(i32 -1, i8* %4, i32 1024, i32 0)
%21 = load i32, i32* @MSG_DONTWAIT
%22 = call i32 @send(i32 %19, i8* %4, i32 1024, i32 %21)
%23 = load i32, i32* @PF_INET
%24 = load i32, i32* @SOCK_DGRAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%27 = call i32 @connect(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = call i32 @send(i32 %25, i8* inttoptr (i64 -1 to i8*), i32 1024, i32 0)
%29 = call i32 @send(i32 %25, i8* %4, i32 -1, i32 0)
%30 = call i32 @close(i32 %25)
%31 = load i32, i32* @PF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
%34 = call i32 @connect(i32 %33, %struct.sockaddr* %26, i32 12)
%35 = load i32, i32* @MSG_DONTWAIT
%36 = call i32 @send(i32 %33, i8* %4, i32 1024, i32 %35)
%37 = call i32 @send(i32 %33, i8* %4, i32 1024, i32 -1)
%38 = call i32 @close(i32 %33)
%39 = call i32 @close(i32 %19)
%40 = icmp sgt i64 %17, 0
br i1 %40, label %41, label %44
41: ; preds = %0
%42 = load i32, i32* @SIGKILL
%43 = call i32 @kill(i64 %17, i32 %42)
br label %44
44: ; preds = %41, %0
ret i32 0
}