#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 */
struct sockaddr_in6 {
  int dummy;
};
struct msghdr {
  int msg_namelen;
  int msg_iovlen;
  char *msg_control;
  int msg_controllen;
  struct iovec *msg_iov;
  struct sockaddr_in6 *msg_name;
};
struct iovec {
  void *iov_base;
  size_t iov_len;
};
struct cmsghdr {
  scalar_t__ cmsg_level;
  scalar_t__ cmsg_type;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ cbuf;

/* Variables and functions */
scalar_t__ CMSG_DATA(struct cmsghdr *);
struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *);
struct cmsghdr *CMSG_NXTHDR(struct msghdr *, struct cmsghdr *);
int CMSG_SPACE(int);
scalar_t__ IPPROTO_IPV6;
scalar_t__ IPV6_HOPLIMIT;
int recvmsg(int, struct msghdr *, int);
ssize_t recvfromLL(int fd, void *buf, size_t len, int flags,
                   struct sockaddr_in6 *addr) {
  char cbuf[CMSG_SPACE(sizeof(int))];
  struct iovec iov = {.iov_base = buf, .iov_len = len};
  struct msghdr hdr = {.msg_name = addr,
                       .msg_namelen = sizeof(*addr),
                       .msg_iov = &iov,
                       .msg_iovlen = 1,
                       .msg_control = cbuf,
                       .msg_controllen = sizeof(cbuf)};
  struct cmsghdr *cmsg;
  ssize_t val = recvmsg(fd, &hdr, flags);
  if (val == -1)
    return val;
  for (cmsg = CMSG_FIRSTHDR(&hdr); cmsg != NULL;
       cmsg = CMSG_NXTHDR(&hdr, cmsg)) {
    if ((cmsg->cmsg_level == IPPROTO_IPV6) &&
        (cmsg->cmsg_type == IPV6_HOPLIMIT)) {
      int *data = (int *)CMSG_DATA(cmsg);
      if (255 != *data) {
        return 0;
      }
    }
  }
  return val;
}


