#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*/ MSG_OOB;
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*/ sendto(int, char *, int, int, struct sockaddr *, 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);
  sendto(-1, buf, sizeof(buf), 0, NULL, 0);
  sendto(fd_null, buf, sizeof(buf), MSG_DONTWAIT, NULL, 0);
  s = socket(PF_INET, SOCK_DGRAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  sendto(s, (void *)buf, sizeof(buf), MSG_OOB, (struct sockaddr *)&sin1,
         sizeof(sin1));
  sendto(s, (void *)-1, sizeof(buf), 0, (struct sockaddr *)&sin1, sizeof(sin1));
  sendto(s, (void *)buf, -1, 0, (struct sockaddr *)&sin1, sizeof(sin1));
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&sin1, sizeof(sin1));
  sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&sin1, -1);
  sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)-1, sizeof(sin1));
  sendto(s, buf, sizeof(buf), -1, (struct sockaddr *)&sin1, sizeof(sin1));
  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    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
lea    -0x18(%rbp),%rdi
call   10b0 <start_server@plt>
mov    %rax,-0x20(%rbp)
mov    0x2d6c(%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    %r9d,%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %r9d,%ecx
call   1050 <sendto@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    0x2d41(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%edx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
call   1050 <sendto@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    0x2d4d(%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    0x2d27(%rip),%rax
mov    (%rax),%ecx
lea    -0x18(%rbp),%r8
mov    $0x400,%edx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%r8
mov    $0xffffffffffffffff,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0xffffffff,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
mov    0x2c99(%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
lea    -0x18(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0xffffffff,%r9d
call   1050 <sendto@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0xffffffffffffffff,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x400,%edx
mov    $0xffffffff,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmpq   $0x0,-0x20(%rbp)
jle    13ef <main+0x24f>
mov    -0x20(%rbp),%rdi
mov    0x2bb0(%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    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    %rsp,%r12
mov    %r12,%rdi
call   10b0 <start_server@plt>
mov    %rax,%r14
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
lea    0xdd5(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r15d
lea    0x10(%rsp),%rbp
mov    $0xffffffff,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <sendto@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%ecx
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <sendto@plt>
mov    0x2d30(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%ecx
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x0(%r13),%edi
mov    0x2cb0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xffffffff,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0xffffffffffffffff,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
test   %r14,%r14
jle    13b6 <main+0x216>
mov    0x2bec(%rip),%rax
mov    (%rax),%esi
mov    %r14,%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
@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 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 @sendto(i32 -1, i8* %25, i32 1024, i32 0, %struct.sockaddr* null, 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 @sendto(i32 %27, i8* %28, i32 1024, i32 %29, %struct.sockaddr* null, i32 0)
%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 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* @MSG_OOB
%40 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%41 = call i32 @sendto(i32 %37, i8* %38, i32 1024, i32 %39, %struct.sockaddr* %40, i32 12)
%42 = load i32, i32* %2
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%44 = call i32 @sendto(i32 %42, i8* inttoptr (i64 -1 to i8*), i32 1024, i32 0, %struct.sockaddr* %43, i32 12)
%45 = load i32, i32* %2
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%47 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%48 = call i32 @sendto(i32 %45, i8* %46, i32 -1, i32 0, %struct.sockaddr* %47, i32 12)
%49 = load i32, i32* %2
%50 = call i32 @close(i32 %49)
%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 12)
%57 = load i32, i32* %2
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%59 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%60 = call i32 @sendto(i32 %57, i8* %58, i32 1024, i32 0, %struct.sockaddr* %59, i32 12)
%61 = load i32, i32* %2
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%63 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%64 = call i32 @sendto(i32 %61, i8* %62, i32 1024, i32 0, %struct.sockaddr* %63, i32 -1)
%65 = load i32, i32* %2
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%67 = call i32 @sendto(i32 %65, i8* %66, i32 1024, i32 0, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32 12)
%68 = load i32, i32* %2
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%70 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%71 = call i32 @sendto(i32 %68, i8* %69, i32 1024, i32 -1, %struct.sockaddr* %70, i32 12)
%72 = load i32, i32* %2
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %3
%75 = call i32 @close(i32 %74)
%76 = load i64, i64* %5
%77 = icmp sgt i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %0
%79 = load i64, i64* %5
%80 = load i32, i32* @SIGKILL
%81 = call i32 @kill(i64 %79, i32 %80)
br label %82
82: ; preds = %78, %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
@MSG_OOB = 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 @sendto(i32 -1, i8* %4, i32 1024, i32 0, %struct.sockaddr* null, i32 0)
%21 = load i32, i32* @MSG_DONTWAIT
%22 = call i32 @sendto(i32 %19, i8* %4, i32 1024, i32 %21, %struct.sockaddr* null, i32 0)
%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 = load i32, i32* @MSG_OOB
%29 = call i32 @sendto(i32 %25, i8* %4, i32 1024, i32 %28, %struct.sockaddr* %26, i32 12)
%30 = call i32 @sendto(i32 %25, i8* inttoptr (i64 -1 to i8*), i32 1024, i32 0, %struct.sockaddr* %26, i32 12)
%31 = call i32 @sendto(i32 %25, i8* %4, i32 -1, i32 0, %struct.sockaddr* %26, i32 12)
%32 = call i32 @close(i32 %25)
%33 = load i32, i32* @PF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
%36 = call i32 @connect(i32 %35, %struct.sockaddr* %26, i32 12)
%37 = call i32 @sendto(i32 %35, i8* %4, i32 1024, i32 0, %struct.sockaddr* %26, i32 12)
%38 = call i32 @sendto(i32 %35, i8* %4, i32 1024, i32 0, %struct.sockaddr* %26, i32 -1)
%39 = call i32 @sendto(i32 %35, i8* %4, i32 1024, i32 0, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32 12)
%40 = call i32 @sendto(i32 %35, i8* %4, i32 1024, i32 -1, %struct.sockaddr* %26, i32 12)
%41 = call i32 @close(i32 %35)
%42 = call i32 @close(i32 %19)
%43 = icmp sgt i64 %17, 0
br i1 %43, label %44, label %47
44: ; preds = %0
%45 = load i32, i32* @SIGKILL
%46 = call i32 @kill(i64 %17, i32 %45)
br label %47
47: ; preds = %44, %0
ret i32 0
}