#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 */

/* Type definitions */
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ in6addr_any;
int w_bind(int, struct sockaddr *, int);
int w_bind_local6(int sockfd, unsigned short port) {
  struct sockaddr_in6 addr;
  addr.sin6_family = AF_INET6;
  addr.sin6_addr = in6addr_any;
  addr.sin6_port = htons(port);
  return w_bind(sockfd, (struct sockaddr *)&addr, sizeof(addr));
}


x86 assembly (clang, -O0):
<w_bind_local6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movzwl -0x6(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1030 <w_bind@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<w_bind_local6>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %esi,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1030 <w_bind@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@in6addr_any = global i32 0
define i32 @w_bind_local6(i32 %0, i16 zeroext %1) {
%3 = alloca i32
%4 = alloca i16
%5 = alloca %struct.sockaddr_in6
store i32 %0, i32* %3
store i16 %1, i16* %4
%6 = load i32, i32* @AF_INET6
%7 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i32 0, i32 2
store i32 %6, i32* %7
%8 = load i32, i32* @in6addr_any
%9 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i32 0, i32 1
store i32 %8, i32* %9
%10 = load i16, i16* %4
%11 = call i32 @htons(i16 zeroext %10)
%12 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i32 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* %3
%14 = bitcast %struct.sockaddr_in6* %5 to %struct.sockaddr*
%15 = call i32 @w_bind(i32 %13, %struct.sockaddr* %14, i32 12)
ret i32 %15
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@in6addr_any = global i32 0
define i32 @w_bind_local6(i32 %0, i16 zeroext %1) {
%3 = alloca %struct.sockaddr_in6
%4 = bitcast %struct.sockaddr_in6* %3 to i8*
%5 = load i32, i32* @AF_INET6
%6 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 2
store i32 %5, i32* %6
%7 = load i32, i32* @in6addr_any
%8 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 1
store i32 %7, i32* %8
%9 = tail call i32 @htons(i16 zeroext %1)
%10 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 0
store i32 %9, i32* %10
%11 = bitcast %struct.sockaddr_in6* %3 to %struct.sockaddr*
%12 = call i32 @w_bind(i32 %0, %struct.sockaddr* %11, i32 12)
ret i32 %12
}