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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xf4240,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    117e <main+0x5e>
mov    -0x24(%rbp),%edi
call   1040 <int_to_bits_alt@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114f <main+0x2f>
mov    -0x20(%rbp),%esi
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <int_to_bits_alt@plt>
add    %eax,%ebx
add    $0x1,%ebp
cmp    $0xf4240,%ebp
jne    1130 <main+0x10>
lea    0xeb5(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 1000000, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %22, %3
%12 = load i32, i32* %10
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %10
%17 = call i64 @int_to_bits_alt(i32 %16)
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %9
br label %22
22: ; preds = %15
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
store i32 %24, i32* %10
br label %11
25: ; preds = %11
%26 = load i32, i32* %9
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}

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) {
br label %7
4: ; preds = %7
%5 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12)
%6 = load i32, i32* @EXIT_SUCCESS
ret i32 %6
7: ; preds = %3, %7
%8 = phi i32 [ 0, %3 ], [ %13, %7 ]
%9 = phi i32 [ 0, %3 ], [ %12, %7 ]
%10 = tail call i64 @int_to_bits_alt(i32 %8)
%11 = trunc i64 %10 to i32
%12 = add i32 %9, %11
%13 = add nuw nsw i32 %8, 1
%14 = icmp eq i32 %13, 1000000
br i1 %14, label %4, label %7
}