#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_level;
  int /*<<< orphan*/ cmsg_len;
};

/* 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) {
  if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS)
    return -1;
  struct cmsghdr *newp = (struct cmsghdr *)bp;
  newp->cmsg_len = CMSG_LEN(0);
  newp->cmsg_level = IPPROTO_IPV6;
  newp->cmsg_type = type;
  *cmsgp = newp;
  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    -0x1c(%rbp),%eax
mov    0x2ebb(%rip),%rcx
cmp    (%rcx),%eax
je     1153 <inet6_option_init+0x43>
mov    -0x1c(%rbp),%eax
mov    0x2e99(%rip),%rcx
cmp    (%rcx),%eax
je     1153 <inet6_option_init+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <inet6_option_init+0x86>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
call   1030 <CMSG_LEN@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2e5e(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%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,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ec2(%rip),%rax
cmp    %edx,(%rax)
je     113b <inet6_option_init+0x2b>
mov    0x2ea7(%rip),%rax
mov    $0xffffffff,%r15d
cmp    %ebp,(%rax)
jne    1159 <inet6_option_init+0x49>
xor    %r15d,%r15d
xor    %edi,%edi
call   1030 <CMSG_LEN@plt>
mov    %eax,0x8(%rbx)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %ebp,(%rbx)
mov    %rbx,(%r14)
mov    %r15d,%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 i32, i32* %7
%10 = load i32, i32* @IPV6_HOPOPTS
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* %7
%14 = load i32, i32* @IPV6_DSTOPTS
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %4
br label %31
17: ; preds = %12, %3
%18 = load i8*, i8** %5
%19 = bitcast i8* %18 to %struct.cmsghdr*
store %struct.cmsghdr* %19, %struct.cmsghdr** %8
%20 = call i32 @CMSG_LEN(i32 0)
%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* @IPPROTO_IPV6
%24 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%25 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %24, i32 0, i32 1
store i32 %23, i32* %25
%26 = load i32, i32* %7
%27 = load %struct.cmsghdr*, %struct.cmsghdr** %8
%28 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %27, i32 0, i32 0
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 = %17, %16
%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 = tail call i32 @CMSG_LEN(i32 0)
%11 = getelementptr inbounds i8, i8* %0, i64 8
%12 = bitcast i8* %11 to i32*
store i32 %10, i32* %12
%13 = load i32, i32* @IPPROTO_IPV6
%14 = getelementptr inbounds i8, i8* %0, i64 4
%15 = bitcast i8* %14 to i32*
store i32 %13, i32* %15
%16 = bitcast i8* %0 to i32*
store i32 %2, 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
}