int utf8_enc_len(int first_char) {
  if (first_char < 0x80)
    return 1;
  if (first_char < 0xc0)
    return 0;
  if (first_char < 0xe0)
    return 2;
  if (first_char < 0xf0)
    return 3;
  if (first_char < 0xf8)
    return 4;
  if (first_char < 0xfc)
    return 5;
  if (first_char < 0xfe)
    return 6;
  return 0;
}


x86 assembly (clang, -O0):
<utf8_enc_len>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1120 <utf8_enc_len+0x20>
movl   $0x1,-0x4(%rbp)
jmp    11bd <utf8_enc_len+0xbd>
cmpl   $0xc0,-0x8(%rbp)
jge    1139 <utf8_enc_len+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11bd <utf8_enc_len+0xbd>
cmpl   $0xe0,-0x8(%rbp)
jge    1152 <utf8_enc_len+0x52>
movl   $0x2,-0x4(%rbp)
jmp    11bd <utf8_enc_len+0xbd>
cmpl   $0xf0,-0x8(%rbp)
jge    116b <utf8_enc_len+0x6b>
movl   $0x3,-0x4(%rbp)
jmp    11bd <utf8_enc_len+0xbd>
cmpl   $0xf8,-0x8(%rbp)
jge    1184 <utf8_enc_len+0x84>
movl   $0x4,-0x4(%rbp)
jmp    11bd <utf8_enc_len+0xbd>
cmpl   $0xfc,-0x8(%rbp)
jge    119d <utf8_enc_len+0x9d>
movl   $0x5,-0x4(%rbp)
jmp    11bd <utf8_enc_len+0xbd>
cmpl   $0xfe,-0x8(%rbp)
jge    11b6 <utf8_enc_len+0xb6>
movl   $0x6,-0x4(%rbp)
jmp    11bd <utf8_enc_len+0xbd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_enc_len>:
mov    $0x1,%eax
cmp    $0x80,%edi
jl     115b <utf8_enc_len+0x5b>
xor    %eax,%eax
cmp    $0xc0,%edi
jb     115b <utf8_enc_len+0x5b>
mov    $0x2,%eax
cmp    $0xe0,%edi
jb     115b <utf8_enc_len+0x5b>
mov    $0x3,%eax
cmp    $0xf0,%edi
jb     115b <utf8_enc_len+0x5b>
mov    $0x4,%eax
cmp    $0xf8,%edi
jb     115b <utf8_enc_len+0x5b>
mov    $0x5,%eax
cmp    $0xfc,%edi
jb     115b <utf8_enc_len+0x5b>
xor    %ecx,%ecx
cmp    $0xfe,%edi
mov    $0x6,%eax
cmovae %ecx,%eax
ret

LLVM IR (-O0):
define i32 @utf8_enc_len(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 128
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %2
br label %32
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 192
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 0, i32* %2
br label %32
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 224
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 2, i32* %2
br label %32
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 240
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 3, i32* %2
br label %32
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 248
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 4, i32* %2
br label %32
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 252
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 5, i32* %2
br label %32
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 254
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 6, i32* %2
br label %32
31: ; preds = %27
store i32 0, i32* %2
br label %32
32: ; preds = %31, %30, %26, %22, %18, %14, %10, %6
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @utf8_enc_len(i32 %0) {
%2 = icmp slt i32 %0, 128
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 192
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 224
br i1 %6, label %16, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 240
br i1 %8, label %16, label %9
9: ; preds = %7
%10 = icmp ult i32 %0, 248
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = icmp ult i32 %0, 252
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = icmp ult i32 %0, 254
%15 = select i1 %14, i32 6, i32 0
br label %16
16: ; preds = %13, %11, %9, %7, %5, %3, %1
%17 = phi i32 [ 1, %1 ], [ 0, %3 ], [ 2, %5 ], [ 3, %7 ], [ 4, %9 ], [ 5, %11 ], [ %15, %13 ]
ret i32 %17
}