int count_leading_zeros_128(const __uint128_t *src) {
  int i = 127;
  while ((i >= 0) && ((((__uint128_t)1 << i) & *src) == 0)) {
    i--;
  };
  return (127 - i);
}


x86 assembly (clang, -O0):
<count_leading_zeros_128>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x7f,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jl     1169 <count_leading_zeros_128+0x69>
mov    -0xc(%rbp),%sil
xor    %eax,%eax
mov    %eax,%edx
mov    $0x1,%eax
mov    %sil,%cl
mov    %rdx,%rdi
shld   %cl,%rax,%rdi
mov    %rdi,-0x18(%rbp)
mov    %sil,%cl
shl    %cl,%rax
mov    -0x18(%rbp),%rcx
test   $0x40,%sil
cmovne %rax,%rcx
cmovne %rdx,%rax
mov    -0x8(%rbp),%rsi
mov    (%rsi),%rdx
mov    0x8(%rsi),%rsi
and    %rsi,%rcx
and    %rdx,%rax
or     %rcx,%rax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1179 <count_leading_zeros_128+0x79>
jmp    1187 <count_leading_zeros_128+0x87>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    110f <count_leading_zeros_128+0xf>
mov    $0x7f,%eax
sub    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_leading_zeros_128>:
mov    (%rdi),%r10
mov    0x8(%rdi),%rsi
mov    $0x7c,%edx
xor    %r8d,%r8d
mov    $0x1,%r9d
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x3(%rdx),%ecx
xor    %edi,%edi
shld   %cl,%r9,%rdi
mov    $0x1,%eax
shl    %cl,%rax
test   $0x40,%cl
cmovne %rax,%rdi
cmovne %r8,%rax
and    %rsi,%rdi
and    %r10,%rax
or     %rdi,%rax
jne    11d2 <count_leading_zeros_128+0xd2>
lea    0x2(%rdx),%ecx
xor    %eax,%eax
shld   %cl,%r9,%rax
mov    $0x1,%edi
shl    %cl,%rdi
test   $0x40,%cl
cmovne %rdi,%rax
cmovne %r8,%rdi
and    %rsi,%rax
and    %r10,%rdi
or     %rax,%rdi
jne    11d7 <count_leading_zeros_128+0xd7>
lea    0x1(%rdx),%ecx
xor    %eax,%eax
shld   %cl,%r9,%rax
mov    $0x1,%edi
shl    %cl,%rdi
test   $0x40,%cl
cmovne %rdi,%rax
cmovne %r8,%rdi
and    %rsi,%rax
and    %r10,%rdi
or     %rax,%rdi
jne    11dc <count_leading_zeros_128+0xdc>
xor    %eax,%eax
mov    %edx,%ecx
shld   %cl,%r9,%rax
mov    $0x1,%edi
shl    %cl,%rdi
test   $0x40,%dl
cmovne %rdi,%rax
cmovne %r8,%rdi
and    %rsi,%rax
and    %r10,%rdi
or     %rax,%rdi
jne    11df <count_leading_zeros_128+0xdf>
add    $0xfffffffc,%edx
cmp    $0xfffffffc,%edx
jne    1120 <count_leading_zeros_128+0x20>
mov    $0xffffffff,%edx
jmp    11df <count_leading_zeros_128+0xdf>
add    $0x3,%edx
jmp    11df <count_leading_zeros_128+0xdf>
add    $0x2,%edx
jmp    11df <count_leading_zeros_128+0xdf>
add    $0x1,%edx
mov    $0x7f,%eax
sub    %edx,%eax
ret

LLVM IR (-O0):
define i32 @count_leading_zeros_128(i128* %0) {
%2 = alloca i128*
%3 = alloca i32
store i128* %0, i128** %2
store i32 127, i32* %3
br label %4
4: ; preds = %17, %1
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i32, i32* %3
%9 = zext i32 %8 to i128
%10 = shl i128 1, %9
%11 = load i128*, i128** %2
%12 = load i128, i128* %11
%13 = and i128 %10, %12
%14 = icmp eq i128 %13, 0
br label %15
15: ; preds = %7, %4
%16 = phi i1 [ false, %4 ], [ %14, %7 ]
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -1
store i32 %19, i32* %3
br label %4
20: ; preds = %15
%21 = load i32, i32* %3
%22 = sub nsw i32 127, %21
ret i32 %22
}

LLVM IR (-O2):
define i32 @count_leading_zeros_128(i128* nocapture %0) {
%2 = load i128, i128* %0
br label %3
3: ; preds = %27, %1
%4 = phi i32 [ 127, %1 ], [ %28, %27 ]
%5 = zext i32 %4 to i128
%6 = shl nuw i128 1, %5
%7 = and i128 %2, %6
%8 = icmp eq i128 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %3
%10 = add nsw i32 %4, -1
%11 = zext i32 %10 to i128
%12 = shl nuw i128 1, %11
%13 = and i128 %2, %12
%14 = icmp eq i128 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %9
%16 = add nsw i32 %4, -2
%17 = zext i32 %16 to i128
%18 = shl nuw i128 1, %17
%19 = and i128 %2, %18
%20 = icmp eq i128 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %15
%22 = add nsw i32 %4, -3
%23 = zext i32 %22 to i128
%24 = shl nuw i128 1, %23
%25 = and i128 %2, %24
%26 = icmp eq i128 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = add nsw i32 %4, -4
%29 = icmp eq i32 %22, 0
br i1 %29, label %30, label %3
30: ; preds = %27, %21, %15, %9, %3
%31 = phi i32 [ %4, %3 ], [ %10, %9 ], [ %16, %15 ], [ %22, %21 ], [ -1, %27 ]
%32 = sub nsw i32 127, %31
ret i32 %32
}