int _gcry_ctz(unsigned int x) {
  static const unsigned char mod37[] = {sizeof(unsigned int) * 8,
                                        0,
                                        1,
                                        26,
                                        2,
                                        23,
                                        27,
                                        0,
                                        3,
                                        16,
                                        24,
                                        30,
                                        28,
                                        11,
                                        0,
                                        13,
                                        4,
                                        7,
                                        17,
                                        0,
                                        25,
                                        22,
                                        31,
                                        15,
                                        29,
                                        10,
                                        12,
                                        6,
                                        0,
                                        21,
                                        14,
                                        9,
                                        5,
                                        20,
                                        8,
                                        19,
                                        18};
  return (int)mod37[(-x & x) % 37];
}


x86 assembly (clang, -O0):
<_gcry_ctz>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
sub    -0x4(%rbp),%eax
and    -0x4(%rbp),%eax
mov    $0x25,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
mov    %eax,%ecx
lea    0xedd(%rip),%rax
movzbl (%rax,%rcx,1),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gcry_ctz>:
mov    %edi,%eax
neg    %eax
and    %edi,%eax
mov    $0xbacf914d,%ecx
imul   %rax,%rcx
shr    $0x20,%rcx
mov    %eax,%edx
sub    %ecx,%edx
shr    %edx
add    %ecx,%edx
shr    $0x5,%edx
lea    (%rdx,%rdx,8),%ecx
lea    (%rdx,%rcx,4),%ecx
sub    %ecx,%eax
lea    0xed3(%rip),%rcx
movzbl (%rax,%rcx,1),%eax
ret

LLVM IR (-O0):
@_gcry_ctz.mod37 = internal constant [37 x i8] c" \00\01\1A\02\17\1B\00\03\10\18\1E\1C\0B\00\0D\04\07\11\00\19\16\1F\0F\1D\0A\0C\06\00\15\0E\09\05\14\08\13\12"
define i32 @_gcry_ctz(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = sub i32 0, %3
%5 = load i32, i32* %2
%6 = and i32 %4, %5
%7 = urem i32 %6, 37
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds [37 x i8], [37 x i8]* @_gcry_ctz.mod37, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
ret i32 %11
}

LLVM IR (-O2):
@_gcry_ctz.mod37 = internal unnamed_addr constant [37 x i8] c" \00\01\1A\02\17\1B\00\03\10\18\1E\1C\0B\00\0D\04\07\11\00\19\16\1F\0F\1D\0A\0C\06\00\15\0E\09\05\14\08\13\12"
define i32 @_gcry_ctz(i32 %0) {
%2 = sub i32 0, %0
%3 = and i32 %2, %0
%4 = urem i32 %3, 37
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds [37 x i8], [37 x i8]* @_gcry_ctz.mod37, i64 0, i64 %5
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
ret i32 %8
}