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

/* Variables and functions */
void *AF_INET;
void *INADDR_ANY;
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 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;
  pid_t pid = 0;
  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);
  fd_null = open("/dev/null", O_WRONLY);
  connect(-1, (struct sockaddr *)&sin1, sizeof(sin1));
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)-1, sizeof(sin1));
  connect(s, (struct sockaddr *)&sin1, -1);
  connect(s, (struct sockaddr *)&sin1, 3);
  connect(fd_null, (struct sockaddr *)&sin1, sizeof(sin1));
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  connect(s, (struct sockaddr *)&sin1, sizeof(sin1));
  close(s);
  s = socket(PF_INET, SOCK_STREAM, 0);
  connect(s, (struct sockaddr *)&sin2, sizeof(sin2));
  connect(s, (struct sockaddr *)&sin4, sizeof(sin4));
  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    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0x2e3a(%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    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   10a0 <start_server@plt>
mov    %rax,-0x60(%rbp)
mov    0x2df2(%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    0x2dbd(%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)
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
lea    0xda9(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
lea    -0x28(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xffffffff,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x3,%edx
call   1090 <connect@plt>
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
mov    0x2cc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmpq   $0x0,-0x60(%rbp)
jle    136a <main+0x1da>
mov    -0x60(%rbp),%rdi
mov    0x2c5d(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2e43(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x30(%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,0x40(%rsp)
mov    0x2e00(%rip),%rbp
mov    0x0(%rbp),%rax
mov    %rax,0x38(%rsp)
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <start_server@plt>
mov    %rax,%r14
mov    (%r15),%eax
mov    %eax,0x18(%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    %rax,0x28(%rsp)
mov    0x0(%rbp),%rax
mov    %rax,0x20(%rsp)
movl   $0x2f,(%rsp)
movq   $0x0,0x10(%rsp)
mov    $0xafffefd,%edi
call   1050 <htonl@plt>
mov    %rax,0x8(%rsp)
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
lea    0xd9b(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r15d
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    0x2d42(%rip),%r12
mov    (%r12),%edi
mov    0x2d3f(%rip),%r13
mov    0x0(%r13),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
call   1090 <connect@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1090 <connect@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
lea    0x18(%rsp),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   1090 <connect@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
test   %r14,%r14
jle    135a <main+0x1ca>
mov    0x2c70(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <kill@plt>
xor    %eax,%eax
add    $0x48,%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.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
@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 i64
store i32 0, i32* %1
store i64 0, i64* %7
%8 = load i8*, i8** @AF_INET
%9 = ptrtoint i8* %8 to i32
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %9, i32* %10
%11 = call i32 (...) @getpid()
%12 = srem i32 %11, 32768
%13 = add nsw i32 %12, 11000
%14 = call i8* @htons(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i8* %14, i8** %15
%16 = load i8*, i8** @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i8* %16, i8** %18
%19 = call i64 @start_server(%struct.sockaddr_in* %4)
store i64 %19, i64* %7
%20 = load i8*, i8** @AF_INET
%21 = ptrtoint i8* %20 to i32
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %21, i32* %22
%23 = call i32 (...) @getpid()
%24 = srem i32 %23, 32768
%25 = add nsw i32 %24, 10000
%26 = call i8* @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i8* %26, i8** %27
%28 = load i8*, i8** @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i8* %28, i8** %30
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 47, i32* %31
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* null, i8** %32
%33 = call i8* @htonl(i32 184549117)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i8* %33, i8** %35
%36 = load i32, i32* @O_WRONLY
%37 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %36)
store i32 %37, i32* %3
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%39 = call i32 @connect(i32 -1, %struct.sockaddr* %38, i32 24)
%40 = load i32, i32* @PF_INET
%41 = load i32, i32* @SOCK_STREAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
store i32 %42, i32* %2
%43 = load i32, i32* %2
%44 = call i32 @connect(i32 %43, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32 24)
%45 = load i32, i32* %2
%46 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%47 = call i32 @connect(i32 %45, %struct.sockaddr* %46, i32 -1)
%48 = load i32, i32* %2
%49 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%50 = call i32 @connect(i32 %48, %struct.sockaddr* %49, i32 3)
%51 = load i32, i32* %3
%52 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%53 = call i32 @connect(i32 %51, %struct.sockaddr* %52, i32 24)
%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 = load i32, i32* %2
%58 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%59 = call i32 @connect(i32 %57, %struct.sockaddr* %58, i32 24)
%60 = load i32, i32* %2
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* @PF_INET
%63 = load i32, i32* @SOCK_STREAM
%64 = call i32 @socket(i32 %62, i32 %63, i32 0)
store i32 %64, i32* %2
%65 = load i32, i32* %2
%66 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%67 = call i32 @connect(i32 %65, %struct.sockaddr* %66, i32 24)
%68 = load i32, i32* %2
%69 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%70 = call i32 @connect(i32 %68, %struct.sockaddr* %69, i32 24)
%71 = load i32, i32* %2
%72 = call i32 @close(i32 %71)
%73 = load i32, i32* %3
%74 = call i32 @close(i32 %73)
%75 = load i64, i64* %7
%76 = icmp sgt i64 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %0
%78 = load i64, i64* %7
%79 = load i32, i32* @SIGKILL
%80 = call i32 @kill(i64 %78, i32 %79)
br label %81
81: ; preds = %77, %0
ret i32 0
}

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