#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 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;
};
struct msghdr {
  int msg_namelen;
  int msg_iovlen;
  scalar_t__ msg_flags;
  scalar_t__ msg_controllen;
  int /*<<< orphan*/ *msg_control;
  struct iovec *msg_iov;
  struct sockaddr_in *msg_name;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
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 */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int MSG_DONTWAIT;
int MSG_OOB;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIGKILL;
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*/ sendmsg(int, struct msghdr *, int);
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, from;
  pid_t pid = 0;
  char buf[1024];
  fd_set rdfds;
  struct msghdr msgdat;
  struct iovec iov;
  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);
  fromlen = sizeof(from);
  iov.iov_base = buf;
  iov.iov_len = sizeof(buf);
  msgdat.msg_name = &from;
  msgdat.msg_namelen = fromlen;
  msgdat.msg_iov = &iov;
  msgdat.msg_iovlen = 1;
  msgdat.msg_control = NULL;
  msgdat.msg_controllen = 0;
  msgdat.msg_flags = 0;
  fd_null = open("/dev/null", O_WRONLY);
  sendmsg(-1, &msgdat, 0);
  sendmsg(fd_null, &msgdat, MSG_DONTWAIT);
  s = socket(PF_INET, SOCK_DGRAM, 0);
  sendmsg(s, &msgdat, MSG_OOB);
  sendmsg(s, (struct msghdr *)-1, 0);
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  sendmsg(s, &msgdat, -1);
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  sendmsg(s, &msgdat, MSG_DONTWAIT);
  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    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    $0x8000,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x2af8,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   10a0 <start_server@plt>
mov    %rax,-0x30(%rbp)
movl   $0xc,-0x47c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x478(%rbp)
movl   $0x400,-0x470(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x47c(%rbp),%eax
mov    %eax,-0x468(%rbp)
lea    -0x478(%rbp),%rax
mov    %rax,-0x448(%rbp)
movl   $0x1,-0x464(%rbp)
movq   $0x0,-0x450(%rbp)
movq   $0x0,-0x458(%rbp)
movq   $0x0,-0x460(%rbp)
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
lea    0xd90(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%edi
lea    -0x468(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    -0xc(%rbp),%edi
mov    0x2d1b(%rip),%rax
mov    (%rax),%edx
lea    -0x468(%rbp),%rsi
call   1030 <sendmsg@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d0f(%rip),%rax
mov    (%rax),%edx
lea    -0x468(%rbp),%rsi
call   1030 <sendmsg@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
lea    -0x468(%rbp),%rsi
mov    $0xffffffff,%edx
call   1030 <sendmsg@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
mov    0x2c77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
mov    0x2c40(%rip),%rax
mov    (%rax),%edx
lea    -0x468(%rbp),%rsi
call   1030 <sendmsg@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmpq   $0x0,-0x30(%rbp)
jle    13ab <main+0x21b>
mov    -0x30(%rbp),%rdi
mov    0x2c04(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
xor    %eax,%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xor    %eax,%eax
call   1040 <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   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   10a0 <start_server@plt>
mov    %rax,0x18(%rsp)
lea    0x70(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x400,0x28(%rsp)
lea    0x60(%rsp),%rax
mov    %rax,0x58(%rsp)
movabs $0x10000000c,%rax
mov    %rax,0x30(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x50(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x38(%rsp)
movq   $0x0,0x48(%rsp)
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
lea    0xdb1(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r12d
lea    0x30(%rsp),%rbx
mov    $0xffffffff,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1030 <sendmsg@plt>
mov    0x2d32(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <sendmsg@plt>
mov    %ebp,%edi
mov    $0xffffffffffffffff,%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x0(%r13),%edi
mov    0x2cef(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
call   1030 <sendmsg@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x0(%r13),%edi
mov    (%r14),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <sendmsg@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
jle    135b <main+0x1cb>
mov    0x2c54(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
xor    %eax,%eax
add    $0x478,%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.msghdr = type { i32, i32, i64, i64, i32*, %struct.iovec*, %struct.sockaddr_in* }
%struct.iovec = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = 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
@MSG_OOB = 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 i64
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca %struct.msghdr
%10 = alloca %struct.iovec
%11 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %6
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %12, i32* %13
%14 = call i32 (...) @getpid()
%15 = srem i32 %14, 32768
%16 = add nsw i32 %15, 11000
%17 = call i32 @htons(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i64 @start_server(%struct.sockaddr_in* %4)
store i64 %22, i64* %6
store i32 12, i32* %11
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %10, i32 0, i32 0
store i8* %23, i8** %24
%25 = getelementptr inbounds %struct.iovec, %struct.iovec* %10, i32 0, i32 1
store i32 1024, i32* %25
%26 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 6
store %struct.sockaddr_in* %5, %struct.sockaddr_in** %26
%27 = load i32, i32* %11
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 0
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 5
store %struct.iovec* %10, %struct.iovec** %29
%30 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 1
store i32 1, i32* %30
%31 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 4
store i32* null, i32** %31
%32 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 3
store i64 0, i64* %32
%33 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 2
store i64 0, i64* %33
%34 = load i32, i32* @O_WRONLY
%35 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %34)
store i32 %35, i32* %3
%36 = call i32 @sendmsg(i32 -1, %struct.msghdr* %9, i32 0)
%37 = load i32, i32* %3
%38 = load i32, i32* @MSG_DONTWAIT
%39 = call i32 @sendmsg(i32 %37, %struct.msghdr* %9, i32 %38)
%40 = load i32, i32* @PF_INET
%41 = load i32, i32* @SOCK_DGRAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
store i32 %42, i32* %2
%43 = load i32, i32* %2
%44 = load i32, i32* @MSG_OOB
%45 = call i32 @sendmsg(i32 %43, %struct.msghdr* %9, i32 %44)
%46 = load i32, i32* %2
%47 = call i32 @sendmsg(i32 %46, %struct.msghdr* inttoptr (i64 -1 to %struct.msghdr*), 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 = load i32, i32* %2
%57 = call i32 @sendmsg(i32 %56, %struct.msghdr* %9, i32 -1)
%58 = load i32, i32* %2
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* @PF_INET
%61 = load i32, i32* @SOCK_STREAM
%62 = call i32 @socket(i32 %60, i32 %61, i32 0)
store i32 %62, i32* %2
%63 = load i32, i32* %2
%64 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%65 = call i32 @connect(i32 %63, %struct.sockaddr* %64, i32 12)
%66 = load i32, i32* %2
%67 = load i32, i32* @MSG_DONTWAIT
%68 = call i32 @sendmsg(i32 %66, %struct.msghdr* %9, i32 %67)
%69 = load i32, i32* %2
%70 = call i32 @close(i32 %69)
%71 = load i32, i32* %3
%72 = call i32 @close(i32 %71)
%73 = load i64, i64* %6
%74 = icmp sgt i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %0
%76 = load i64, i64* %6
%77 = load i32, i32* @SIGKILL
%78 = call i32 @kill(i64 %76, i32 %77)
br label %79
79: ; preds = %75, %0
ret i32 0
}

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