#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*/ SOCK_STREAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getsockname(int, struct sockaddr *, int *);
int open(char *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sock_stream;
  int fd_null;
  struct sockaddr_in sin0, sin1;
  socklen_t sinlen;
  sin0.sin_family = AF_INET;
  sin0.sin_port = 0;
  sin0.sin_addr.s_addr = INADDR_ANY;
  sinlen = sizeof(sin1);
  sock_stream = socket(PF_INET, SOCK_STREAM, 0);
  bind(sock_stream, (struct sockaddr *)&sin0, sizeof(sin0));
  fd_null = open("/dev/null", O_WRONLY);
  getsockname(-1, (struct sockaddr *)&sin1, &sinlen);
  getsockname(fd_null, (struct sockaddr *)&sin1, &sinlen);
  getsockname(sock_stream, (struct sockaddr *)-1, &sinlen);
  getsockname(sock_stream, (struct sockaddr *)&sin1, (socklen_t *)-1);
  getsockname(sock_stream, (struct sockaddr *)&sin1, (socklen_t *)&sinlen);
  close(sock_stream);
  close(fd_null);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movl   $0x18,-0x44(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1040 <bind@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
lea    0xe3d(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
lea    -0x40(%rbp),%rsi
mov    $0xffffffff,%edi
lea    -0x44(%rbp),%rdx
call   1060 <getsockname@plt>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1060 <getsockname@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
lea    -0x44(%rbp),%rdx
call   1060 <getsockname@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xffffffffffffffff,%rdx
call   1060 <getsockname@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1060 <getsockname@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    -0xc(%rbp),%edi
call   1030 <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    $0x38,%rsp
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movl   $0x18,0x4(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1040 <bind@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r14d
lea    0x20(%rsp),%rbp
lea    0x4(%rsp),%r15
mov    $0xffffffff,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1060 <getsockname@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1060 <getsockname@plt>
mov    %ebx,%edi
mov    $0xffffffffffffffff,%rsi
mov    %r15,%rdx
call   1060 <getsockname@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xffffffffffffffff,%rdx
call   1060 <getsockname@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1060 <getsockname@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    %r14d,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x38,%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
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i64 0, i64* %9
%10 = load i32, i32* @INADDR_ANY
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 0
store i32 %10, i32* %12
store i32 24, i32* %6
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = bitcast %struct.sockaddr_in* %4 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)
store i32 %20, i32* %3
%21 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%22 = call i32 @getsockname(i32 -1, %struct.sockaddr* %21, i32* %6)
%23 = load i32, i32* %3
%24 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%25 = call i32 @getsockname(i32 %23, %struct.sockaddr* %24, i32* %6)
%26 = load i32, i32* %2
%27 = call i32 @getsockname(i32 %26, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32* %6)
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%30 = call i32 @getsockname(i32 %28, %struct.sockaddr* %29, i32* inttoptr (i64 -1 to i32*))
%31 = load i32, i32* %2
%32 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%33 = call i32 @getsockname(i32 %31, %struct.sockaddr* %32, i32* %6)
%34 = load i32, i32* %2
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
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
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i64 0, i64* %9
%10 = load i32, i32* @INADDR_ANY
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %10, i32* %11
store i32 24, i32* %3
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%16 = call i32 @bind(i32 %14, %struct.sockaddr* %15, i32 24)
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%20 = call i32 @getsockname(i32 -1, %struct.sockaddr* %19, i32* %3)
%21 = call i32 @getsockname(i32 %18, %struct.sockaddr* %19, i32* %3)
%22 = call i32 @getsockname(i32 %14, %struct.sockaddr* inttoptr (i64 -1 to %struct.sockaddr*), i32* %3)
%23 = call i32 @getsockname(i32 %14, %struct.sockaddr* %19, i32* inttoptr (i64 -1 to i32*))
%24 = call i32 @getsockname(i32 %14, %struct.sockaddr* %19, i32* %3)
%25 = call i32 @close(i32 %14)
%26 = call i32 @close(i32 %18)
ret i32 0
}