#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 */
typedef int /*<<< orphan*/ sun1;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  scalar_t__ sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sin3;
typedef int /*<<< orphan*/ sin2;
typedef int /*<<< orphan*/ sin1;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ AF_UNIX;
void *INADDR_ANY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int getpid();
void *htonl(int);
scalar_t__ htons(int);
int open(char *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int main() {
  char buf[1024];
  int sock_inet_stream;
  int sock_local;
  int fd_null;
  struct sockaddr_in sin1, sin2, sin3;
  struct sockaddr_un sun1;
  sin1.sin_family = AF_INET;
  sin1.sin_port = htons((getpid() % 32768) + 10000);
  sin1.sin_addr.s_addr = INADDR_ANY;
  sin2.sin_family = AF_INET;
  sin2.sin_port = 0;
  sin2.sin_addr.s_addr = INADDR_ANY;
  sin3.sin_family = AF_INET;
  sin3.sin_port = 0;
  sin3.sin_addr.s_addr = htonl(0x0AFFFEFD);
  sun1.sun_family = AF_UNIX;
  strncpy(sun1.sun_path, ".", sizeof(sun1.sun_path));
  sock_inet_stream = socket(PF_INET, SOCK_STREAM, 0);
  sock_local = socket(PF_LOCAL, SOCK_STREAM, 0);
  fd_null = open("/dev/null", O_WRONLY);
  bind(-1, (struct sockaddr *)&sin1, sizeof(sin1));
  bind(sock_inet_stream, (struct sockaddr *)-1, sizeof(struct sockaddr_in));
  bind(sock_inet_stream, (struct sockaddr *)&sin1, 3);
  bind(fd_null, (struct sockaddr *)&sin1, sizeof(sin1));
  bind(sock_inet_stream, (struct sockaddr *)&sin2, sizeof(sin2));
  bind(sock_local, (struct sockaddr *)&sun1, sizeof(sun1));
  bind(sock_inet_stream, (struct sockaddr *)&sin3, sizeof(sin3));
  bind(sock_inet_stream, (struct sockaddr *)&sin1, -1);
  close(sock_inet_stream);
  close(sock_local);
  close(fd_null);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x428(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    $0x8000,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x2710,%edi
call   1050 <htons@plt>
mov    %rax,-0x430(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x438(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x440(%rbp)
movq   $0x0,-0x448(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x450(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x458(%rbp)
movq   $0x0,-0x460(%rbp)
mov    $0xafffefd,%edi
call   1060 <htonl@plt>
mov    %rax,-0x468(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x46c(%rbp)
mov    -0x470(%rbp),%edi
lea    0xdb3(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x414(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x418(%rbp)
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
lea    0xd5d(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x41c(%rbp)
lea    -0x438(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    -0x414(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    -0x414(%rbp),%edi
lea    -0x438(%rbp),%rsi
mov    $0x3,%edx
call   1080 <bind@plt>
mov    -0x41c(%rbp),%edi
lea    -0x438(%rbp),%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    -0x414(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    -0x418(%rbp),%edi
lea    -0x470(%rbp),%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
mov    -0x414(%rbp),%edi
lea    -0x468(%rbp),%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    -0x414(%rbp),%edi
lea    -0x438(%rbp),%rsi
mov    $0xffffffff,%edx
call   1080 <bind@plt>
mov    -0x414(%rbp),%edi
call   1070 <close@plt>
mov    -0x418(%rbp),%edi
call   1070 <close@plt>
mov    -0x41c(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2e57(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x50(%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    $0x2710,%edi
call   1050 <htons@plt>
mov    %rax,0x48(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x40(%rsp)
mov    (%rbx),%rcx
mov    %rcx,0x38(%rsp)
movq   $0x0,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rcx,0x20(%rsp)
movq   $0x0,0x18(%rsp)
mov    $0xafffefd,%edi
call   1060 <htonl@plt>
mov    %rax,0x10(%rsp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xde4(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    0x2d92(%rip),%rbp
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%r14d
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
lea    0xd9a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r15d
lea    0x40(%rsp),%rbp
mov    $0xffffffff,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    %ebx,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x3,%edx
call   1080 <bind@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
lea    0x28(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   1080 <bind@plt>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
call   1080 <bind@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
call   1080 <bind@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i8* null
@AF_UNIX = global i32 0
@.str = [2 x i8] c".\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@PF_LOCAL = global i32 0
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_un
store i32 0, i32* %1
%10 = load i8*, i8** @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %10, i8** %11
%12 = call i32 (...) @getpid()
%13 = srem i32 %12, 32768
%14 = add nsw i32 %13, 10000
%15 = call i64 @htons(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i64 %15, i64* %16
%17 = load i8*, i8** @INADDR_ANY
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i8* %17, i8** %19
%20 = load i8*, i8** @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %20, i8** %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i64 0, i64* %22
%23 = load i8*, i8** @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i8* %23, i8** %25
%26 = load i8*, i8** @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i8* %26, i8** %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i64 0, i64* %28
%29 = call i8* @htonl(i32 184549117)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i8* %29, i8** %31
%32 = load i32, i32* @AF_UNIX
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @strncpy(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 4)
%37 = load i32, i32* @PF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = call i32 @socket(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %3
%40 = load i32, i32* @PF_LOCAL
%41 = load i32, i32* @SOCK_STREAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
store i32 %42, i32* %4
%43 = load i32, i32* @O_WRONLY
%44 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %43)
store i32 %44, i32* %5
%45 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%46 = call i32 @bind(i32 -1, %struct.sockaddr* %45, i32 24)
%47 = load i32, i32* %3
%48 = call i32 @bind(i32 %47, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32 24)
%49 = load i32, i32* %3
%50 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%51 = call i32 @bind(i32 %49, %struct.sockaddr* %50, i32 3)
%52 = load i32, i32* %5
%53 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%54 = call i32 @bind(i32 %52, %struct.sockaddr* %53, i32 24)
%55 = load i32, i32* %3
%56 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%57 = call i32 @bind(i32 %55, %struct.sockaddr* %56, i32 24)
%58 = load i32, i32* %4
%59 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%60 = call i32 @bind(i32 %58, %struct.sockaddr* %59, i32 8)
%61 = load i32, i32* %3
%62 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%63 = call i32 @bind(i32 %61, %struct.sockaddr* %62, i32 24)
%64 = load i32, i32* %3
%65 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%66 = call i32 @bind(i32 %64, %struct.sockaddr* %65, i32 -1)
%67 = load i32, i32* %3
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* %4
%70 = call i32 @close(i32 %69)
%71 = load i32, i32* %5
%72 = call i32 @close(i32 %71)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i8* null
@AF_UNIX = global i32 0
@.str = [2 x i8] c".\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@PF_LOCAL = global i32 0
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_un
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_un* %4 to i8*
%9 = load i8*, i8** @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %9, i8** %10
%11 = tail call i32 (...) @getpid()
%12 = srem i32 %11, 32768
%13 = add nsw i32 %12, 10000
%14 = tail call i64 @htons(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i64 %14, i64* %15
%16 = load i8*, i8** @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i8* %16, i8** %17
%18 = load i8*, i8** @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %18, i8** %19
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i64 0, i64* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i8* %16, i8** %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %18, i8** %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i64 0, i64* %23
%24 = tail call i8* @htonl(i32 184549117)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i8* %24, i8** %25
%26 = load i32, i32* @AF_UNIX
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i32 %26, i32* %27
%28 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 4)
%29 = load i32, i32* @PF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = tail call i32 @socket(i32 %29, i32 %30, i32 0)
%32 = load i32, i32* @PF_LOCAL
%33 = load i32, i32* @SOCK_STREAM
%34 = tail call i32 @socket(i32 %32, i32 %33, i32 0)
%35 = load i32, i32* @O_WRONLY
%36 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%38 = call i32 @bind(i32 -1, %struct.sockaddr* %37, i32 24)
%39 = call i32 @bind(i32 %31, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32 24)
%40 = call i32 @bind(i32 %31, %struct.sockaddr* %37, i32 3)
%41 = call i32 @bind(i32 %36, %struct.sockaddr* %37, i32 24)
%42 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%43 = call i32 @bind(i32 %31, %struct.sockaddr* %42, i32 24)
%44 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%45 = call i32 @bind(i32 %34, %struct.sockaddr* %44, i32 8)
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%47 = call i32 @bind(i32 %31, %struct.sockaddr* %46, i32 24)
%48 = call i32 @bind(i32 %31, %struct.sockaddr* %37, i32 -1)
%49 = call i32 @close(i32 %31)
%50 = call i32 @close(i32 %34)
%51 = call i32 @close(i32 %36)
ret i32 0
}