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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_ICMPV6;
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_MULTICAST_HOPS;
int /*<<< orphan*/ IPV6_RECVHOPLIMIT;
int /*<<< orphan*/ IPV6_UNICAST_HOPS;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_DONTROUTE;
int /*<<< orphan*/ close(int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int create_rs_socket() {
  int fd = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
  int i;
  if (fd < 0)
    return -1;
  i = 1;
  if (setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &i, sizeof(int)) < 0) {
    close(fd);
    return -1;
  }
  i = 255;
  if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &i, sizeof(i)) < 0) {
    close(fd);
    return -1;
  }
  i = 255;
  if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &i, sizeof(i)) < 0) {
    close(fd);
    return -1;
  }
  i = 1;
  if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &i, sizeof(int)) < 0) {
    close(fd);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<create_rs_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1171 <create_rs_socket+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <create_rs_socket+0x16b>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11ba <create_rs_socket+0x8a>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <create_rs_socket+0x16b>
movl   $0xff,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1203 <create_rs_socket+0xd3>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <create_rs_socket+0x16b>
movl   $0xff,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    124c <create_rs_socket+0x11c>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <create_rs_socket+0x16b>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
mov    0x2d8a(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1295 <create_rs_socket+0x165>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <create_rs_socket+0x16b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_rs_socket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     122f <create_rs_socket+0xff>
mov    %eax,%ebp
movl   $0x1,0xc(%rsp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1228 <create_rs_socket+0xf8>
movl   $0xff,0xc(%rsp)
mov    0x2dfd(%rip),%r14
mov    (%r14),%esi
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1228 <create_rs_socket+0xf8>
movl   $0xff,0xc(%rsp)
mov    (%r14),%esi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1228 <create_rs_socket+0xf8>
movl   $0x1,0xc(%rsp)
mov    (%r14),%esi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1228 <create_rs_socket+0xf8>
mov    %ebp,%ebx
jmp    122f <create_rs_socket+0xff>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PF_INET6 = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMPV6 = global i32 0
@SOL_SOCKET = global i32 0
@SO_DONTROUTE = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_UNICAST_HOPS = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@IPV6_RECVHOPLIMIT = global i32 0
define i32 @create_rs_socket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @PF_INET6
%5 = load i32, i32* @SOCK_RAW
%6 = load i32, i32* @IPPROTO_ICMPV6
%7 = call i32 @socket(i32 %4, i32 %5, i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %49
11: ; preds = %0
store i32 1, i32* %3
%12 = load i32, i32* %2
%13 = load i32, i32* @SOL_SOCKET
%14 = load i32, i32* @SO_DONTROUTE
%15 = call i64 @setsockopt(i32 %12, i32 %13, i32 %14, i32* %3, i32 4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
store i32 -1, i32* %1
br label %49
20: ; preds = %11
store i32 255, i32* %3
%21 = load i32, i32* %2
%22 = load i32, i32* @IPPROTO_IPV6
%23 = load i32, i32* @IPV6_UNICAST_HOPS
%24 = call i64 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %3, i32 4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %1
br label %49
29: ; preds = %20
store i32 255, i32* %3
%30 = load i32, i32* %2
%31 = load i32, i32* @IPPROTO_IPV6
%32 = load i32, i32* @IPV6_MULTICAST_HOPS
%33 = call i64 @setsockopt(i32 %30, i32 %31, i32 %32, i32* %3, i32 4)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* %2
%37 = call i32 @close(i32 %36)
store i32 -1, i32* %1
br label %49
38: ; preds = %29
store i32 1, i32* %3
%39 = load i32, i32* %2
%40 = load i32, i32* @IPPROTO_IPV6
%41 = load i32, i32* @IPV6_RECVHOPLIMIT
%42 = call i64 @setsockopt(i32 %39, i32 %40, i32 %41, i32* %3, i32 4)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i32, i32* %2
%46 = call i32 @close(i32 %45)
store i32 -1, i32* %1
br label %49
47: ; preds = %38
%48 = load i32, i32* %2
store i32 %48, i32* %1
br label %49
49: ; preds = %47, %44, %35, %26, %17, %10
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@PF_INET6 = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMPV6 = global i32 0
@SOL_SOCKET = global i32 0
@SO_DONTROUTE = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_UNICAST_HOPS = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@IPV6_RECVHOPLIMIT = global i32 0
define i32 @create_rs_socket() {
%1 = alloca i32
%2 = load i32, i32* @PF_INET6
%3 = load i32, i32* @SOCK_RAW
%4 = load i32, i32* @IPPROTO_ICMPV6
%5 = tail call i32 @socket(i32 %2, i32 %3, i32 %4)
%6 = bitcast i32* %1 to i8*
%7 = icmp slt i32 %5, 0
br i1 %7, label %30, label %8
8: ; preds = %0
store i32 1, i32* %1
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_DONTROUTE
%11 = call i64 @setsockopt(i32 %5, i32 %9, i32 %10, i32* %1, i32 4)
%12 = icmp slt i64 %11, 0
br i1 %12, label %28, label %13
13: ; preds = %8
store i32 255, i32* %1
%14 = load i32, i32* @IPPROTO_IPV6
%15 = load i32, i32* @IPV6_UNICAST_HOPS
%16 = call i64 @setsockopt(i32 %5, i32 %14, i32 %15, i32* %1, i32 4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %13
store i32 255, i32* %1
%19 = load i32, i32* @IPPROTO_IPV6
%20 = load i32, i32* @IPV6_MULTICAST_HOPS
%21 = call i64 @setsockopt(i32 %5, i32 %19, i32 %20, i32* %1, i32 4)
%22 = icmp slt i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %18
store i32 1, i32* %1
%24 = load i32, i32* @IPPROTO_IPV6
%25 = load i32, i32* @IPV6_RECVHOPLIMIT
%26 = call i64 @setsockopt(i32 %5, i32 %24, i32 %25, i32* %1, i32 4)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23, %18, %13, %8
%29 = call i32 @close(i32 %5)
br label %30
30: ; preds = %28, %23, %0
%31 = phi i32 [ -1, %0 ], [ %5, %23 ], [ -1, %28 ]
ret i32 %31
}