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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_MULTICAST_HOPS;
int /*<<< orphan*/ IPV6_UNICAST_HOPS;
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int set_hop_limit(int fd, int value) {
  return (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &value,
                     sizeof(value)) ||
          setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &value,
                     sizeof(value)))
             ? -1
             : 0;
}


x86 assembly (clang, -O0):
<set_hop_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
jne    1182 <set_hop_limit+0x72>
mov    -0x4(%rbp),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%dl
xor    %eax,%eax
mov    $0xffffffff,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_hop_limit>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %esi,0x4(%rsp)
mov    0x2eaf(%rip),%r14
mov    (%r14),%esi
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    116d <set_hop_limit+0x5d>
mov    (%r14),%esi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
neg    %rax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@IPPROTO_IPV6 = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@IPV6_UNICAST_HOPS = global i32 0
define i32 @set_hop_limit(i32 %0, i32 %1) {
%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* @IPPROTO_IPV6
%7 = load i32, i32* @IPV6_MULTICAST_HOPS
%8 = call i64 @setsockopt(i32 %5, i32 %6, i32 %7, i32* %4, i32 4)
%9 = icmp ne i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* %3
%12 = load i32, i32* @IPPROTO_IPV6
%13 = load i32, i32* @IPV6_UNICAST_HOPS
%14 = call i64 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %4, i32 4)
%15 = icmp ne i64 %14, 0
br label %16
16: ; preds = %10, %2
%17 = phi i1 [ true, %2 ], [ %15, %10 ]
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 -1, i32 0
ret i32 %19
}

LLVM IR (-O2):
@IPPROTO_IPV6 = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@IPV6_UNICAST_HOPS = global i32 0
define i32 @set_hop_limit(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = load i32, i32* @IPPROTO_IPV6
%5 = load i32, i32* @IPV6_MULTICAST_HOPS
%6 = call i64 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %3, i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @IPPROTO_IPV6
%10 = load i32, i32* @IPV6_UNICAST_HOPS
%11 = call i64 @setsockopt(i32 %0, i32 %9, i32 %10, i32* %3, i32 4)
%12 = icmp ne i64 %11, 0
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %8, %2
%15 = phi i32 [ -1, %2 ], [ %13, %8 ]
ret i32 %15
}