#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 scalar_t__ uint8_t;
struct in6_addr {
  int dummy;
};

/* Variables and functions */
scalar_t__ IPV6_RTHDR_TYPE_0;
int /*<<< orphan*/ memcpy(scalar_t__ *, struct in6_addr const *, int);
int inet6_rth_add(void *bp, const struct in6_addr *addr) {
  if (((uint8_t *)bp)[2] != IPV6_RTHDR_TYPE_0)
    return -1;
  memcpy(((uint8_t *)bp) + 8 + 16 * ((uint8_t *)bp)[3]++, addr, 16);
  return 0;
}


x86 assembly (clang, -O0):
<inet6_rth_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%rax
je     1144 <inet6_rth_add+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <inet6_rth_add+0x6f>
mov    -0x10(%rbp),%rdi
add    $0x40,%rdi
mov    -0x10(%rbp),%rcx
mov    0x18(%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,0x18(%rcx)
shl    $0x4,%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_rth_add>:
push   %rax
mov    0x10(%rdi),%rcx
mov    0x2ecc(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    1149 <inet6_rth_add+0x39>
mov    0x18(%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x18(%rdi)
shl    $0x7,%rax
add    %rax,%rdi
add    $0x40,%rdi
mov    $0x10,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@IPV6_RTHDR_TYPE_0 = global i64 0
define i32 @inet6_rth_add(i8* %0, %struct.in6_addr* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.in6_addr*
store i8* %0, i8** %4
store %struct.in6_addr* %1, %struct.in6_addr** %5
%6 = load i8*, i8** %4
%7 = bitcast i8* %6 to i64*
%8 = getelementptr inbounds i64, i64* %7, i64 2
%9 = load i64, i64* %8
%10 = load i64, i64* @IPV6_RTHDR_TYPE_0
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %26
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to i64*
%16 = getelementptr inbounds i64, i64* %15, i64 8
%17 = load i8*, i8** %4
%18 = bitcast i8* %17 to i64*
%19 = getelementptr inbounds i64, i64* %18, i64 3
%20 = load i64, i64* %19
%21 = add nsw i64 %20, 1
store i64 %21, i64* %19
%22 = mul nsw i64 16, %20
%23 = getelementptr inbounds i64, i64* %16, i64 %22
%24 = load %struct.in6_addr*, %struct.in6_addr** %5
%25 = call i32 @memcpy(i64* %23, %struct.in6_addr* %24, i32 16)
store i32 0, i32* %3
br label %26
26: ; preds = %13, %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@IPV6_RTHDR_TYPE_0 = global i64 0
define i32 @inet6_rth_add(i8* %0, %struct.in6_addr* %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 16
%4 = bitcast i8* %3 to i64*
%5 = load i64, i64* %4
%6 = load i64, i64* @IPV6_RTHDR_TYPE_0
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %0, i64 64
%10 = bitcast i8* %9 to i64*
%11 = getelementptr inbounds i8, i8* %0, i64 24
%12 = bitcast i8* %11 to i64*
%13 = load i64, i64* %12
%14 = add nsw i64 %13, 1
store i64 %14, i64* %12
%15 = shl nsw i64 %13, 4
%16 = getelementptr inbounds i64, i64* %10, i64 %15
%17 = tail call i32 @memcpy(i64* %16, %struct.in6_addr* %1, i32 16)
br label %18
18: ; preds = %2, %8
%19 = phi i32 [ 0, %8 ], [ -1, %2 ]
ret i32 %19
}