#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 uint32_t;
struct msghdr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_DSTOPTS;
int inet6_opt_append(void *, int, int, int /*<<< orphan*/, int, int, void **);
int inet6_opt_finish(void *, int, int);
int inet6_opt_init(int /*<<< orphan*/ *, int /*<<< orphan*/);
int set_ancillary_attr(struct msghdr *, int /*<<< orphan*/, int /*<<< orphan*/,
                       void *, int);
int create_dstopt(struct msghdr *msg, void *hdrbuf, uint32_t hdrbuf_len,
                  uint32_t dstopt_len, void **optbuf) {
  uint32_t acclen = 0;
  uint32_t opt_len = 0;
  uint32_t offset = 0;
  offset = inet6_opt_init(NULL, 0);
  opt_len = inet6_opt_append(hdrbuf, hdrbuf_len, offset, IPV6_DSTOPTS,
                             dstopt_len, 8, optbuf);
  opt_len = inet6_opt_finish(hdrbuf, hdrbuf_len, dstopt_len);
  acclen = set_ancillary_attr(msg, IPPROTO_IPV6, IPV6_DSTOPTS, hdrbuf, opt_len);
  return acclen;
}


x86 assembly (clang, -O0):
<create_dstopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1060 <inet6_opt_init@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    0x2e52(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%rax
mov    $0x8,%r9d
mov    %rax,(%rsp)
call   1050 <inet6_opt_append@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <inet6_opt_finish@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8d
call   1040 <set_ancillary_attr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dstopt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
xor    %esi,%esi
call   1060 <inet6_opt_init@plt>
mov    0x2e77(%rip),%r13
mov    0x0(%r13),%ecx
mov    %r15,(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r12d,%r8d
mov    $0x8,%r9d
call   1050 <inet6_opt_append@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1030 <inet6_opt_finish@plt>
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%esi
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    %rbx,%rcx
mov    %eax,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <set_ancillary_attr@plt>

LLVM IR (-O0):
%struct.msghdr = type { i32 }
@IPV6_DSTOPTS = global i32 0
@IPPROTO_IPV6 = global i32 0
define i32 @create_dstopt(%struct.msghdr* %0, i8* %1, i32 %2, i32 %3, i8** %4) {
%6 = alloca %struct.msghdr*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store %struct.msghdr* %0, %struct.msghdr** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8** %4, i8*** %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%14 = call i32 @inet6_opt_init(i32* null, i32 0)
store i32 %14, i32* %13
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = load i32, i32* %13
%18 = load i32, i32* @IPV6_DSTOPTS
%19 = load i32, i32* %9
%20 = load i8**, i8*** %10
%21 = call i32 @inet6_opt_append(i8* %15, i32 %16, i32 %17, i32 %18, i32 %19, i32 8, i8** %20)
store i32 %21, i32* %12
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = call i32 @inet6_opt_finish(i8* %22, i32 %23, i32 %24)
store i32 %25, i32* %12
%26 = load %struct.msghdr*, %struct.msghdr** %6
%27 = load i32, i32* @IPPROTO_IPV6
%28 = load i32, i32* @IPV6_DSTOPTS
%29 = load i8*, i8** %7
%30 = load i32, i32* %12
%31 = call i32 @set_ancillary_attr(%struct.msghdr* %26, i32 %27, i32 %28, i8* %29, i32 %30)
store i32 %31, i32* %11
%32 = load i32, i32* %11
ret i32 %32
}

LLVM IR (-O2):
%struct.msghdr = type { i32 }
@IPV6_DSTOPTS = global i32 0
@IPPROTO_IPV6 = global i32 0
define i32 @create_dstopt(%struct.msghdr* %0, i8* %1, i32 %2, i32 %3, i8** %4) {
%6 = tail call i32 @inet6_opt_init(i32* null, i32 0)
%7 = load i32, i32* @IPV6_DSTOPTS
%8 = tail call i32 @inet6_opt_append(i8* %1, i32 %2, i32 %6, i32 %7, i32 %3, i32 8, i8** %4)
%9 = tail call i32 @inet6_opt_finish(i8* %1, i32 %2, i32 %3)
%10 = load i32, i32* @IPPROTO_IPV6
%11 = load i32, i32* @IPV6_DSTOPTS
%12 = tail call i32 @set_ancillary_attr(%struct.msghdr* %0, i32 %10, i32 %11, i8* %1, i32 %9)
ret i32 %12
}