#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 /*<<< orphan*/ _DIAGASSERT(int /*<<< orphan*/);
int inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) {
  register struct cmsghdr *ch;
  _DIAGASSERT(bp != NULL);
  _DIAGASSERT(cmsgp != NULL);
  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)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <_DIAGASSERT@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <_DIAGASSERT@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
je     118f <inet6_option_init+0x6f>
mov    -0x1c(%rbp),%eax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%eax
je     118f <inet6_option_init+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <inet6_option_init+0xaa>
mov    0x2e3a(%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   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <_DIAGASSERT@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <_DIAGASSERT@plt>
mov    0x2e95(%rip),%rax
cmp    %r15d,(%rax)
je     1169 <inet6_option_init+0x49>
mov    0x2e79(%rip),%rax
mov    $0xffffffff,%ebp
cmp    %r15d,(%rax)
jne    1187 <inet6_option_init+0x67>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    %r15d,(%rbx)
xor    %ebp,%ebp
xor    %edi,%edi
call   1030 <CMSG_LEN@plt>
mov    %eax,0x4(%rbx)
mov    %rbx,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @_DIAGASSERT(i32 %11)
%13 = load %struct.cmsghdr**, %struct.cmsghdr*** %6
%14 = icmp ne %struct.cmsghdr** %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @_DIAGASSERT(i32 %15)
%17 = load i8*, i8** %5
%18 = bitcast i8* %17 to %struct.cmsghdr*
store %struct.cmsghdr* %18, %struct.cmsghdr** %8
%19 = load i32, i32* %7
%20 = load i32, i32* @IPV6_HOPOPTS
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %3
%23 = load i32, i32* %7
%24 = load i32, i32* @IPV6_DSTOPTS
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %4
br label %39
27: ; preds = %22, %3
%28 = load i32, i32* @IPPROTO_IPV6
%29 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%30 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %29, i32 0, i32 2
store i32 %28, i32* %30
%31 = load i32, i32* %7
%32 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%33 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = call i32 @CMSG_LEN(i32 0)
%35 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%36 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %35, i32 0, i32 1
store i32 %34, i32* %36
%37 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%38 = load %struct.cmsghdr**, %struct.cmsghdr*** %6
store %struct.cmsghdr* %37, %struct.cmsghdr** %38
store i32 0, i32* %4
br label %39
39: ; preds = %27, %26
%40 = load i32, i32* %4
ret i32 %40
}

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