#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 /*<<< orphan*/ memset(char *, char, int);
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);
  memset(buf, 'a', sizeof(buf));
  send(-1, buf, sizeof(buf), 0);
  memset(buf, 'b', sizeof(buf));
  send(fd_null, buf, sizeof(buf), MSG_DONTWAIT);
  s = socket(PF_INET, SOCK_DGRAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  memset(buf, 'c', sizeof(buf));
  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));
  memset(buf, 'd', sizeof(buf));
  send(s, buf, sizeof(buf), MSG_DONTWAIT);
  memset(buf, 'e', sizeof(buf));
  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    0x2e17(%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    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
lea    -0x18(%rbp),%rdi
call   10c0 <start_server@plt>
mov    %rax,-0x20(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0xdcb(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0xc(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x61,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x420(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x420(%rbp),%rdi
mov    $0x62,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    0x2d16(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%edx
call   1050 <send@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
lea    -0x420(%rbp),%rdi
mov    $0x63,%esi
mov    $0x400,%edx
call   1060 <memset@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   1070 <close@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
lea    -0x420(%rbp),%rdi
mov    $0x64,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    0x2c3f(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%edx
call   1050 <send@plt>
lea    -0x420(%rbp),%rdi
mov    $0x65,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
cmpq   $0x0,-0x20(%rbp)
jle    13d1 <main+0x221>
mov    -0x20(%rbp),%rdi
mov    0x2bd6(%rip),%rax
mov    (%rax),%esi
call   1090 <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    0x2e20(%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    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
mov    %rsp,%r15
mov    %r15,%rdi
call   10c0 <start_server@plt>
mov    %rax,%r14
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
lea    0xdc5(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x61,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rbx,%rdi
mov    $0x62,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%ecx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <send@plt>
mov    0x2d10(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
mov    %rbx,%rdi
mov    $0x63,%esi
mov    $0x400,%edx
call   1060 <memset@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   1070 <close@plt>
mov    0x0(%r13),%edi
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    0x2c66(%rip),%rax
mov    (%rax),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <send@plt>
mov    %rbx,%rdi
mov    $0x65,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r12d,%edi
call   1070 <close@plt>
test   %r14,%r14
jle    139e <main+0x1ee>
mov    0x2c0c(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <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 @memset(i8* %25, i8 signext 97, i32 1024)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = call i32 @send(i32 -1, i8* %27, i32 1024, i32 0)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i8 signext 98, i32 1024)
%31 = load i32, i32* %3
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = load i32, i32* @MSG_DONTWAIT
%34 = call i32 @send(i32 %31, i8* %32, i32 1024, i32 %33)
%35 = load i32, i32* @PF_INET
%36 = load i32, i32* @SOCK_DGRAM
%37 = call i32 @socket(i32 %35, i32 %36, i32 0)
store i32 %37, i32* %2
%38 = load i32, i32* %2
%39 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%40 = call i32 @connect(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i8 signext 99, i32 1024)
%43 = load i32, i32* %2
%44 = call i32 @send(i32 %43, i8* inttoptr (i64 -1 to i8*), i32 1024, i32 0)
%45 = load i32, i32* %2
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%47 = call i32 @send(i32 %45, i8* %46, i32 -1, i32 0)
%48 = load i32, i32* %2
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* @PF_INET
%51 = load i32, i32* @SOCK_STREAM
%52 = call i32 @socket(i32 %50, i32 %51, i32 0)
store i32 %52, i32* %2
%53 = load i32, i32* %2
%54 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%55 = call i32 @connect(i32 %53, %struct.sockaddr* %54, i32 12)
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i8 signext 100, i32 1024)
%58 = load i32, i32* %2
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%60 = load i32, i32* @MSG_DONTWAIT
%61 = call i32 @send(i32 %58, i8* %59, i32 1024, i32 %60)
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%63 = call i32 @memset(i8* %62, i8 signext 101, i32 1024)
%64 = load i32, i32* %2
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%66 = call i32 @send(i32 %64, i8* %65, i32 1024, i32 -1)
%67 = load i32, i32* %2
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* %3
%70 = call i32 @close(i32 %69)
%71 = load i64, i64* %5
%72 = icmp sgt i64 %71, 0
br i1 %72, label %73, label %77
73: ; preds = %0
%74 = load i64, i64* %5
%75 = load i32, i32* @SIGKILL
%76 = call i32 @kill(i64 %74, i32 %75)
br label %77
77: ; preds = %73, %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 @memset(i8* %4, i8 signext 97, i32 1024)
%21 = call i32 @send(i32 -1, i8* %4, i32 1024, i32 0)
%22 = call i32 @memset(i8* %4, i8 signext 98, i32 1024)
%23 = load i32, i32* @MSG_DONTWAIT
%24 = call i32 @send(i32 %19, i8* %4, i32 1024, i32 %23)
%25 = load i32, i32* @PF_INET
%26 = load i32, i32* @SOCK_DGRAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%29 = call i32 @connect(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = call i32 @memset(i8* %4, i8 signext 99, i32 1024)
%31 = call i32 @send(i32 %27, i8* inttoptr (i64 -1 to i8*), i32 1024, i32 0)
%32 = call i32 @send(i32 %27, i8* %4, i32 -1, i32 0)
%33 = call i32 @close(i32 %27)
%34 = load i32, i32* @PF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
%37 = call i32 @connect(i32 %36, %struct.sockaddr* %28, i32 12)
%38 = call i32 @memset(i8* %4, i8 signext 100, i32 1024)
%39 = load i32, i32* @MSG_DONTWAIT
%40 = call i32 @send(i32 %36, i8* %4, i32 1024, i32 %39)
%41 = call i32 @memset(i8* %4, i8 signext 101, i32 1024)
%42 = call i32 @send(i32 %36, i8* %4, i32 1024, i32 -1)
%43 = call i32 @close(i32 %36)
%44 = call i32 @close(i32 %19)
%45 = icmp sgt i64 %17, 0
br i1 %45, label %46, label %49
46: ; preds = %0
%47 = load i32, i32* @SIGKILL
%48 = call i32 @kill(i64 %17, i32 %47)
br label %49
49: ; preds = %46, %0
ret i32 0
}