#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 scalar_t__ sa_family_t;
typedef int /*<<< orphan*/ hops;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_MULTICAST_HOPS;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ log_message(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int if_setsockopt_mcast_hops(sa_family_t family, int *sd) {
  int ret;
  int hops = 255;
  if (*sd < 0 || family == AF_INET)
    return -1;
  ret = setsockopt(*sd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops, sizeof(hops));
  if (ret < 0) {
    log_message(LOG_INFO,
                "cant set IPV6_MULTICAST_HOPS IP option. errno=%d (%m)", errno);
    close(*sd);
    *sd = -1;
  }
  return *sd;
}


x86 assembly (clang, -O0):
<if_setsockopt_mcast_hops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xff,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jl     1168 <if_setsockopt_mcast_hops+0x38>
mov    -0x10(%rbp),%rax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <if_setsockopt_mcast_hops+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <if_setsockopt_mcast_hops+0xb4>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11db <if_setsockopt_mcast_hops+0xab>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
lea    0xe3f(%rip),%rsi
call   1050 <log_message@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<if_setsockopt_mcast_hops>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rax
movl   $0xff,0x4(%rsp)
mov    (%rsi),%edi
mov    $0xffffffff,%ebp
test   %edi,%edi
js     11ad <if_setsockopt_mcast_hops+0x7d>
mov    0x2e98(%rip),%rcx
cmp    %rax,(%rcx)
je     11ad <if_setsockopt_mcast_hops+0x7d>
mov    %rsi,%rbx
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     1182 <if_setsockopt_mcast_hops+0x52>
mov    (%rbx),%ebp
jmp    11ad <if_setsockopt_mcast_hops+0x7d>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
lea    0xe65(%rip),%rsi
call   1050 <log_message@plt>
mov    (%rbx),%edi
call   1040 <close@plt>
movl   $0xffffffff,(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i64 0
@IPPROTO_IPV6 = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@LOG_INFO = global i32 0
@.str = [54 x i8] c"cant set IPV6_MULTICAST_HOPS IP option. errno=%d (%m)\00"
@errno = global i32 0
define i32 @if_setsockopt_mcast_hops(i64 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %4
store i32* %1, i32** %5
store i32 255, i32* %7
%8 = load i32*, i32** %5
%9 = load i32, i32* %8
%10 = icmp slt i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i64, i64* %4
%13 = load i64, i64* @AF_INET
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11, %2
store i32 -1, i32* %3
br label %35
16: ; preds = %11
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = load i32, i32* @IPPROTO_IPV6
%20 = load i32, i32* @IPV6_MULTICAST_HOPS
%21 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i32* %7, i32 4)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %16
%25 = load i32, i32* @LOG_INFO
%26 = load i32, i32* @errno
%27 = call i32 @log_message(i32 %25, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = load i32*, i32** %5
store i32 -1, i32* %31
br label %32
32: ; preds = %24, %16
%33 = load i32*, i32** %5
%34 = load i32, i32* %33
store i32 %34, i32* %3
br label %35
35: ; preds = %32, %15
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@AF_INET = global i64 0
@IPPROTO_IPV6 = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@LOG_INFO = global i32 0
@.str = [54 x i8] c"cant set IPV6_MULTICAST_HOPS IP option. errno=%d (%m)\00"
@errno = global i32 0
define i32 @if_setsockopt_mcast_hops(i64 %0, i32* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 255, i32* %3
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %7, %0
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %23, label %10
10: ; preds = %2
%11 = load i32, i32* @IPPROTO_IPV6
%12 = load i32, i32* @IPV6_MULTICAST_HOPS
%13 = call i32 @setsockopt(i32 %5, i32 %11, i32 %12, i32* %3, i32 4)
%14 = icmp slt i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = load i32, i32* %1
br label %23
17: ; preds = %10
%18 = load i32, i32* @LOG_INFO
%19 = load i32, i32* @errno
%20 = call i32 @log_message(i32 %18, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %1
%22 = call i32 @close(i32 %21)
store i32 -1, i32* %1
br label %23
23: ; preds = %17, %15, %2
%24 = phi i32 [ -1, %2 ], [ %16, %15 ], [ -1, %17 ]
ret i32 %24
}