#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 */
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, int, unsigned int);
int main(void) {
  int i = 0;
  unsigned int masks[4];
  masks[0] = 0x5555;
  masks[1] = 0x3333;
  masks[2] = 0x0F0F;
  masks[3] = 0x00FF;
  unsigned int running_sum = 0x1111;
  unsigned int x1 = 0;
  unsigned int x2 = 0;
  for (i = 0; i < 4; i++) {
    x1 = running_sum & masks[i];
    x2 = (running_sum >> (unsigned int)pow(2, i)) & masks[i];
    running_sum = x1 + x2;
  }
  printf("%04X has %d bits set.\n", 0x1111, running_sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x5555,-0x20(%rbp)
movl   $0x3333,-0x1c(%rbp)
movl   $0xf0f,-0x18(%rbp)
movl   $0xff,-0x14(%rbp)
movl   $0x1111,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11c3 <main+0xa3>
mov    -0x24(%rbp),%eax
movslq -0x8(%rbp),%rcx
and    -0x20(%rbp,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%eax
shr    %cl,%eax
movslq -0x8(%rbp),%rcx
and    -0x20(%rbp,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116e <main+0x4e>
mov    -0x24(%rbp),%edx
lea    0xe33(%rip),%rdi
mov    $0x1111,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x2,%edi
xor    %esi,%esi
call   1040 <pow@plt>
mov    $0x1111,%ebx
mov    %eax,%ecx
shr    %cl,%ebx
and    $0x1555,%ebx
add    $0x1111,%ebx
mov    %ebx,%ebp
and    $0x3333,%ebp
mov    $0x2,%edi
mov    $0x1,%esi
call   1040 <pow@plt>
mov    %eax,%ecx
shr    %cl,%ebx
and    $0x3333,%ebx
add    %ebp,%ebx
mov    %ebx,%ebp
and    $0x707,%ebp
mov    $0x2,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %eax,%ecx
shr    %cl,%ebx
and    $0xf0f,%ebx
add    %ebp,%ebx
movzbl %bl,%ebp
mov    $0x2,%edi
mov    $0x3,%esi
call   1040 <pow@plt>
mov    %eax,%ecx
shr    %cl,%ebx
movzbl %bl,%edx
add    %ebp,%edx
lea    0xe54(%rip),%rdi
mov    $0x1111,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"%04X has %d bits set.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
store i32 21845, i32* %7
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
store i32 13107, i32* %8
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
store i32 3855, i32* %9
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
store i32 255, i32* %10
store i32 4369, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %2
br label %11
11: ; preds = %34, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = and i32 %15, %19
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = load i32, i32* %2
%23 = call i64 @pow(i32 2, i32 %22)
%24 = trunc i64 %23 to i32
%25 = lshr i32 %21, %24
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = and i32 %25, %29
store i32 %30, i32* %6
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = add i32 %31, %32
store i32 %33, i32* %4
br label %34
34: ; preds = %14
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %11
37: ; preds = %11
%38 = load i32, i32* %4
%39 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 4369, i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"%04X has %d bits set.\0A\00"
define i32 @main() {
%1 = tail call i64 @pow(i32 2, i32 0)
%2 = trunc i64 %1 to i32
%3 = lshr i32 4369, %2
%4 = and i32 %3, 5461
%5 = add nuw nsw i32 %4, 4369
%6 = and i32 %5, 13107
%7 = tail call i64 @pow(i32 2, i32 1)
%8 = trunc i64 %7 to i32
%9 = lshr i32 %5, %8
%10 = and i32 %9, 13107
%11 = add nuw nsw i32 %10, %6
%12 = and i32 %11, 1799
%13 = tail call i64 @pow(i32 2, i32 2)
%14 = trunc i64 %13 to i32
%15 = lshr i32 %11, %14
%16 = and i32 %15, 3855
%17 = add nuw nsw i32 %16, %12
%18 = and i32 %17, 31
%19 = tail call i64 @pow(i32 2, i32 3)
%20 = trunc i64 %19 to i32
%21 = lshr i32 %17, %20
%22 = and i32 %21, 255
%23 = add nuw nsw i32 %22, %18
%24 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 4369, i32 %23)
ret i32 0
}