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

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_MULTICAST_LOOP;
int /*<<< orphan*/ IP_MULTICAST_LOOP;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ log_message(int /*<<< orphan*/, char *, char *,
                               int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int if_setsockopt_mcast_loop(sa_family_t family, int *sd) {
  int ret;
  unsigned char loop = 0;
  int loopv6 = 0;
  if (*sd < 0)
    return -1;
  if (family == AF_INET)
    ret = setsockopt(*sd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));
  else
    ret = setsockopt(*sd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loopv6,
                     sizeof(loopv6));
  if (ret < 0) {
    log_message(LOG_INFO,
                "cant set IP%s_MULTICAST_LOOP IP option. errno=%d (%m)",
                (family == AF_INET) ? "" : "V6", errno);
    close(*sd);
    *sd = -1;
  }
  return *sd;
}


x86 assembly (clang, -O0):
<if_setsockopt_mcast_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1164 <if_setsockopt_mcast_loop+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    123e <if_setsockopt_mcast_loop+0x10e>
mov    -0x10(%rbp),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    11a9 <if_setsockopt_mcast_loop+0x79>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
lea    -0x1d(%rbp),%rcx
mov    $0x1,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
mov    %eax,-0x1c(%rbp)
jmp    11d5 <if_setsockopt_mcast_loop+0xa5>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1235 <if_setsockopt_mcast_loop+0x105>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
mov    0x2de5(%rip),%rax
mov    (%rax),%rsi
lea    0xe39(%rip),%rdx
lea    0xe31(%rip),%rax
cmp    %rsi,%rcx
cmove  %rax,%rdx
mov    0x2dae(%rip),%rax
mov    (%rax),%ecx
lea    0xde5(%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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<if_setsockopt_mcast_loop>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbp
movb   $0x0,0x3(%rsp)
movl   $0x0,0x4(%rsp)
mov    (%rsi),%edi
mov    $0xffffffff,%r14d
test   %edi,%edi
js     11f2 <if_setsockopt_mcast_loop+0xc2>
mov    %rsi,%rbx
mov    0x2e77(%rip),%r15
cmp    %rbp,(%r15)
jne    1185 <if_setsockopt_mcast_loop+0x55>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
lea    0x3(%rsp),%rcx
mov    $0x1,%r8d
jmp    11a2 <if_setsockopt_mcast_loop+0x72>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %eax,%eax
js     11b2 <if_setsockopt_mcast_loop+0x82>
mov    (%rbx),%r14d
jmp    11f2 <if_setsockopt_mcast_loop+0xc2>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
cmp    %rbp,(%r15)
lea    0xe70(%rip),%rax
lea    0xe6a(%rip),%rdx
cmove  %rax,%rdx
mov    0x2de9(%rip),%rax
mov    (%rax),%ecx
lea    0xe20(%rip),%rsi
call   1050 <log_message@plt>
mov    (%rbx),%edi
call   1040 <close@plt>
movl   $0xffffffff,(%rbx)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i64 0
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_MULTICAST_LOOP = global i32 0
@LOG_INFO = global i32 0
@.str = [54 x i8] c"cant set IP%s_MULTICAST_LOOP IP option. errno=%d (%m)\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"V6\00"
@errno = global i32 0
define i32 @if_setsockopt_mcast_loop(i64 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i64 %0, i64* %4
store i32* %1, i32** %5
store i8 0, i8* %7
store i32 0, i32* %8
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %48
13: ; preds = %2
%14 = load i64, i64* %4
%15 = load i64, i64* @AF_INET
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = load i32, i32* @IPPROTO_IP
%21 = load i32, i32* @IP_MULTICAST_LOOP
%22 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %19, i32 %20, i32 %21, i8* %7, i64 1)
store i32 %22, i32* %6
br label %29
23: ; preds = %13
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = load i32, i32* @IPPROTO_IPV6
%27 = load i32, i32* @IPV6_MULTICAST_LOOP
%28 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %25, i32 %26, i32 %27, i32* %8, i64 4)
store i32 %28, i32* %6
br label %29
29: ; preds = %23, %17
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %29
%33 = load i32, i32* @LOG_INFO
%34 = load i64, i64* %4
%35 = load i64, i64* @AF_INET
%36 = icmp eq i64 %34, %35
%37 = zext i1 %36 to i64
%38 = select i1 %36, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%39 = load i32, i32* @errno
%40 = call i32 @log_message(i32 %33, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %38, i32 %39)
%41 = load i32*, i32** %5
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = load i32*, i32** %5
store i32 -1, i32* %44
br label %45
45: ; preds = %32, %29
%46 = load i32*, i32** %5
%47 = load i32, i32* %46
store i32 %47, i32* %3
br label %48
48: ; preds = %45, %12
%49 = load i32, i32* %3
ret i32 %49
}

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