#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;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ sin1;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ accept4(int, struct sockaddr *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int getpid();
int /*<<< orphan*/ htons(int);
int open(char *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int s, fd_null;
  struct sockaddr_in sin1;
  socklen_t sinlen;
  sin1.sin_family = AF_INET;
  sin1.sin_port = htons((getpid() % 32768) + 11000);
  sin1.sin_addr.s_addr = INADDR_ANY;
  fd_null = open("/dev/null", O_WRONLY);
  accept4(-1, NULL, NULL, 0);
  accept4(fd_null, (struct sockaddr *)&sin1, &sinlen, 0);
  s = socket(PF_INET, SOCK_STREAM, 0);
  bind(s, (struct sockaddr *)&sin1, sizeof(sin1));
  accept4(s, (struct sockaddr *)-1, &sinlen, 0);
  accept4(s, (struct sockaddr *)&sin1, (socklen_t *)-1, 0);
  accept4(s, (struct sockaddr *)&sin1, (socklen_t *)&sinlen, 02000000);
  accept4(s, (struct sockaddr *)&sin1, (socklen_t *)&sinlen, -1);
  close(s);
  close(fd_null);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%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   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
mov    %rdx,%rsi
call   1040 <accept4@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <accept4@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
lea    -0x1c(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <accept4@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xffffffffffffffff,%rdx
xor    %ecx,%ecx
call   1040 <accept4@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x80000,%ecx
call   1040 <accept4@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0xffffffff,%ecx
call   1040 <accept4@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%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   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r14d
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <accept4@plt>
lea    0x8(%rsp),%rbx
lea    0x14(%rsp),%r15
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
call   1040 <accept4@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    %ebp,%edi
mov    $0xffffffffffffffff,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
call   1040 <accept4@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xffffffffffffffff,%rdx
xor    %ecx,%ecx
call   1040 <accept4@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0x80000,%ecx
call   1040 <accept4@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1040 <accept4@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
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.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
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %6, i32* %7
%8 = call i32 (...) @getpid()
%9 = srem i32 %8, 32768
%10 = add nsw i32 %9, 11000
%11 = call i32 @htons(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 %13, i32* %15
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %3
%18 = call i32 @accept4(i32 -1, %struct.sockaddr* null, i32* null, i32 0)
%19 = load i32, i32* %3
%20 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%21 = call i32 @accept4(i32 %19, %struct.sockaddr* %20, i32* %5, i32 0)
%22 = load i32, i32* @PF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%27 = call i32 @bind(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = load i32, i32* %2
%29 = call i32 @accept4(i32 %28, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32* %5, i32 0)
%30 = load i32, i32* %2
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call i32 @accept4(i32 %30, %struct.sockaddr* %31, i32* inttoptr (i64 -1 to i32*), i32 0)
%33 = load i32, i32* %2
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i32 @accept4(i32 %33, %struct.sockaddr* %34, i32* %5, i32 524288)
%36 = load i32, i32* %2
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = call i32 @accept4(i32 %36, %struct.sockaddr* %37, i32* %5, i32 -1)
%39 = load i32, i32* %2
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %3
%42 = call i32 @close(i32 %41)
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
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = bitcast i32* %2 to i8*
%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* @O_WRONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = tail call i32 @accept4(i32 -1, %struct.sockaddr* null, i32* null, i32 0)
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @accept4(i32 %15, %struct.sockaddr* %17, i32* %2, i32 0)
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = call i32 @bind(i32 %21, %struct.sockaddr* %17, i32 12)
%23 = call i32 @accept4(i32 %21, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32* %2, i32 0)
%24 = call i32 @accept4(i32 %21, %struct.sockaddr* %17, i32* inttoptr (i64 -1 to i32*), i32 0)
%25 = call i32 @accept4(i32 %21, %struct.sockaddr* %17, i32* %2, i32 524288)
%26 = call i32 @accept4(i32 %21, %struct.sockaddr* %17, i32* %2, i32 -1)
%27 = call i32 @close(i32 %21)
%28 = call i32 @close(i32 %15)
ret i32 0
}