#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;
__attribute__((visibility("default"))) int
inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) {
  struct cmsghdr *ch = (struct cmsghdr *)bp;
  if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS)
    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     115b <inet6_option_init+0x4b>
mov    -0x1c(%rbp),%eax
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%eax
je     115b <inet6_option_init+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <inet6_option_init+0x86>
mov    0x2e6e(%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
mov    0x2ec7(%rip),%rax
cmp    %edx,(%rax)
je     1135 <inet6_option_init+0x25>
mov    0x2eac(%rip),%rax
mov    $0xffffffff,%ebp
cmp    %edx,(%rax)
jne    1152 <inet6_option_init+0x42>
mov    0x2e94(%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 ne i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* %7
%16 = load i32, i32* @IPV6_DSTOPTS
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %4
br label %31
19: ; preds = %14, %3
%20 = load i32, i32* @IPPROTO_IPV6
%21 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%22 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %21, i32 0, i32 2
store i32 %20, i32* %22
%23 = load i32, i32* %7
%24 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%25 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = call i32 @CMSG_LEN(i32 0)
%27 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%28 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %27, i32 0, i32 1
store i32 %26, i32* %28
%29 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%30 = load %struct.cmsghdr**, %struct.cmsghdr*** %6
store %struct.cmsghdr* %29, %struct.cmsghdr** %30
store i32 0, i32* %4
br label %31
31: ; preds = %19, %18
%32 = load i32, i32* %4
ret i32 %32
}

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 = load i32, i32* @IPV6_DSTOPTS
%7 = icmp eq i32 %6, %2
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %18
9: ; preds = %3
%10 = load i32, i32* @IPPROTO_IPV6
%11 = getelementptr inbounds i8, i8* %0, i64 8
%12 = bitcast i8* %11 to i32*
store i32 %10, i32* %12
%13 = bitcast i8* %0 to i32*
store i32 %2, i32* %13
%14 = tail call i32 @CMSG_LEN(i32 0)
%15 = getelementptr inbounds i8, i8* %0, i64 4
%16 = bitcast i8* %15 to i32*
store i32 %14, i32* %16
%17 = bitcast %struct.cmsghdr** %1 to i8**
store i8* %0, i8** %17
br label %18
18: ; preds = %3, %9
%19 = phi i32 [ 0, %9 ], [ -1, %3 ]
ret i32 %19
}