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

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ IPV6_RECVHOPLIMIT;
int /*<<< orphan*/ IP_RECVTTL;
int /*<<< orphan*/ SOL_IP;
int /*<<< orphan*/ SOL_IPV6;
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int use_recv_ttl(int af, int sk) {
  int n = 1;
  if (af == AF_INET) {
    if (setsockopt(sk, SOL_IP, IP_RECVTTL, &n, sizeof(n)) < 0)
      do {
        perror("setsockopt IP_RECVTTL");
        return -1;
      } while (0);
  } else if (af == AF_INET6) {
    if (setsockopt(sk, SOL_IPV6, IPV6_RECVHOPLIMIT, &n, sizeof(n)) < 0)
      do {
        perror("setsockopt IPV6_RECVHOPLIMIT");
        return -1;
      } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<use_recv_ttl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%eax
jne    1197 <use_recv_ttl+0x77>
mov    -0xc(%rbp),%edi
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1192 <use_recv_ttl+0x72>
jmp    117a <use_recv_ttl+0x5a>
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <use_recv_ttl+0xe5>
jmp    11fe <use_recv_ttl+0xde>
mov    -0x8(%rbp),%eax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
jne    11f9 <use_recv_ttl+0xd9>
mov    -0xc(%rbp),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11f4 <use_recv_ttl+0xd4>
jmp    11dc <use_recv_ttl+0xbc>
lea    0xe33(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <use_recv_ttl+0xe5>
jmp    11f9 <use_recv_ttl+0xd9>
jmp    11fe <use_recv_ttl+0xde>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<use_recv_ttl>:
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2e94(%rip),%rax
cmp    %edi,(%rax)
jne    116e <use_recv_ttl+0x4e>
mov    0x2eb9(%rip),%rax
mov    (%rax),%eax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%edx
lea    0xc(%rsp),%rcx
mov    %esi,%edi
mov    %eax,%esi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    11a6 <use_recv_ttl+0x86>
lea    0xe94(%rip),%rdi
jmp    11b5 <use_recv_ttl+0x95>
mov    0x2e4b(%rip),%rax
xor    %ebx,%ebx
cmp    %edi,(%rax)
jne    11a6 <use_recv_ttl+0x86>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    0x2e55(%rip),%rcx
mov    (%rcx),%edx
lea    0xc(%rsp),%rcx
mov    %esi,%edi
mov    %eax,%esi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     11ae <use_recv_ttl+0x8e>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe61(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11a6 <use_recv_ttl+0x86>

LLVM IR (-O0):
@AF_INET = global i32 0
@SOL_IP = global i32 0
@IP_RECVTTL = global i32 0
@.str = [22 x i8] c"setsockopt IP_RECVTTL\00"
@AF_INET6 = global i32 0
@SOL_IPV6 = global i32 0
@IPV6_RECVHOPLIMIT = global i32 0
@.str.1 = [29 x i8] c"setsockopt IPV6_RECVHOPLIMIT\00"
define i32 @use_recv_ttl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 1, i32* %6
%7 = load i32, i32* %4
%8 = load i32, i32* @AF_INET
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i32, i32* %5
%12 = load i32, i32* @SOL_IP
%13 = load i32, i32* @IP_RECVTTL
%14 = call i64 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %6, i32 4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
br label %17
17: ; preds = %16
%18 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
19: ; No predecessors!
br label %20
20: ; preds = %19, %10
br label %37
21: ; preds = %2
%22 = load i32, i32* %4
%23 = load i32, i32* @AF_INET6
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i32, i32* %5
%27 = load i32, i32* @SOL_IPV6
%28 = load i32, i32* @IPV6_RECVHOPLIMIT
%29 = call i64 @setsockopt(i32 %26, i32 %27, i32 %28, i32* %6, i32 4)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
34: ; No predecessors!
br label %35
35: ; preds = %34, %25
br label %36
36: ; preds = %35, %21
br label %37
37: ; preds = %36, %20
store i32 0, i32* %3
br label %38
38: ; preds = %37, %32, %17
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOL_IP = global i32 0
@IP_RECVTTL = global i32 0
@.str = [22 x i8] c"setsockopt IP_RECVTTL\00"
@AF_INET6 = global i32 0
@SOL_IPV6 = global i32 0
@IPV6_RECVHOPLIMIT = global i32 0
@.str.1 = [29 x i8] c"setsockopt IPV6_RECVHOPLIMIT\00"
define i32 @use_recv_ttl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%5 = load i32, i32* @AF_INET
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @SOL_IP
%9 = load i32, i32* @IP_RECVTTL
%10 = call i64 @setsockopt(i32 %1, i32 %8, i32 %9, i32* %3, i32 4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %20, label %23
12: ; preds = %2
%13 = load i32, i32* @AF_INET6
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32, i32* @SOL_IPV6
%17 = load i32, i32* @IPV6_RECVHOPLIMIT
%18 = call i64 @setsockopt(i32 %1, i32 %16, i32 %17, i32* %3, i32 4)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15, %7
%21 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), %15 ]
%22 = call i32 @perror(i8* %21)
br label %23
23: ; preds = %20, %7, %15, %12
%24 = phi i32 [ 0, %12 ], [ 0, %15 ], [ 0, %7 ], [ -1, %20 ]
ret i32 %24
}