x86 assembly (clang, -O0):
<recvfromLL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    $0x4,%edi
call   1040 <CMSG_SPACE@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdx
mov    %rdx,-0x48(%rbp)
mov    -0x18(%rbp),%rdx
mov    %rdx,-0x40(%rbp)
movl   $0x4,-0x70(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    %rcx,-0x68(%rbp)
mov    %eax,-0x60(%rbp)
lea    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    -0x70(%rbp),%rsi
call   1060 <recvmsg@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0xffffffff,-0x7c(%rbp)
jne    11fb <recvfromLL+0xab>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    12a6 <recvfromLL+0x156>
lea    -0x70(%rbp),%rdi
call   1070 <CMSG_FIRSTHDR@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1299 <recvfromLL+0x149>
mov    -0x78(%rbp),%rax
mov    (%rax),%rax
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%rax
jne    127e <recvfromLL+0x12e>
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
jne    127e <recvfromLL+0x12e>
mov    -0x78(%rbp),%rdi
call   1030 <CMSG_DATA@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rcx
mov    $0xff,%eax
cmp    (%rcx),%eax
je     1279 <recvfromLL+0x129>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    12a6 <recvfromLL+0x156>
jmp    127e <recvfromLL+0x12e>
jmp    1283 <recvfromLL+0x133>
mov    -0x78(%rbp),%rsi
lea    -0x70(%rbp),%rdi
call   1050 <CMSG_NXTHDR@plt>
mov    %rax,-0x78(%rbp)
jmp    1208 <recvfromLL+0xb8>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x80(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvfromLL>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r15
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%r12d
mov    $0x4,%edi
call   1040 <CMSG_SPACE@plt>
mov    %eax,%ecx
mov    %rsp,%rdx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rbx,-0x60(%rbp)
mov    %r13,-0x58(%rbp)
movabs $0x100000004,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rdx,-0x48(%rbp)
mov    %eax,-0x40(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    %r15,-0x30(%rbp)
lea    -0x50(%rbp),%rsi
mov    %r12d,%edi
mov    %r14d,%edx
call   1060 <recvmsg@plt>
cmp    $0xffffffff,%eax
je     123b <recvfromLL+0xeb>
mov    %eax,%r14d
lea    -0x50(%rbp),%rdi
call   1070 <CMSG_FIRSTHDR@plt>
test   %rax,%rax
je     1241 <recvfromLL+0xf1>
mov    %rax,%rbx
mov    0x2df3(%rip),%r12
mov    0x2dfc(%rip),%r13
lea    -0x50(%rbp),%r15
jmp    1213 <recvfromLL+0xc3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <CMSG_NXTHDR@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1241 <recvfromLL+0xf1>
mov    (%rbx),%rax
cmp    (%r12),%rax
jne    1200 <recvfromLL+0xb0>
mov    0x8(%rbx),%rax
cmp    0x0(%r13),%rax
jne    1200 <recvfromLL+0xb0>
mov    %rbx,%rdi
call   1030 <CMSG_DATA@plt>
cmpl   $0xff,(%rax)
je     1200 <recvfromLL+0xb0>
xor    %r14d,%r14d
jmp    1241 <recvfromLL+0xf1>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.iovec = type { i8*, i64 }
%struct.msghdr = type { i32, i32, i8*, i32, %struct.iovec*, %struct.sockaddr_in6* }
%struct.cmsghdr = type { i64, i64 }
@IPPROTO_IPV6 = global i64 0
@IPV6_HOPLIMIT = global i64 0
define i32 @recvfromLL(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr_in6* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca %struct.sockaddr_in6*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca %struct.iovec
%15 = alloca %struct.msghdr
%16 = alloca %struct.cmsghdr*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store %struct.sockaddr_in6* %4, %struct.sockaddr_in6** %11
%20 = call i32 @CMSG_SPACE(i32 4)
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %12
%23 = alloca i8, i64 %21
store i64 %21, i64* %13
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 0
%25 = load i8*, i8** %8
store i8* %25, i8** %24
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 1
%27 = load i64, i64* %9
store i64 %27, i64* %26
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 0
store i32 4, i32* %28
%29 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 1
store i32 1, i32* %29
%30 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 2
store i8* %23, i8** %30
%31 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 3
%32 = trunc i64 %21 to i32
store i32 %32, i32* %31
%33 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 4
store %struct.iovec* %14, %struct.iovec** %33
%34 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 5
%35 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %11
store %struct.sockaddr_in6* %35, %struct.sockaddr_in6** %34
%36 = load i32, i32* %7
%37 = load i32, i32* %10
%38 = call i32 @recvmsg(i32 %36, %struct.msghdr* %15, i32 %37)
store i32 %38, i32* %17
%39 = load i32, i32* %17
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %5
%42 = load i32, i32* %17
store i32 %42, i32* %6
store i32 1, i32* %18
br label %75
43: ; preds = %5
%44 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %15)
store %struct.cmsghdr* %44, %struct.cmsghdr** %16
br label %45
45: ; preds = %70, %43
%46 = load %struct.cmsghdr*, %struct.cmsghdr** %16
%47 = icmp ne %struct.cmsghdr* %46, null
br i1 %47, label %48, label %73
48: ; preds = %45
%49 = load %struct.cmsghdr*, %struct.cmsghdr** %16
%50 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %49, i32 0, i32 0
%51 = load i64, i64* %50
%52 = load i64, i64* @IPPROTO_IPV6
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %69
54: ; preds = %48
%55 = load %struct.cmsghdr*, %struct.cmsghdr** %16
%56 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %55, i32 0, i32 1
%57 = load i64, i64* %56
%58 = load i64, i64* @IPV6_HOPLIMIT
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %69
60: ; preds = %54
%61 = load %struct.cmsghdr*, %struct.cmsghdr** %16
%62 = call i64 @CMSG_DATA(%struct.cmsghdr* %61)
%63 = inttoptr i64 %62 to i32*
store i32* %63, i32** %19
%64 = load i32*, i32** %19
%65 = load i32, i32* %64
%66 = icmp ne i32 255, %65
br i1 %66, label %67, label %68
67: ; preds = %60
store i32 0, i32* %6
store i32 1, i32* %18
br label %75
68: ; preds = %60
br label %69
69: ; preds = %68, %54, %48
br label %70
70: ; preds = %69
%71 = load %struct.cmsghdr*, %struct.cmsghdr** %16
%72 = call %struct.cmsghdr* @CMSG_NXTHDR(%struct.msghdr* %15, %struct.cmsghdr* %71)
store %struct.cmsghdr* %72, %struct.cmsghdr** %16
br label %45
73: ; preds = %45
%74 = load i32, i32* %17
store i32 %74, i32* %6
store i32 1, i32* %18
br label %75
75: ; preds = %73, %67, %41
%76 = load i8*, i8** %12
%77 = load i32, i32* %6
ret i32 %77
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.iovec = type { i8*, i64 }
%struct.msghdr = type { i32, i32, i8*, i32, %struct.iovec*, %struct.sockaddr_in6* }
%struct.cmsghdr = type { i64, i64 }
@IPPROTO_IPV6 = global i64 0
@IPV6_HOPLIMIT = global i64 0
define i32 @recvfromLL(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr_in6* %4) {
%6 = alloca %struct.iovec
%7 = alloca %struct.msghdr
%8 = tail call i32 @CMSG_SPACE(i32 4)
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = bitcast %struct.iovec* %6 to i8*
%12 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 0
store i8* %1, i8** %12
%13 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 1
store i64 %2, i64* %13
%14 = bitcast %struct.msghdr* %7 to i8*
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 0
store i32 4, i32* %15
%16 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 1
store i32 1, i32* %16
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 2
store i8* %10, i8** %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 3
store i32 %8, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 4
store %struct.iovec* %6, %struct.iovec** %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 5
store %struct.sockaddr_in6* %4, %struct.sockaddr_in6** %20
%21 = call i32 @recvmsg(i32 %0, %struct.msghdr* %7, i32 %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %45, label %23
23: ; preds = %5
%24 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %7)
%25 = icmp eq %struct.cmsghdr* %24, null
br i1 %25, label %45, label %26
26: ; preds = %23, %42
%27 = phi %struct.cmsghdr* [ %43, %42 ], [ %24, %23 ]
%28 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %27, i64 0, i32 0
%29 = load i64, i64* %28
%30 = load i64, i64* @IPPROTO_IPV6
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %26
%33 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %27, i64 0, i32 1
%34 = load i64, i64* %33
%35 = load i64, i64* @IPV6_HOPLIMIT
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = call i64 @CMSG_DATA(%struct.cmsghdr* %27)
%39 = inttoptr i64 %38 to i32*
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 255
br i1 %41, label %42, label %45
42: ; preds = %26, %32, %37
%43 = call %struct.cmsghdr* @CMSG_NXTHDR(%struct.msghdr* %7, %struct.cmsghdr* %27)
%44 = icmp eq %struct.cmsghdr* %43, null
br i1 %44, label %45, label %26
45: ; preds = %37, %42, %23, %5
%46 = phi i32 [ -1, %5 ], [ %21, %23 ], [ 0, %37 ], [ %21, %42 ]
ret i32 %46
}