#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 uint8_t;
struct ip6_ext {
  int ip6e_len;
};
struct cmsghdr {
  scalar_t__ cmsg_level;
  scalar_t__ cmsg_type;
  scalar_t__ cmsg_len;
};

/* Variables and functions */
int /*<<< orphan*/ CCMSG_DATA(struct cmsghdr const *);
scalar_t__ CMSG_SPACE(int);
scalar_t__ IPPROTO_IPV6;
scalar_t__ IPV6_DSTOPTS;
scalar_t__ IPV6_HOPOPTS;
int /*<<< orphan*/ _DIAGASSERT(int /*<<< orphan*/);
struct ip6_ext *__UNCONST(int /*<<< orphan*/);
int ip6optlen(int *, int *);
int inet6_option_find(const struct cmsghdr *cmsg, uint8_t **tptrp, int type) {
  struct ip6_ext *ip6e;
  int hdrlen, optlen;
  uint8_t *optp, *lim;
  _DIAGASSERT(cmsg != NULL);
  _DIAGASSERT(tptrp != NULL);
  if (cmsg->cmsg_level != IPPROTO_IPV6 ||
      (cmsg->cmsg_type != IPV6_HOPOPTS && cmsg->cmsg_type != IPV6_DSTOPTS))
    return (-1);
  if (cmsg->cmsg_len < CMSG_SPACE(sizeof(struct ip6_ext)))
    return (-1);
  ip6e = __UNCONST(CCMSG_DATA(cmsg));
  hdrlen = (ip6e->ip6e_len + 1) << 3;
  if (cmsg->cmsg_len < CMSG_SPACE(hdrlen))
    return (-1);
  lim = (uint8_t *)(void *)ip6e + hdrlen;
  if (*tptrp == NULL)
    *tptrp = (uint8_t *)(void *)(ip6e + 1);
  else {
    if ((optlen = ip6optlen(*tptrp, lim)) == 0)
      return (-1);
    *tptrp = *tptrp + optlen;
  }
  for (optp = *tptrp; optp < lim; optp += optlen) {
    if (*optp == type) {
      *tptrp = optp;
      return (0);
    }
    if ((optlen = ip6optlen(optp, lim)) == 0)
      return (-1);
  }
  *tptrp = NULL;
  return (-1);
}


