#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 ip6_rthdr0 {
  int ip6r0_len;
  int /*<<< orphan*/ ip6r0_segleft;
  int /*<<< orphan*/ *ip6r0_addr;
};
struct in6_addr {
  int dummy;
};
struct cmsghdr {
  int cmsg_len;
};

/* Variables and functions */
scalar_t__ CMSG_DATA(struct cmsghdr *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in6_addr const *, int);
int inet6_srcrt_add(struct cmsghdr *cmsg, const struct in6_addr *addr) {
  struct ip6_rthdr0 *hdr;
  hdr = (struct ip6_rthdr0 *)CMSG_DATA(cmsg);
  cmsg->cmsg_len += sizeof(struct in6_addr);
  hdr->ip6r0_len += sizeof(struct in6_addr) / 8;
  memcpy(&hdr->ip6r0_addr[hdr->ip6r0_segleft++], addr, sizeof(struct in6_addr));
  return 0;
}


x86 assembly (clang, -O0):
<inet6_srcrt_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <CMSG_DATA@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq (%rax),%rcx
add    $0x4,%rcx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movslq (%rax),%rcx
add    $0x0,%rcx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rcx
mov    0x4(%rcx),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,0x4(%rcx)
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_srcrt_add>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <CMSG_DATA@plt>
addl   $0x4,(%rbx)
movslq 0x4(%rax),%rdi
lea    0x1(%rdi),%ecx
mov    %ecx,0x4(%rax)
shl    $0x2,%rdi
add    0x8(%rax),%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.cmsghdr = type { i32 }
%struct.in6_addr = type { i32 }
%struct.ip6_rthdr0 = type { i32, i32, i32* }
define i32 @inet6_srcrt_add(%struct.cmsghdr* %0, %struct.in6_addr* %1) {
%3 = alloca %struct.cmsghdr*
%4 = alloca %struct.in6_addr*
%5 = alloca %struct.ip6_rthdr0*
store %struct.cmsghdr* %0, %struct.cmsghdr** %3
store %struct.in6_addr* %1, %struct.in6_addr** %4
%6 = load %struct.cmsghdr*, %struct.cmsghdr** %3
%7 = call i64 @CMSG_DATA(%struct.cmsghdr* %6)
%8 = inttoptr i64 %7 to %struct.ip6_rthdr0*
store %struct.ip6_rthdr0* %8, %struct.ip6_rthdr0** %5
%9 = load %struct.cmsghdr*, %struct.cmsghdr** %3
%10 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = add i64 %12, 4
%14 = trunc i64 %13 to i32
store i32 %14, i32* %10
%15 = load %struct.ip6_rthdr0*, %struct.ip6_rthdr0** %5
%16 = getelementptr inbounds %struct.ip6_rthdr0, %struct.ip6_rthdr0* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = add i64 %18, 0
%20 = trunc i64 %19 to i32
store i32 %20, i32* %16
%21 = load %struct.ip6_rthdr0*, %struct.ip6_rthdr0** %5
%22 = getelementptr inbounds %struct.ip6_rthdr0, %struct.ip6_rthdr0* %21, i32 0, i32 2
%23 = load i32*, i32** %22
%24 = load %struct.ip6_rthdr0*, %struct.ip6_rthdr0** %5
%25 = getelementptr inbounds %struct.ip6_rthdr0, %struct.ip6_rthdr0* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
store i32 %27, i32* %25
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i32, i32* %23, i64 %28
%30 = load %struct.in6_addr*, %struct.in6_addr** %4
%31 = call i32 @memcpy(i32* %29, %struct.in6_addr* %30, i32 4)
ret i32 0
}

LLVM IR (-O2):
%struct.cmsghdr = type { i32 }
%struct.in6_addr = type { i32 }
%struct.ip6_rthdr0 = type { i32, i32, i32* }
define i32 @inet6_srcrt_add(%struct.cmsghdr* %0, %struct.in6_addr* %1) {
%3 = tail call i64 @CMSG_DATA(%struct.cmsghdr* %0)
%4 = inttoptr i64 %3 to %struct.ip6_rthdr0*
%5 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = add i32 %6, 4
store i32 %7, i32* %5
%8 = getelementptr inbounds %struct.ip6_rthdr0, %struct.ip6_rthdr0* %4, i64 0, i32 2
%9 = load i32*, i32** %8
%10 = getelementptr inbounds %struct.ip6_rthdr0, %struct.ip6_rthdr0* %4, i64 0, i32 1
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %10
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i32, i32* %9, i64 %13
%15 = tail call i32 @memcpy(i32* %14, %struct.in6_addr* %1, i32 4)
ret i32 0
}