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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_V6ONLY;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int _socket_set_option(int sfd) {
  int optval;
  optval = (1);
  if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) {
    return (-1);
  }
  optval = (0);
  if (setsockopt(sfd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)) < 0) {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<_socket_set_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ebc(%rip),%rax
mov    (%rax),%esi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    115c <_socket_set_option+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <_socket_set_option+0x94>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    119d <_socket_set_option+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <_socket_set_option+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_socket_set_option>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2ec2(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1178 <_socket_set_option+0x68>
movl   $0x0,0xc(%rsp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
sar    $0x3f,%rax
jmp    117d <_socket_set_option+0x6d>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
define i32 @_socket_set_option(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
%5 = load i32, i32* %3
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_REUSEADDR
%8 = call i64 @setsockopt(i32 %5, i32 %6, i32 %7, i32* %4, i32 4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %19
11: ; preds = %1
store i32 0, i32* %4
%12 = load i32, i32* %3
%13 = load i32, i32* @IPPROTO_IPV6
%14 = load i32, i32* @IPV6_V6ONLY
%15 = call i64 @setsockopt(i32 %12, i32 %13, i32 %14, i32* %4, i32 4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 -1, i32* %2
br label %19
18: ; preds = %11
store i32 0, i32* %2
br label %19
19: ; preds = %18, %17, %10
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
define i32 @_socket_set_option(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = load i32, i32* @SOL_SOCKET
%5 = load i32, i32* @SO_REUSEADDR
%6 = call i64 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %2, i32 4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %1
store i32 0, i32* %2
%9 = load i32, i32* @IPPROTO_IPV6
%10 = load i32, i32* @IPV6_V6ONLY
%11 = call i64 @setsockopt(i32 %0, i32 %9, i32 %10, i32* %2, i32 4)
%12 = ashr i64 %11, 63
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %8, %1
%15 = phi i32 [ -1, %1 ], [ %13, %8 ]
ret i32 %15
}