#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 */

/* Variables and functions */
scalar_t__ memcmp(unsigned char const *, unsigned char const *, unsigned char);
int in_prefix(const unsigned char *restrict address,
              const unsigned char *restrict prefix, unsigned char plen) {
  unsigned char m;
  if (plen > 128)
    plen = 128;
  if (memcmp(address, prefix, plen / 8) != 0)
    return 0;
  if (plen % 8 == 0)
    return 1;
  m = 0xFF << (8 - (plen % 8));
  return ((address[plen / 8] & m) == (prefix[plen / 8] & m));
}


x86 assembly (clang, -O0):
<in_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x80,%eax
jle    1138 <in_prefix+0x28>
movb   $0x80,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movzbl -0x19(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
movzbl %al,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     116a <in_prefix+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    1201 <in_prefix+0xf1>
movzbl -0x19(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118b <in_prefix+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    1201 <in_prefix+0xf1>
movzbl -0x19(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x8,%ecx
sub    %edx,%ecx
mov    $0xff,%eax
shl    %cl,%eax
mov    %al,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movzbl -0x19(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x1a(%rbp),%ecx
and    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
movzbl -0x19(%rbp),%eax
mov    $0x8,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x20(%rbp),%eax
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
movzbl -0x1a(%rbp),%edx
and    %edx,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_prefix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
test   %dl,%dl
mov    $0x80,%ebx
cmovns %edx,%ebx
mov    %rbx,%r12
shr    $0x3,%r12
mov    %r12d,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1165 <in_prefix+0x55>
and    $0x7,%ebx
je     1160 <in_prefix+0x50>
mov    $0x8,%cl
sub    %bl,%cl
mov    (%r15,%r12,1),%al
xor    (%r14,%r12,1),%al
movzbl %al,%edx
shr    %cl,%edx
xor    %eax,%eax
test   %edx,%edx
sete   %al
jmp    1165 <in_prefix+0x55>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @in_prefix(i8* noalias %0, i8* noalias %1, i8 zeroext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%9 = load i8, i8* %7
%10 = zext i8 %9 to i32
%11 = icmp sgt i32 %10, 128
br i1 %11, label %12, label %13
12: ; preds = %3
store i8 -128, i8* %7
br label %13
13: ; preds = %12, %3
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = load i8, i8* %7
%17 = zext i8 %16 to i32
%18 = sdiv i32 %17, 8
%19 = trunc i32 %18 to i8
%20 = call i64 @memcmp(i8* %14, i8* %15, i8 zeroext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 0, i32* %4
br label %60
23: ; preds = %13
%24 = load i8, i8* %7
%25 = zext i8 %24 to i32
%26 = srem i32 %25, 8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %4
br label %60
29: ; preds = %23
%30 = load i8, i8* %7
%31 = zext i8 %30 to i32
%32 = srem i32 %31, 8
%33 = sub nsw i32 8, %32
%34 = shl i32 255, %33
%35 = trunc i32 %34 to i8
store i8 %35, i8* %8
%36 = load i8*, i8** %5
%37 = load i8, i8* %7
%38 = zext i8 %37 to i32
%39 = sdiv i32 %38, 8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = load i8, i8* %8
%45 = zext i8 %44 to i32
%46 = and i32 %43, %45
%47 = load i8*, i8** %6
%48 = load i8, i8* %7
%49 = zext i8 %48 to i32
%50 = sdiv i32 %49, 8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %47, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = load i8, i8* %8
%56 = zext i8 %55 to i32
%57 = and i32 %54, %56
%58 = icmp eq i32 %46, %57
%59 = zext i1 %58 to i32
store i32 %59, i32* %4
br label %60
60: ; preds = %29, %28, %22
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
define i32 @in_prefix(i8* noalias %0, i8* noalias %1, i8 zeroext %2) {
%4 = icmp ult i8 %2, -128
%5 = select i1 %4, i8 %2, i8 -128
%6 = zext i8 %5 to i32
%7 = lshr i32 %6, 3
%8 = trunc i32 %7 to i8
%9 = tail call i64 @memcmp(i8* %0, i8* %1, i8 zeroext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %3
%12 = and i32 %6, 7
%13 = icmp eq i32 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = sub nuw nsw i32 8, %12
%16 = shl nuw nsw i32 255, %15
%17 = zext i32 %7 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %1, i64 %17
%21 = load i8, i8* %20
%22 = xor i8 %21, %19
%23 = zext i8 %22 to i32
%24 = and i32 %16, %23
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %11, %3, %14
%28 = phi i32 [ %26, %14 ], [ 0, %3 ], [ 1, %11 ]
ret i32 %28
}