x86 assembly (clang, -O0):
<inet6_option_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <_DIAGASSERT@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <_DIAGASSERT@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%rax
jne    11ce <inet6_option_find+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%rax
je     11da <inet6_option_find+0x8a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%rax
je     11da <inet6_option_find+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    136a <inet6_option_find+0x21a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    $0x4,%edi
call   1030 <CMSG_SPACE@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jge    120c <inet6_option_find+0xbc>
movl   $0xffffffff,-0x4(%rbp)
jmp    136a <inet6_option_find+0x21a>
mov    -0x10(%rbp),%rdi
call   1040 <CCMSG_DATA@plt>
mov    %eax,%edi
call   1070 <__UNCONST@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
shl    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <CMSG_SPACE@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jge    125f <inet6_option_find+0x10f>
movl   $0xffffffff,-0x4(%rbp)
jmp    136a <inet6_option_find+0x21a>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1294 <inet6_option_find+0x144>
mov    -0x28(%rbp),%rcx
add    $0x4,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12d5 <inet6_option_find+0x185>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <ip6optlen@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jne    12bc <inet6_option_find+0x16c>
movl   $0xffffffff,-0x4(%rbp)
jmp    136a <inet6_option_find+0x21a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    1358 <inet6_option_find+0x208>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jne    1314 <inet6_option_find+0x1c4>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    136a <inet6_option_find+0x21a>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <ip6optlen@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jne    1339 <inet6_option_find+0x1e9>
movl   $0xffffffff,-0x4(%rbp)
jmp    136a <inet6_option_find+0x21a>
jmp    133e <inet6_option_find+0x1ee>
mov    -0x30(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    12e0 <inet6_option_find+0x190>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_option_find>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1050 <_DIAGASSERT@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <_DIAGASSERT@plt>
mov    0x0(%rbp),%rax
mov    0x2e45(%rip),%rcx
mov    $0xffffffff,%r12d
cmp    (%rcx),%rax
jne    126a <inet6_option_find+0x11a>
mov    0x8(%rbp),%rax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%rax
je     11ba <inet6_option_find+0x6a>
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
jne    126a <inet6_option_find+0x11a>
mov    0x10(%rbp),%rbx
mov    $0x4,%edi
call   1030 <CMSG_SPACE@plt>
cmp    %rax,%rbx
jl     126a <inet6_option_find+0x11a>
mov    %rbp,%rdi
call   1040 <CCMSG_DATA@plt>
mov    %eax,%edi
call   1070 <__UNCONST@plt>
mov    %rax,%rbx
mov    (%rax),%eax
lea    0x8(,%rax,8),%r13d
mov    0x10(%rbp),%rbp
mov    %r13d,%edi
call   1030 <CMSG_SPACE@plt>
cmp    %rax,%rbp
jl     126a <inet6_option_find+0x11a>
movslq %r13d,%rax
lea    (%rbx,%rax,4),%rbp
mov    (%r15),%rdi
test   %rdi,%rdi
je     1225 <inet6_option_find+0xd5>
mov    %rbp,%rsi
call   1060 <ip6optlen@plt>
test   %eax,%eax
je     126a <inet6_option_find+0x11a>
movslq %eax,%rbx
shl    $0x2,%rbx
add    (%r15),%rbx
jmp    1229 <inet6_option_find+0xd9>
add    $0x4,%rbx
mov    %rbx,(%r15)
cmp    %rbp,%rbx
jae    125f <inet6_option_find+0x10f>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r14d,(%rbx)
je     1267 <inet6_option_find+0x117>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <ip6optlen@plt>
test   %eax,%eax
je     127c <inet6_option_find+0x12c>
cltq
lea    (%rbx,%rax,4),%rbx
cmp    %rbp,%rbx
jb     1240 <inet6_option_find+0xf0>
mov    $0xffffffff,%r12d
xor    %ebx,%ebx
mov    %rbx,(%r15)
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%r12d
jmp    126a <inet6_option_find+0x11a>

LLVM IR (-O0):
%struct.cmsghdr = type { i64, i64, i64 }
%struct.ip6_ext = type { i32 }
@IPPROTO_IPV6 = global i64 0
@IPV6_HOPOPTS = global i64 0
@IPV6_DSTOPTS = global i64 0
define i32 @inet6_option_find(%struct.cmsghdr* %0, i32** %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.cmsghdr*
%6 = alloca i32**
%7 = alloca i32
%8 = alloca %struct.ip6_ext*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
store %struct.cmsghdr* %0, %struct.cmsghdr** %5
store i32** %1, i32*** %6
store i32 %2, i32* %7
%13 = load %struct.cmsghdr*, %struct.cmsghdr** %5
%14 = icmp ne %struct.cmsghdr* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @_DIAGASSERT(i32 %15)
%17 = load i32**, i32*** %6
%18 = icmp ne i32** %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @_DIAGASSERT(i32 %19)
%21 = load %struct.cmsghdr*, %struct.cmsghdr** %5
%22 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* @IPPROTO_IPV6
%25 = icmp ne i64 %23, %24
br i1 %25, label %38, label %26
26: ; preds = %3
%27 = load %struct.cmsghdr*, %struct.cmsghdr** %5
%28 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = load i64, i64* @IPV6_HOPOPTS
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %26
%33 = load %struct.cmsghdr*, %struct.cmsghdr** %5
%34 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %33, i32 0, i32 1
%35 = load i64, i64* %34
%36 = load i64, i64* @IPV6_DSTOPTS
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %32, %3
store i32 -1, i32* %4
br label %121
39: ; preds = %32, %26
%40 = load %struct.cmsghdr*, %struct.cmsghdr** %5
%41 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %40, i32 0, i32 2
%42 = load i64, i64* %41
%43 = call i64 @CMSG_SPACE(i32 4)
%44 = icmp slt i64 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %39
store i32 -1, i32* %4
br label %121
46: ; preds = %39
%47 = load %struct.cmsghdr*, %struct.cmsghdr** %5
%48 = call i32 @CCMSG_DATA(%struct.cmsghdr* %47)
%49 = call %struct.ip6_ext* @__UNCONST(i32 %48)
store %struct.ip6_ext* %49, %struct.ip6_ext** %8
%50 = load %struct.ip6_ext*, %struct.ip6_ext** %8
%51 = getelementptr inbounds %struct.ip6_ext, %struct.ip6_ext* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = add nsw i32 %52, 1
%54 = shl i32 %53, 3
store i32 %54, i32* %9
%55 = load %struct.cmsghdr*, %struct.cmsghdr** %5
%56 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %55, i32 0, i32 2
%57 = load i64, i64* %56
%58 = load i32, i32* %9
%59 = call i64 @CMSG_SPACE(i32 %58)
%60 = icmp slt i64 %57, %59
br i1 %60, label %61, label %62
61: ; preds = %46
store i32 -1, i32* %4
br label %121
62: ; preds = %46
%63 = load %struct.ip6_ext*, %struct.ip6_ext** %8
%64 = bitcast %struct.ip6_ext* %63 to i8*
%65 = bitcast i8* %64 to i32*
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
store i32* %68, i32** %12
%69 = load i32**, i32*** %6
%70 = load i32*, i32** %69
%71 = icmp eq i32* %70, null
br i1 %71, label %72, label %78
72: ; preds = %62
%73 = load %struct.ip6_ext*, %struct.ip6_ext** %8
%74 = getelementptr inbounds %struct.ip6_ext, %struct.ip6_ext* %73, i64 1
%75 = bitcast %struct.ip6_ext* %74 to i8*
%76 = bitcast i8* %75 to i32*
%77 = load i32**, i32*** %6
store i32* %76, i32** %77
br label %92
78: ; preds = %62
%79 = load i32**, i32*** %6
%80 = load i32*, i32** %79
%81 = load i32*, i32** %12
%82 = call i32 @ip6optlen(i32* %80, i32* %81)
store i32 %82, i32* %10
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %78
store i32 -1, i32* %4
br label %121
85: ; preds = %78
%86 = load i32**, i32*** %6
%87 = load i32*, i32** %86
%88 = load i32, i32* %10
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
%91 = load i32**, i32*** %6
store i32* %90, i32** %91
br label %92
92: ; preds = %85, %72
%93 = load i32**, i32*** %6
%94 = load i32*, i32** %93
store i32* %94, i32** %11
br label %95
95: ; preds = %114, %92
%96 = load i32*, i32** %11
%97 = load i32*, i32** %12
%98 = icmp ult i32* %96, %97
br i1 %98, label %99, label %119
99: ; preds = %95
%100 = load i32*, i32** %11
%101 = load i32, i32* %100
%102 = load i32, i32* %7
%103 = icmp eq i32 %101, %102
br i1 %103, label %104, label %107
104: ; preds = %99
%105 = load i32*, i32** %11
%106 = load i32**, i32*** %6
store i32* %105, i32** %106
store i32 0, i32* %4
br label %121
107: ; preds = %99
%108 = load i32*, i32** %11
%109 = load i32*, i32** %12
%110 = call i32 @ip6optlen(i32* %108, i32* %109)
store i32 %110, i32* %10
%111 = icmp eq i32 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %107
store i32 -1, i32* %4
br label %121
113: ; preds = %107
br label %114
114: ; preds = %113
%115 = load i32, i32* %10
%116 = load i32*, i32** %11
%117 = sext i32 %115 to i64
%118 = getelementptr inbounds i32, i32* %116, i64 %117
store i32* %118, i32** %11
br label %95
119: ; preds = %95
%120 = load i32**, i32*** %6
store i32* null, i32** %120
store i32 -1, i32* %4
br label %121
121: ; preds = %119, %112, %104, %84, %61, %45, %38
%122 = load i32, i32* %4
ret i32 %122
}

LLVM IR (-O2):
%struct.cmsghdr = type { i64, i64, i64 }
%struct.ip6_ext = type { i32 }
@IPPROTO_IPV6 = global i64 0
@IPV6_HOPOPTS = global i64 0
@IPV6_DSTOPTS = global i64 0
define i32 @inet6_option_find(%struct.cmsghdr* %0, i32** %1, i32 %2) {
%4 = icmp ne %struct.cmsghdr* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @_DIAGASSERT(i32 %5)
%7 = icmp ne i32** %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @_DIAGASSERT(i32 %8)
%10 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %0, i64 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @IPPROTO_IPV6
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %68
14: ; preds = %3
%15 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %0, i64 0, i32 1
%16 = load i64, i64* %15
%17 = load i64, i64* @IPV6_HOPOPTS
%18 = icmp eq i64 %16, %17
%19 = load i64, i64* @IPV6_DSTOPTS
%20 = icmp eq i64 %16, %19
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %22, label %68
22: ; preds = %14
%23 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %0, i64 0, i32 2
%24 = load i64, i64* %23
%25 = tail call i64 @CMSG_SPACE(i32 4)
%26 = icmp slt i64 %24, %25
br i1 %26, label %68, label %27
27: ; preds = %22
%28 = tail call i32 @CCMSG_DATA(%struct.cmsghdr* %0)
%29 = tail call %struct.ip6_ext* @__UNCONST(i32 %28)
%30 = getelementptr inbounds %struct.ip6_ext, %struct.ip6_ext* %29, i64 0, i32 0
%31 = load i32, i32* %30
%32 = shl i32 %31, 3
%33 = add i32 %32, 8
%34 = load i64, i64* %23
%35 = tail call i64 @CMSG_SPACE(i32 %33)
%36 = icmp slt i64 %34, %35
br i1 %36, label %68, label %37
37: ; preds = %27
%38 = sext i32 %33 to i64
%39 = getelementptr inbounds %struct.ip6_ext, %struct.ip6_ext* %29, i64 %38, i32 0
%40 = load i32*, i32** %1
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = getelementptr inbounds %struct.ip6_ext, %struct.ip6_ext* %29, i64 1, i32 0
br label %51
44: ; preds = %37
%45 = tail call i32 @ip6optlen(i32* %40, i32* %39)
%46 = icmp eq i32 %45, 0
br i1 %46, label %68, label %47
47: ; preds = %44
%48 = load i32*, i32** %1
%49 = sext i32 %45 to i64
%50 = getelementptr inbounds i32, i32* %48, i64 %49
br label %51
51: ; preds = %47, %42
%52 = phi i32* [ %50, %47 ], [ %43, %42 ]
store i32* %52, i32** %1
%53 = icmp ult i32* %52, %39
br i1 %53, label %54, label %65
54: ; preds = %51, %61
%55 = phi i32* [ %63, %61 ], [ %52, %51 ]
%56 = load i32, i32* %55
%57 = icmp eq i32 %56, %2
br i1 %57, label %65, label %58
58: ; preds = %54
%59 = tail call i32 @ip6optlen(i32* %55, i32* %39)
%60 = icmp eq i32 %59, 0
br i1 %60, label %68, label %61
61: ; preds = %58
%62 = sext i32 %59 to i64
%63 = getelementptr inbounds i32, i32* %55, i64 %62
%64 = icmp ult i32* %63, %39
br i1 %64, label %54, label %65
65: ; preds = %61, %54, %51
%66 = phi i32* [ null, %51 ], [ %55, %54 ], [ null, %61 ]
%67 = phi i32 [ -1, %51 ], [ 0, %54 ], [ -1, %61 ]
store i32* %66, i32** %1
br label %68
68: ; preds = %58, %65, %44, %27, %22, %3, %14
%69 = phi i32 [ -1, %14 ], [ -1, %3 ], [ -1, %22 ], [ -1, %27 ], [ -1, %44 ], [ %67, %65 ], [ -1, %58 ]
ret i32 %69
}