#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 cmsghdr {
  int cmsg_type;
  int /*<<< orphan*/ cmsg_len;
  int /*<<< orphan*/ cmsg_level;
};

/* Variables and functions */
int /*<<< orphan*/ CMSG_LEN(int /*<<< orphan*/);
int /*<<< orphan*/ IPPROTO_IPV6;
int IPV6_DSTOPTS;
int IPV6_HOPOPTS;
int inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) {
  struct cmsghdr *ch = (struct cmsghdr *)bp;
  if (!((type) == IPV6_HOPOPTS || (type) == 22) &&
      !((type) == IPV6_DSTOPTS || (type) == 23))
    return (-1);
  ch->cmsg_level = IPPROTO_IPV6;
  ch->cmsg_type = type;
  ch->cmsg_len = CMSG_LEN(0);
  *cmsgp = ch;
  return (0);
}


x86 assembly (clang, -O0):
<inet6_option_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2eb3(%rip),%rcx
cmp    (%rcx),%eax
je     116f <inet6_option_init+0x5f>
cmpl   $0x16,-0x1c(%rbp)
je     116f <inet6_option_init+0x5f>
mov    -0x1c(%rbp),%eax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%eax
je     116f <inet6_option_init+0x5f>
cmpl   $0x17,-0x1c(%rbp)
je     116f <inet6_option_init+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <inet6_option_init+0x9a>
mov    0x2e5a(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
xor    %edi,%edi
call   1030 <CMSG_LEN@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_option_init>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
cmp    $0x16,%edx
je     113f <inet6_option_init+0x2f>
mov    0x2ec2(%rip),%rax
cmp    %edx,(%rax)
je     113f <inet6_option_init+0x2f>
cmp    $0x17,%edx
je     113f <inet6_option_init+0x2f>
mov    0x2ea2(%rip),%rax
mov    $0xffffffff,%ebp
cmp    %edx,(%rax)
jne    115c <inet6_option_init+0x4c>
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    %edx,(%rbx)
xor    %ebp,%ebp
xor    %edi,%edi
call   1030 <CMSG_LEN@plt>
mov    %eax,0x4(%rbx)
mov    %rbx,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.cmsghdr = type { i32, i32, i32 }
@IPV6_HOPOPTS = global i32 0
@IPV6_DSTOPTS = global i32 0
@IPPROTO_IPV6 = global i32 0
define i32 @inet6_option_init(i8* %0, %struct.cmsghdr** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.cmsghdr**
%7 = alloca i32
%8 = alloca %struct.cmsghdr*
store i8* %0, i8** %5
store %struct.cmsghdr** %1, %struct.cmsghdr*** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = bitcast i8* %9 to %struct.cmsghdr*
store %struct.cmsghdr* %10, %struct.cmsghdr** %8
%11 = load i32, i32* %7
%12 = load i32, i32* @IPV6_HOPOPTS
%13 = icmp eq i32 %11, %12
br i1 %13, label %25, label %14
14: ; preds = %3
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 22
br i1 %16, label %25, label %17
17: ; preds = %14
%18 = load i32, i32* %7
%19 = load i32, i32* @IPV6_DSTOPTS
%20 = icmp eq i32 %18, %19
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 23
br i1 %23, label %25, label %24
24: ; preds = %21
store i32 -1, i32* %4
br label %37
25: ; preds = %21, %17, %14, %3
%26 = load i32, i32* @IPPROTO_IPV6
%27 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%28 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %27, i32 0, i32 2
store i32 %26, i32* %28
%29 = load i32, i32* %7
%30 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%31 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = call i32 @CMSG_LEN(i32 0)
%33 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%34 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %33, i32 0, i32 1
store i32 %32, i32* %34
%35 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%36 = load %struct.cmsghdr**, %struct.cmsghdr*** %6
store %struct.cmsghdr* %35, %struct.cmsghdr** %36
store i32 0, i32* %4
br label %37
37: ; preds = %25, %24
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
%struct.cmsghdr = type { i32, i32, i32 }
@IPV6_HOPOPTS = global i32 0
@IPV6_DSTOPTS = global i32 0
@IPPROTO_IPV6 = global i32 0
define i32 @inet6_option_init(i8* %0, %struct.cmsghdr** nocapture writeonly %1, i32 %2) {
%4 = load i32, i32* @IPV6_HOPOPTS
%5 = icmp eq i32 %4, %2
%6 = icmp eq i32 %2, 22
%7 = or i1 %6, %5
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = load i32, i32* @IPV6_DSTOPTS
%10 = icmp eq i32 %9, %2
%11 = icmp eq i32 %2, 23
%12 = or i1 %11, %10
br i1 %12, label %13, label %22
13: ; preds = %8, %3
%14 = load i32, i32* @IPPROTO_IPV6
%15 = getelementptr inbounds i8, i8* %0, i64 8
%16 = bitcast i8* %15 to i32*
store i32 %14, i32* %16
%17 = bitcast i8* %0 to i32*
store i32 %2, i32* %17
%18 = tail call i32 @CMSG_LEN(i32 0)
%19 = getelementptr inbounds i8, i8* %0, i64 4
%20 = bitcast i8* %19 to i32*
store i32 %18, i32* %20
%21 = bitcast %struct.cmsghdr** %1 to i8**
store i8* %0, i8** %21
br label %22
22: ; preds = %8, %13
%23 = phi i32 [ 0, %13 ], [ -1, %8 ]
ret i32 %23
}