#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int nth_position(int /*<<< orphan*/, int);
int /*<<< orphan*/ set_bit(int /*<<< orphan*/ *, int, int);
uint32_t extrakt_even_bits(uint32_t number) {
  int i, evenBitPos = 0;
  uint32_t evenBitExtrakted = 0;
  for (i = 0; i < 32; i++) {
    if (!(i % 2 == 0)) {
      bool currentBit = nth_position(number, i);
      if (currentBit) {
        set_bit(&evenBitExtrakted, evenBitPos, currentBit);
      }
      evenBitPos++;
    }
  }
  return evenBitExtrakted;
}


x86 assembly (clang, -O0):
<extrakt_even_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    11a1 <extrakt_even_bits+0x81>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     118e <extrakt_even_bits+0x6e>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <nth_position@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1185 <extrakt_even_bits+0x65>
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    -0x10(%rbp),%rdi
call   1030 <set_bit@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1193 <extrakt_even_bits+0x73>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1140 <extrakt_even_bits+0x20>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extrakt_even_bits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
movl   $0x0,0x4(%rsp)
xor    %ebp,%ebp
lea    0x4(%rsp),%r14
xor    %ebx,%ebx
jmp    114b <extrakt_even_bits+0x2b>
nopl   (%rax)
add    $0x1,%ebx
add    $0x1,%ebp
cmp    $0x20,%ebp
je     116d <extrakt_even_bits+0x4d>
test   $0x1,%bpl
je     1143 <extrakt_even_bits+0x23>
mov    %r15d,%edi
mov    %ebp,%esi
call   1040 <nth_position@plt>
test   %eax,%eax
je     1140 <extrakt_even_bits+0x20>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <set_bit@plt>
jmp    1140 <extrakt_even_bits+0x20>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @extrakt_even_bits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %3
br label %7
7: ; preds = %28, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 32
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = load i32, i32* %3
%12 = srem i32 %11, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %10
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i32 @nth_position(i32 %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32, i32* %4
%22 = load i32, i32* %6
%23 = call i32 @set_bit(i32* %5, i32 %21, i32 %22)
br label %24
24: ; preds = %20, %14
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %27
27: ; preds = %24, %10
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %7
31: ; preds = %7
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @extrakt_even_bits(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %1, %16
%5 = phi i32 [ 0, %1 ], [ %18, %16 ]
%6 = phi i32 [ 0, %1 ], [ %17, %16 ]
%7 = and i32 %5, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = call i32 @nth_position(i32 %0, i32 %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @set_bit(i32* %2, i32 %6, i32 %10)
br label %14
14: ; preds = %12, %9
%15 = add nsw i32 %6, 1
br label %16
16: ; preds = %4, %14
%17 = phi i32 [ %6, %4 ], [ %15, %14 ]
%18 = add nuw nsw i32 %5, 1
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %4
20: ; preds = %16
%21 = load i32, i32* %2
ret i32 %21
}