int GetOctetMsbMatchDepth(int aOct, int bOct) {
  if ((aOct & 0xFF) == (bOct & 0xFF)) {
    return 8;
  } else if ((aOct & 0xFE) == (bOct & 0xFE)) {
    return 8 - 1;
  } else if ((aOct & 0xFC) == (bOct & 0xFC)) {
    return 8 - 2;
  } else if ((aOct & 0xF8) == (bOct & 0xF8)) {
    return 8 - 3;
  } else if ((aOct & 0xF0) == (bOct & 0xF0)) {
    return 8 - 4;
  } else if ((aOct & 0xE0) == (bOct & 0xE0)) {
    return 8 - 5;
  } else if ((aOct & 0xC0) == (bOct & 0xC0)) {
    return 8 - 6;
  } else if ((aOct & 0x80) == (bOct & 0x80)) {
    return 8 - 7;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<GetOctetMsbMatchDepth>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
jne    112f <GetOctetMsbMatchDepth+0x2f>
movl   $0x8,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
mov    -0x8(%rbp),%eax
and    $0xfe,%eax
mov    -0xc(%rbp),%ecx
and    $0xfe,%ecx
cmp    %ecx,%eax
jne    1154 <GetOctetMsbMatchDepth+0x54>
movl   $0x7,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
mov    -0x8(%rbp),%eax
and    $0xfc,%eax
mov    -0xc(%rbp),%ecx
and    $0xfc,%ecx
cmp    %ecx,%eax
jne    1179 <GetOctetMsbMatchDepth+0x79>
movl   $0x6,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
mov    -0x8(%rbp),%eax
and    $0xf8,%eax
mov    -0xc(%rbp),%ecx
and    $0xf8,%ecx
cmp    %ecx,%eax
jne    119e <GetOctetMsbMatchDepth+0x9e>
movl   $0x5,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
mov    -0xc(%rbp),%ecx
and    $0xf0,%ecx
cmp    %ecx,%eax
jne    11c3 <GetOctetMsbMatchDepth+0xc3>
movl   $0x4,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
mov    -0x8(%rbp),%eax
and    $0xe0,%eax
mov    -0xc(%rbp),%ecx
and    $0xe0,%ecx
cmp    %ecx,%eax
jne    11e8 <GetOctetMsbMatchDepth+0xe8>
movl   $0x3,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
mov    -0x8(%rbp),%eax
and    $0xc0,%eax
mov    -0xc(%rbp),%ecx
and    $0xc0,%ecx
cmp    %ecx,%eax
jne    120d <GetOctetMsbMatchDepth+0x10d>
movl   $0x2,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
mov    -0x8(%rbp),%eax
and    $0x80,%eax
mov    -0xc(%rbp),%ecx
and    $0x80,%ecx
cmp    %ecx,%eax
jne    1232 <GetOctetMsbMatchDepth+0x132>
movl   $0x1,-0x4(%rbp)
jmp    1239 <GetOctetMsbMatchDepth+0x139>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetOctetMsbMatchDepth>:
xor    %esi,%edi
test   %dil,%dil
je     1135 <GetOctetMsbMatchDepth+0x35>
test   $0xfe,%dil
je     113b <GetOctetMsbMatchDepth+0x3b>
test   $0xfc,%dil
je     1141 <GetOctetMsbMatchDepth+0x41>
test   $0xf8,%dil
je     1147 <GetOctetMsbMatchDepth+0x47>
test   $0xf0,%dil
je     114d <GetOctetMsbMatchDepth+0x4d>
test   $0xe0,%dil
je     1153 <GetOctetMsbMatchDepth+0x53>
test   $0xc0,%dil
je     1159 <GetOctetMsbMatchDepth+0x59>
xor    %eax,%eax
test   $0x80,%dil
sete   %al
ret
mov    $0x8,%eax
ret
mov    $0x7,%eax
ret
mov    $0x6,%eax
ret
mov    $0x5,%eax
ret
mov    $0x4,%eax
ret
mov    $0x3,%eax
ret
mov    $0x2,%eax
ret

LLVM IR (-O0):
define i32 @GetOctetMsbMatchDepth(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = and i32 %6, 255
%8 = load i32, i32* %5
%9 = and i32 %8, 255
%10 = icmp eq i32 %7, %9
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 8, i32* %3
br label %62
12: ; preds = %2
%13 = load i32, i32* %4
%14 = and i32 %13, 254
%15 = load i32, i32* %5
%16 = and i32 %15, 254
%17 = icmp eq i32 %14, %16
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 7, i32* %3
br label %62
19: ; preds = %12
%20 = load i32, i32* %4
%21 = and i32 %20, 252
%22 = load i32, i32* %5
%23 = and i32 %22, 252
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 6, i32* %3
br label %62
26: ; preds = %19
%27 = load i32, i32* %4
%28 = and i32 %27, 248
%29 = load i32, i32* %5
%30 = and i32 %29, 248
%31 = icmp eq i32 %28, %30
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 5, i32* %3
br label %62
33: ; preds = %26
%34 = load i32, i32* %4
%35 = and i32 %34, 240
%36 = load i32, i32* %5
%37 = and i32 %36, 240
%38 = icmp eq i32 %35, %37
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 4, i32* %3
br label %62
40: ; preds = %33
%41 = load i32, i32* %4
%42 = and i32 %41, 224
%43 = load i32, i32* %5
%44 = and i32 %43, 224
%45 = icmp eq i32 %42, %44
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 3, i32* %3
br label %62
47: ; preds = %40
%48 = load i32, i32* %4
%49 = and i32 %48, 192
%50 = load i32, i32* %5
%51 = and i32 %50, 192
%52 = icmp eq i32 %49, %51
br i1 %52, label %53, label %54
53: ; preds = %47
store i32 2, i32* %3
br label %62
54: ; preds = %47
%55 = load i32, i32* %4
%56 = and i32 %55, 128
%57 = load i32, i32* %5
%58 = and i32 %57, 128
%59 = icmp eq i32 %56, %58
br i1 %59, label %60, label %61
60: ; preds = %54
store i32 1, i32* %3
br label %62
61: ; preds = %54
store i32 0, i32* %3
br label %62
62: ; preds = %61, %60, %53, %46, %39, %32, %25, %18, %11
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
define i32 @GetOctetMsbMatchDepth(i32 %0, i32 %1) {
%3 = xor i32 %1, %0
%4 = and i32 %3, 255
%5 = icmp eq i32 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %2
%7 = and i32 %3, 254
%8 = icmp eq i32 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = and i32 %3, 252
%11 = icmp eq i32 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = and i32 %3, 248
%14 = icmp eq i32 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %12
%16 = and i32 %3, 240
%17 = icmp eq i32 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %15
%19 = and i32 %3, 224
%20 = icmp eq i32 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %18
%22 = and i32 %3, 192
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = lshr i32 %3, 7
%26 = and i32 %25, 1
%27 = xor i32 %26, 1
br label %28
28: ; preds = %24, %21, %18, %15, %12, %9, %6, %2
%29 = phi i32 [ 8, %2 ], [ 7, %6 ], [ 6, %9 ], [ 5, %12 ], [ 4, %15 ], [ 3, %18 ], [ 2, %21 ], [ %27, %24 ]
ret i32 %29
}