unsigned short floor_log2_s_asm(register unsigned short x) {
  unsigned short result = 0;
  asm("xorl   %%eax, %%eax  ;"
      "movw   %1, %%ax      ;"
      "testw  %%ax, %%ax    ;"
      "je     end_%=        ;"
      "movl   %%eax, %%edx  ;"
      "shrw   %%dx          ;"
      "orw    %%dx, %%ax    ;"
      "movw   %%ax, %%dx    ;"
      "shrw   $2, %%dx      ;"
      "orw    %%dx, %%ax    ;"
      "movw   %%ax, %%dx    ;"
      "shrw   $4, %%dx      ;"
      "orw    %%dx, %%ax    ;"
      "movw   %%ax, %%dx    ;"
      "shrw   $8, %%dx      ;"
      "orw    %%dx, %%ax    ;"
      "movw   %%ax, %%dx    ;"
      "shrw   %%dx          ;"
      "andw   $0x5555, %%dx ;"
      "subw   %%dx, %%ax    ;"
      "movw   %%ax, %%dx    ;"
      "andw   $0x3333, %%dx ;"
      "shrw   $2, %%ax      ;"
      "andw   $0x3333, %%ax ;"
      "addw   %%dx, %%ax    ;"
      "movw   %%ax, %%dx    ;"
      "shrw   $4, %%dx      ;"
      "addw   %%dx, %%ax    ;"
      "andw   $0x0f0f, %%ax ;"
      "movw   %%ax, %%dx    ;"
      "shrw   $8, %%dx      ;"
      "addw   %%dx, %%ax    ;"
      "andw   $0x3f, %%ax   ;"
      "andw   $0x3f, %%ax   ;"
      "subw   $0x1, %%ax    ;"
      "end_%=:                 ;"
      "mov    %%ax, %0      ;"
      : "=r"(result)
      : "r"(x)
      : "%eax", "%edx");
  return result;
}


x86 assembly (clang, -O0):
<floor_log2_s_asm>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movw   $0x0,-0x4(%rbp)
mov    -0x2(%rbp),%cx
xor    %eax,%eax
mov    %cx,%ax
test   %ax,%ax
je     118e <end_0>
mov    %eax,%edx
shr    %dx
or     %dx,%ax
mov    %ax,%dx
shr    $0x2,%dx
or     %dx,%ax
mov    %ax,%dx
shr    $0x4,%dx
or     %dx,%ax
mov    %ax,%dx
shr    $0x8,%dx
or     %dx,%ax
mov    %ax,%dx
shr    %dx
and    $0x5555,%dx
sub    %dx,%ax
mov    %ax,%dx
and    $0x3333,%dx
shr    $0x2,%ax
and    $0x3333,%ax
add    %dx,%ax
mov    %ax,%dx
shr    $0x4,%dx
add    %dx,%ax
and    $0xf0f,%ax
mov    %ax,%dx
shr    $0x8,%dx
add    %dx,%ax
and    $0x3f,%ax
and    $0x3f,%ax
sub    $0x1,%ax

x86 assembly (clang, -O2):
<floor_log2_s_asm>:
xor    %eax,%eax
mov    %di,%ax
test   %ax,%ax
je     1175 <end_0>
mov    %eax,%edx
shr    %dx
or     %dx,%ax
mov    %ax,%dx
shr    $0x2,%dx
or     %dx,%ax
mov    %ax,%dx
shr    $0x4,%dx
or     %dx,%ax
mov    %ax,%dx
shr    $0x8,%dx
or     %dx,%ax
mov    %ax,%dx
shr    %dx
and    $0x5555,%dx
sub    %dx,%ax
mov    %ax,%dx
and    $0x3333,%dx
shr    $0x2,%ax
and    $0x3333,%ax
add    %dx,%ax
mov    %ax,%dx
shr    $0x4,%dx
add    %dx,%ax
and    $0xf0f,%ax
mov    %ax,%dx
shr    $0x8,%dx
add    %dx,%ax
and    $0x3f,%ax
and    $0x3f,%ax
sub    $0x1,%ax

LLVM IR (-O0):
define zeroext i16 @floor_log2_s_asm(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i16
store i16 %0, i16* %2
store i16 0, i16* %3
%4 = load i16, i16* %2
%5 = call i16 asm "xorl %eax, %eax ;movw $1, %ax ;testw %ax, %ax ;je end_${:uid} ;movl %eax, %edx ;shrw %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw $$2, %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw $$4, %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw $$8, %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw %dx ;andw $$0x5555, %dx ;subw %dx, %ax ;movw %ax, %dx ;andw $$0x3333, %dx ;shrw $$2, %ax ;andw $$0x3333, %ax ;addw %dx, %ax ;movw %ax, %dx ;shrw $$4, %dx ;addw %dx, %ax ;andw $$0x0f0f, %ax ;movw %ax, %dx ;shrw $$8, %dx ;addw %dx, %ax ;andw $$0x3f, %ax ;andw $$0x3f, %ax ;subw $$0x1, %ax ;end_${:uid}: ;mov %ax, $0 ;", "=r,r,~{eax},~{edx},~{dirflag},~{fpsr},~{flags}"(i16 %4)
store i16 %5, i16* %3
%6 = load i16, i16* %3
ret i16 %6
}

LLVM IR (-O2):
define zeroext i16 @floor_log2_s_asm(i16 zeroext %0) {
%2 = tail call i16 asm "xorl %eax, %eax ;movw $1, %ax ;testw %ax, %ax ;je end_${:uid} ;movl %eax, %edx ;shrw %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw $$2, %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw $$4, %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw $$8, %dx ;orw %dx, %ax ;movw %ax, %dx ;shrw %dx ;andw $$0x5555, %dx ;subw %dx, %ax ;movw %ax, %dx ;andw $$0x3333, %dx ;shrw $$2, %ax ;andw $$0x3333, %ax ;addw %dx, %ax ;movw %ax, %dx ;shrw $$4, %dx ;addw %dx, %ax ;andw $$0x0f0f, %ax ;movw %ax, %dx ;shrw $$8, %dx ;addw %dx, %ax ;andw $$0x3f, %ax ;andw $$0x3f, %ax ;subw $$0x1, %ax ;end_${:uid}: ;mov %ax, $0 ;", "=r,r,~{eax},~{edx},~{dirflag},~{fpsr},~{flags}"(i16 %0)
ret i16 %2
}