#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 */
typedef int /*<<< orphan*/ yes;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_V6ONLY;
int /*<<< orphan*/ anetSetError(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int anetV6Only(char *err, int s) {
  int yes = 1;
  if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) == -1) {
    anetSetError(err, "setsockopt: %s", strerror(errno));
    close(s);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<anetV6Only>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11bf <anetV6Only+0x7f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe5a(%rip),%rsi
call   1050 <anetSetError@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <anetV6Only+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetV6Only>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
movl   $0x1,0x4(%rsp)
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11a9 <anetV6Only+0x69>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe6d(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1050 <anetSetError@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
@.str = [15 x i8] c"setsockopt: %s\00"
@errno = global i32 0
define i32 @anetV6Only(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %6
%7 = load i32, i32* %5
%8 = load i32, i32* @IPPROTO_IPV6
%9 = load i32, i32* @IPV6_V6ONLY
%10 = call i32 @setsockopt(i32 %7, i32 %8, i32 %9, i32* %6, i32 4)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @anetSetError(i8* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %5
%18 = call i32 @close(i32 %17)
store i32 -1, i32* %3
br label %20
19: ; preds = %2
store i32 0, i32* %3
br label %20
20: ; preds = %19, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
@.str = [15 x i8] c"setsockopt: %s\00"
@errno = global i32 0
define i32 @anetV6Only(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%5 = load i32, i32* @IPPROTO_IPV6
%6 = load i32, i32* @IPV6_V6ONLY
%7 = call i32 @setsockopt(i32 %1, i32 %5, i32 %6, i32* %3, i32 4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 @anetSetError(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @close(i32 %1)
br label %14
14: ; preds = %2, %9
%15 = phi i32 [ -1, %9 ], [ 0, %2 ]
ret i32 %15
}