#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;
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sin1;
typedef int /*<<< orphan*/ sin0;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getpeername(int, struct sockaddr *, int *);
int open(char *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int *);
int main() {
  int s;
  int fd_null;
  int sv[2];
  struct sockaddr_in sin0, sin1;
  socklen_t sinlen;
  sin0.sin_family = AF_INET;
  sin0.sin_port = 0;
  sin0.sin_addr.s_addr = INADDR_ANY;
  s = socket(PF_INET, SOCK_STREAM, 0);
  bind(s, (struct sockaddr *)&sin0, sizeof(sin0));
  fd_null = open("/dev/null", O_WRONLY);
  socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
  sinlen = sizeof(sin1);
  getpeername(-1, (struct sockaddr *)&sin1, &sinlen);
  getpeername(fd_null, (struct sockaddr *)&sin1, &sinlen);
  getpeername(s, (struct sockaddr *)&sin1, &sinlen);
  getpeername(sv[0], (struct sockaddr *)-1, &sinlen);
  getpeername(sv[0], (struct sockaddr *)&sin1, (socklen_t *)0);
  getpeername(sv[0], (struct sockaddr *)&sin1, (socklen_t *)-1);
  getpeername(sv[0], (struct sockaddr *)&sin1, &sinlen);
  close(s);
  close(fd_null);
  close(sv[0]);
  close(sv[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x18,%edx
call   1060 <bind@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rcx
xor    %edx,%edx
call   1050 <socketpair@plt>
movl   $0x18,-0x4c(%rbp)
lea    -0x48(%rbp),%rsi
mov    $0xffffffff,%edi
lea    -0x4c(%rbp),%rdx
call   1030 <getpeername@plt>
mov    -0xc(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1030 <getpeername@plt>
mov    -0x8(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1030 <getpeername@plt>
mov    -0x14(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
lea    -0x4c(%rbp),%rdx
call   1030 <getpeername@plt>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <getpeername@plt>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0xffffffffffffffff,%rdx
call   1030 <getpeername@plt>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1030 <getpeername@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    0x2e2b(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%r15d
lea    0x18(%rsp),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1060 <bind@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    0xe36(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
lea    0xc(%rsp),%rcx
xor    %edx,%edx
call   1050 <socketpair@plt>
movl   $0x18,0x14(%rsp)
lea    0x30(%rsp),%rbp
lea    0x14(%rsp),%rbx
mov    $0xffffffff,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <getpeername@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <getpeername@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <getpeername@plt>
mov    0xc(%rsp),%edi
mov    $0xffffffffffffffff,%rsi
mov    %rbx,%rdx
call   1030 <getpeername@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
xor    %edx,%edx
call   1030 <getpeername@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
mov    $0xffffffffffffffff,%rdx
call   1030 <getpeername@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <getpeername@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@PF_UNIX = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i64 0, i64* %10
%11 = load i32, i32* @INADDR_ANY
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%19 = call i32 @bind(i32 %17, %struct.sockaddr* %18, i32 24)
%20 = load i32, i32* @O_WRONLY
%21 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %3
%22 = load i32, i32* @PF_UNIX
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%25 = call i32 @socketpair(i32 %22, i32 %23, i32 0, i32* %24)
store i32 24, i32* %7
%26 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%27 = call i32 @getpeername(i32 -1, %struct.sockaddr* %26, i32* %7)
%28 = load i32, i32* %3
%29 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%30 = call i32 @getpeername(i32 %28, %struct.sockaddr* %29, i32* %7)
%31 = load i32, i32* %2
%32 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%33 = call i32 @getpeername(i32 %31, %struct.sockaddr* %32, i32* %7)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @getpeername(i32 %35, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32* %7)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%38 = load i32, i32* %37
%39 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%40 = call i32 @getpeername(i32 %38, %struct.sockaddr* %39, i32* null)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%42 = load i32, i32* %41
%43 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%44 = call i32 @getpeername(i32 %42, %struct.sockaddr* %43, i32* inttoptr (i64 -1 to i32*))
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%46 = load i32, i32* %45
%47 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%48 = call i32 @getpeername(i32 %46, %struct.sockaddr* %47, i32* %7)
%49 = load i32, i32* %2
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* %3
%52 = call i32 @close(i32 %51)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
ret i32 0
}

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