#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 unsigned char in6_addr;

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void parse_pref(struct in6_addr *a, const unsigned char *p, int plen) {
  unsigned char b[16];
  memset(b, 0, 16);
  memcpy(b, p, plen / 8);
  if (plen % 8 != 0)
    b[plen / 8] = (p[plen / 8] & ((0xFF << (8 - (plen % 8))) & 0xFF));
  memcpy(a, b, 16);
}


x86 assembly (clang, -O0):
<parse_pref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11cd <parse_pref+0xad>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x34(%rbp),%eax
mov    $0x8,%ecx
sub    %edx,%ecx
mov    $0xff,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    $0xff,%ecx
and    %ecx,%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    $0x8,%esi
cltd
idiv   %esi
cltq
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pref>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    0x7(%rbx),%ebp
test   %ebx,%ebx
cmovns %ebx,%ebp
mov    %ebp,%r13d
sar    $0x3,%r13d
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
and    $0xfffffff8,%ebp
sub    %ebp,%ebx
je     1181 <parse_pref+0x61>
mov    $0x8,%cl
sub    %bl,%cl
mov    $0xff,%eax
shl    %cl,%eax
movslq %r13d,%rcx
and    (%r15,%rcx,1),%al
mov    %al,(%rsp,%rcx,1)
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type opaque
define void @parse_pref(%struct.in6_addr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.in6_addr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [16 x i8]
store %struct.in6_addr* %0, %struct.in6_addr** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 16)
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = sdiv i32 %12, 8
%14 = call i32 @memcpy(i8* %10, i8* %11, i32 %13)
%15 = load i32, i32* %6
%16 = srem i32 %15, 8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sdiv i32 %20, 8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = load i32, i32* %6
%27 = srem i32 %26, 8
%28 = sub nsw i32 8, %27
%29 = shl i32 255, %28
%30 = and i32 %29, 255
%31 = and i32 %25, %30
%32 = trunc i32 %31 to i8
%33 = load i32, i32* %6
%34 = sdiv i32 %33, 8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %18, %3
%38 = load %struct.in6_addr*, %struct.in6_addr** %4
%39 = bitcast %struct.in6_addr* %38 to i8*
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%41 = call i32 @memcpy(i8* %39, i8* %40, i32 16)
ret void
}

LLVM IR (-O2):
%struct.in6_addr = type opaque
define void @parse_pref(%struct.in6_addr* %0, i8* %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 16)
%7 = sdiv i32 %2, 8
%8 = call i32 @memcpy(i8* %5, i8* %1, i32 %7)
%9 = srem i32 %2, 8
%10 = icmp eq i32 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %3
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = sub nsw i32 8, %9
%16 = shl nuw nsw i32 255, %15
%17 = trunc i32 %16 to i8
%18 = and i8 %14, %17
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %12
store i8 %18, i8* %19
br label %20
20: ; preds = %11, %3
%21 = bitcast %struct.in6_addr* %0 to i8*
%22 = call i32 @memcpy(i8* %21, i8* %5, i32 16)
ret void
}