#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_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ null;

/* Variables and functions */
int AF_INET6;
scalar_t__ IN6_IS_ADDR_UNSPECIFIED(int /*<<< orphan*/ *);
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_V6ONLY;
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
void check_ipv6_only(int family, struct sockaddr *addr, int fd) {
  if ((family == AF_INET6) &&
      IN6_IS_ADDR_UNSPECIFIED(&(((struct sockaddr_in6 *)addr)->sin6_addr))) {
    int null = 0;
    setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &null, sizeof(null));
  }
}


x86 assembly (clang, -O0):
<check_ipv6_only>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eac(%rip),%rcx
cmp    (%rcx),%eax
jne    1182 <check_ipv6_only+0x62>
mov    -0x10(%rbp),%rdi
call   1040 <IN6_IS_ADDR_UNSPECIFIED@plt>
cmp    $0x0,%rax
je     1182 <check_ipv6_only+0x62>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_ipv6_only>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ebc(%rip),%rax
cmp    %edi,(%rax)
jne    116b <check_ipv6_only+0x4b>
mov    %edx,%ebx
mov    %rsi,%rdi
call   1040 <IN6_IS_ADDR_UNSPECIFIED@plt>
test   %rax,%rax
je     116b <check_ipv6_only+0x4b>
movl   $0x0,0xc(%rsp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET6 = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
define void @check_ipv6_only(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i32, i32* @AF_INET6
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load %struct.sockaddr*, %struct.sockaddr** %5
%13 = bitcast %struct.sockaddr* %12 to %struct.sockaddr_in6*
%14 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %13, i32 0, i32 0
%15 = call i64 @IN6_IS_ADDR_UNSPECIFIED(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %11
store i32 0, i32* %7
%18 = load i32, i32* %6
%19 = load i32, i32* @IPPROTO_IPV6
%20 = load i32, i32* @IPV6_V6ONLY
%21 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i32* %7, i32 4)
br label %22
22: ; preds = %17, %11, %3
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
define void @check_ipv6_only(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = load i32, i32* @AF_INET6
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = getelementptr %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%9 = tail call i64 @IN6_IS_ADDR_UNSPECIFIED(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%13 = load i32, i32* @IPPROTO_IPV6
%14 = load i32, i32* @IPV6_V6ONLY
%15 = call i32 @setsockopt(i32 %2, i32 %13, i32 %14, i32* %4, i32 4)
br label %16
16: ; preds = %11, %7, %3
ret void
}