#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 */
int /*<<< orphan*/ printabit(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int, unsigned int);
unsigned int random();
int main() {
  unsigned int i, j, map, ones, x;
  for (i = 0; i < 10; i++) {
    x = random();
    map = 1;
    ones = 0;
    for (j = 0; j < 32; j++) {
      if (x & map)
        ones++;
      map <<= 1;
    }
    printabit(x);
    printf("  %10d, %x has %d 1s \n", x, x, ones);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jae    11d3 <main+0xa3>
mov    $0x0,%al
call   1050 <random@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jae    11a8 <main+0x78>
mov    -0x18(%rbp),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
je     1191 <main+0x61>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <main+0x3f>
mov    -0x18(%rbp),%edi
call   1040 <printabit@plt>
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <random@plt>
mov    %eax,%ebp
mov    $0x1,%eax
mov    $0x20,%ecx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edx
and    %ebp,%edx
cmp    $0x1,%edx
sbb    $0xffffffff,%ebx
lea    (%rax,%rax,1),%edx
and    %ebp,%edx
cmp    $0x1,%edx
sbb    $0xffffffff,%ebx
lea    0x0(,%rax,4),%edx
and    %ebp,%edx
cmp    $0x1,%edx
sbb    $0xffffffff,%ebx
lea    0x0(,%rax,8),%edx
and    %ebp,%edx
cmp    $0x1,%edx
sbb    $0xffffffff,%ebx
shl    $0x4,%eax
add    $0xfffffffc,%ecx
jne    1170 <main+0x40>
mov    %ebp,%edi
call   1040 <printabit@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <printf@plt>
add    $0x1,%r15d
cmp    $0xa,%r15d
jne    1150 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c" %10d, %x has %d 1s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %7
7: ; preds = %36, %0
%8 = load i32, i32* %2
%9 = icmp ult i32 %8, 10
br i1 %9, label %10, label %39
10: ; preds = %7
%11 = call i32 (...) @random()
store i32 %11, i32* %6
store i32 1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %3
br label %12
12: ; preds = %26, %10
%13 = load i32, i32* %3
%14 = icmp ult i32 %13, 32
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = and i32 %16, %17
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %5
%22 = add i32 %21, 1
store i32 %22, i32* %5
br label %23
23: ; preds = %20, %15
%24 = load i32, i32* %4
%25 = shl i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %23
%27 = load i32, i32* %3
%28 = add i32 %27, 1
store i32 %28, i32* %3
br label %12
29: ; preds = %12
%30 = load i32, i32* %6
%31 = call i32 @printabit(i32 %30)
%32 = load i32, i32* %6
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %33, i32 %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %2
%38 = add i32 %37, 1
store i32 %38, i32* %2
br label %7
39: ; preds = %7
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [23 x i8] c" %10d, %x has %d 1s \0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %30
%2 = phi i32 [ 0, %0 ], [ %33, %30 ]
%3 = tail call i32 (...) @random()
br label %4
4: ; preds = %4, %1
%5 = phi i32 [ 0, %1 ], [ %26, %4 ]
%6 = phi i32 [ 1, %1 ], [ %27, %4 ]
%7 = phi i32 [ 0, %1 ], [ %28, %4 ]
%8 = and i32 %6, %3
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i32
%11 = add i32 %5, %10
%12 = shl i32 %6, 1
%13 = and i32 %12, %3
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
%16 = add i32 %11, %15
%17 = shl i32 %6, 2
%18 = and i32 %17, %3
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i32
%21 = add i32 %16, %20
%22 = shl i32 %6, 3
%23 = and i32 %22, %3
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i32
%26 = add i32 %21, %25
%27 = shl i32 %6, 4
%28 = add nuw nsw i32 %7, 4
%29 = icmp eq i32 %28, 32
br i1 %29, label %30, label %4
30: ; preds = %4
%31 = tail call i32 @printabit(i32 %3)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %3, i32 %26)
%33 = add nuw nsw i32 %2, 1
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %1
35: ; preds = %30
ret i32 0
}