#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int int32_t;

/* Variables and functions */
unsigned int nul_byte_index_b32(unsigned int mask) {
  int32_t a;
  mask |= mask >> 1;
  mask |= mask >> 2;
  mask |= mask >> 4;
  mask |= mask >> 8;
  mask |= mask >> 16;
  mask >>= 8;
  a = 0x0ff4000 + mask;
  a >>= 23;
  return 3 - (a & mask);
}


x86 assembly (clang, -O0):
<nul_byte_index_b32>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x2,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xff4000,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x17,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
and    -0x4(%rbp),%ecx
mov    $0x3,%eax
sub    %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<nul_byte_index_b32>:
mov    %edi,%eax
shr    %eax
or     %edi,%eax
mov    %eax,%ecx
shr    $0x2,%ecx
or     %eax,%ecx
mov    %ecx,%edx
shr    $0x4,%edx
or     %ecx,%edx
mov    %edx,%eax
shr    $0x18,%eax
mov    %edx,%ecx
shr    $0x10,%ecx
shr    $0x8,%edx
or     %ecx,%edx
or     %eax,%edx
lea    0xff4000(%rdx),%eax
shr    $0x17,%eax
and    %edx,%eax
xor    $0x3,%eax
ret

LLVM IR (-O0):
define i32 @nul_byte_index_b32(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = lshr i32 %4, 1
%6 = load i32, i32* %2
%7 = or i32 %6, %5
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = lshr i32 %8, 2
%10 = load i32, i32* %2
%11 = or i32 %10, %9
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = lshr i32 %12, 4
%14 = load i32, i32* %2
%15 = or i32 %14, %13
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = lshr i32 %16, 8
%18 = load i32, i32* %2
%19 = or i32 %18, %17
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = lshr i32 %20, 16
%22 = load i32, i32* %2
%23 = or i32 %22, %21
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = lshr i32 %24, 8
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = add i32 16728064, %26
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = ashr i32 %28, 23
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = load i32, i32* %2
%32 = and i32 %30, %31
%33 = sub i32 3, %32
ret i32 %33
}

LLVM IR (-O2):
define i32 @nul_byte_index_b32(i32 %0) {
%2 = lshr i32 %0, 1
%3 = or i32 %2, %0
%4 = lshr i32 %3, 2
%5 = or i32 %4, %3
%6 = lshr i32 %5, 4
%7 = or i32 %6, %5
%8 = lshr i32 %7, 24
%9 = lshr i32 %7, 16
%10 = lshr i32 %7, 8
%11 = or i32 %9, %10
%12 = or i32 %11, %8
%13 = add nuw nsw i32 %12, 16728064
%14 = lshr i32 %13, 23
%15 = and i32 %14, %12
%16 = xor i32 %15, 3
ret i32 %16
}