#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 */

/* Variables and functions */
unsigned int spb_floorToPowerOfTwo(unsigned int a) {
  unsigned int result = 0;
  const size_t bit_count = 8 * sizeof(unsigned int);
  unsigned int highest_bit = 0x01u << (bit_count - 1);
  int i;
  for (i = 1; i <= bit_count; ++i) {
    if ((a >> (bit_count - i)) & 0x01u) {
      result = a & (highest_bit >> (i - 1));
      break;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<spb_floorToPowerOfTwo>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x20,-0x10(%rbp)
movl   $0x80000000,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x20,%rax
ja     117c <spb_floorToPowerOfTwo+0x7c>
mov    -0x4(%rbp),%eax
movslq -0x18(%rbp),%rdx
mov    $0x20,%ecx
sub    %rdx,%rcx
shr    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1169 <spb_floorToPowerOfTwo+0x69>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
shr    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    117c <spb_floorToPowerOfTwo+0x7c>
jmp    116e <spb_floorToPowerOfTwo+0x6e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1124 <spb_floorToPowerOfTwo+0x24>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<spb_floorToPowerOfTwo>:
mov    $0x1,%ecx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rax),%edx
movzbl %dl,%edx
bt     %edx,%edi
jb     1160 <spb_floorToPowerOfTwo+0x60>
mov    %edi,%edx
shl    %cl,%edx
test   $0x80000000,%edx
jne    114b <spb_floorToPowerOfTwo+0x4b>
lea    0x1d(%rax),%edx
movzbl %dl,%edx
bt     %edx,%edi
jb     1152 <spb_floorToPowerOfTwo+0x52>
lea    0x1c(%rax),%edx
movzbl %dl,%edx
bt     %edx,%edi
jb     1159 <spb_floorToPowerOfTwo+0x59>
add    $0x4,%ecx
add    $0xfffffffc,%eax
cmp    $0xffffffe0,%eax
jne    1110 <spb_floorToPowerOfTwo+0x10>
xor    %eax,%eax
ret
mov    $0x2,%ecx
jmp    115e <spb_floorToPowerOfTwo+0x5e>
mov    $0x3,%ecx
jmp    115e <spb_floorToPowerOfTwo+0x5e>
mov    $0x4,%ecx
sub    %eax,%ecx
add    $0xff,%cl
mov    $0x80000000,%eax
shr    %cl,%eax
and    %edi,%eax
ret

LLVM IR (-O0):
define i32 @spb_floorToPowerOfTwo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i64 32, i64* %4
store i32 -2147483648, i32* %5
store i32 1, i32* %6
br label %7
7: ; preds = %28, %1
%8 = load i32, i32* %6
%9 = sext i32 %8 to i64
%10 = icmp ule i64 %9, 32
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = sub i64 32, %14
%16 = trunc i64 %15 to i32
%17 = lshr i32 %12, %16
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %11
%21 = load i32, i32* %2
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
%25 = lshr i32 %22, %24
%26 = and i32 %21, %25
store i32 %26, i32* %3
br label %31
27: ; preds = %11
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %7
31: ; preds = %20, %7
%32 = load i32, i32* %3
ret i32 %32
}

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