#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 EXIT_SUCCESS;
char int_to_bits_alt(int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv, char **envp) {
  char table[256 * 256];
  for (int i = 0; i < 256 * 256; i++) {
    table[i] = int_to_bits_alt(i);
  }
  int max = 1000000;
  int bits = 0;
  for (int i = 0; i < max; i++) {
    unsigned short *p = (unsigned short *)&i;
    bits += table[(int)*p];
    p++;
    bits += table[(int)*p];
  }
  printf("bits is %d\n", bits);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x10024(%rbp)
cmpl   $0x10000,-0x10024(%rbp)
jge    1186 <main+0x66>
mov    -0x10024(%rbp),%edi
call   1040 <int_to_bits_alt@plt>
mov    %al,%cl
movslq -0x10024(%rbp),%rax
mov    %cl,-0x10020(%rbp,%rax,1)
mov    -0x10024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10024(%rbp)
jmp    1147 <main+0x27>
movl   $0xf4240,-0x10028(%rbp)
movl   $0x0,-0x1002c(%rbp)
movl   $0x0,-0x10030(%rbp)
mov    -0x10030(%rbp),%eax
cmp    -0x10028(%rbp),%eax
jge    122a <main+0x10a>
lea    -0x10030(%rbp),%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10038(%rbp),%rax
movzwl (%rax),%eax
cltq
movsbl -0x10020(%rbp,%rax,1),%eax
ff
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x10038(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10038(%rbp),%rax
movzwl (%rax),%eax
cltq
movsbl -0x10020(%rbp,%rax,1),%eax
ff
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x10030(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10030(%rbp)
jmp    11a4 <main+0x84>
mov    -0x1002c(%rbp),%esi
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10000,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <int_to_bits_alt@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x10000,%rbx
jne    1130 <main+0x10>
xor    %eax,%eax
xor    %edx,%edx
xor    %esi,%esi
xor    %ecx,%ecx
nop
mov    %edx,%edx
movsbl (%rsp,%rdx,1),%edx
add    %esi,%edx
mov    %ecx,%ecx
movsbl (%rsp,%rcx,1),%ecx
add    %edx,%ecx
mov    %eax,%edx
shr    $0x10,%rdx
mov    %eax,%esi
and    $0xfffe,%esi
movsbl 0x1(%rsp,%rsi,1),%edi
add    %ecx,%edi
movsbl (%rsp,%rdx,1),%esi
add    %edi,%esi
add    $0x2,%eax
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %eax,%edx
and    $0xfffe,%edx
cmp    $0xf4240,%eax
jne    1150 <main+0x30>
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
add    $0x10000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"bits is %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [65536 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i16*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %9
br label %14
14: ; preds = %23, %3
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 65536
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* %9
%19 = call signext i8 @int_to_bits_alt(i32 %18)
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 %21
store i8 %19, i8* %22
br label %23
23: ; preds = %17
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
store i32 %25, i32* %9
br label %14
26: ; preds = %14
store i32 1000000, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %27
27: ; preds = %53, %26
%28 = load i32, i32* %12
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %56
31: ; preds = %27
%32 = bitcast i32* %12 to i16*
store i16* %32, i16** %13
%33 = load i16*, i16** %13
%34 = load i16, i16* %33
%35 = zext i16 %34 to i32
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = load i32, i32* %11
%41 = add nsw i32 %40, %39
store i32 %41, i32* %11
%42 = load i16*, i16** %13
%43 = getelementptr inbounds i16, i16* %42, i32 1
store i16* %43, i16** %13
%44 = load i16*, i16** %13
%45 = load i16, i16* %44
%46 = zext i16 %45 to i32
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = load i32, i32* %11
%52 = add nsw i32 %51, %50
store i32 %52, i32* %11
br label %53
53: ; preds = %31
%54 = load i32, i32* %12
%55 = add nsw i32 %54, 1
store i32 %55, i32* %12
br label %27
56: ; preds = %27
%57 = load i32, i32* %11
%58 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}

LLVM IR (-O2):
@.str = [12 x i8] c"bits is %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [65536 x i8]
%5 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
br label %6
6: ; preds = %3, %6
%7 = phi i64 [ 0, %3 ], [ %11, %6 ]
%8 = trunc i64 %7 to i32
%9 = tail call signext i8 @int_to_bits_alt(i32 %8)
%10 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %7
store i8 %9, i8* %10
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, 65536
br i1 %12, label %16, label %6
13: ; preds = %16
%14 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %43)
%15 = load i32, i32* @EXIT_SUCCESS
ret i32 %15
16: ; preds = %6, %16
%17 = phi i32 [ %44, %16 ], [ 0, %6 ]
%18 = phi i32 [ %46, %16 ], [ 0, %6 ]
%19 = phi i32 [ %43, %16 ], [ 0, %6 ]
%20 = phi i32 [ %45, %16 ], [ 0, %6 ]
%21 = zext i32 %18 to i64
%22 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = add nsw i32 %19, %24
%26 = zext i32 %20 to i64
%27 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = add nsw i32 %25, %29
%31 = lshr i32 %17, 16
%32 = and i32 %17, 65534
%33 = or i32 %32, 1
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = add nsw i32 %30, %37
%39 = zext i32 %31 to i64
%40 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = add nsw i32 %38, %42
%44 = add nuw nsw i32 %17, 2
%45 = lshr i32 %44, 16
%46 = and i32 %44, 65534
%47 = icmp eq i32 %44, 1000000
br i1 %47, label %13, label %16
}