#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*/ printf(char *, int);
char number_of_bits_in_int_wrong(int value) {
  char bits = 0;
  while (value != 0) {
    printf("value is %d\n", value);
    if (value & 1) {
      bits += 1;
    }
    value >>= 1;
  }
  return bits;
}


x86 assembly (clang, -O0):
<number_of_bits_in_int_wrong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     115f <number_of_bits_in_int_wrong+0x4f>
mov    -0x4(%rbp),%esi
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1151 <number_of_bits_in_int_wrong+0x41>
movsbl -0x5(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <number_of_bits_in_int_wrong+0xf>
movsbl -0x5(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_of_bits_in_int_wrong>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     114c <number_of_bits_in_int_wrong+0x3c>
mov    %edi,%ebx
xor    %r15d,%r15d
lea    0xed9(%rip),%r14
mov    %edi,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
and    $0x1,%al
add    %al,%r15b
sar    %ebp
cmp    $0x1,%ebx
mov    %ebp,%ebx
ja     1130 <number_of_bits_in_int_wrong+0x20>
jmp    114f <number_of_bits_in_int_wrong+0x3f>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"value is %d\0A\00"
define signext i8 @number_of_bits_in_int_wrong(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
store i8 0, i8* %3
br label %4
4: ; preds = %18, %1
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %2
%11 = and i32 %10, 1
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = add nsw i32 %15, 1
%17 = trunc i32 %16 to i8
store i8 %17, i8* %3
br label %18
18: ; preds = %13, %7
%19 = load i32, i32* %2
%20 = ashr i32 %19, 1
store i32 %20, i32* %2
br label %4
21: ; preds = %4
%22 = load i8, i8* %3
ret i8 %22
}

LLVM IR (-O2):
@.str = [13 x i8] c"value is %d\0A\00"
define signext i8 @number_of_bits_in_int_wrong(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1, %3
%4 = phi i8 [ %9, %3 ], [ 0, %1 ]
%5 = phi i32 [ %10, %3 ], [ %0, %1 ]
%6 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = trunc i32 %5 to i8
%8 = and i8 %7, 1
%9 = add i8 %8, %4
%10 = ashr i32 %5, 1
%11 = icmp ult i32 %5, 2
br i1 %11, label %12, label %3
12: ; preds = %3, %1
%13 = phi i8 [ 0, %1 ], [ %9, %3 ]
ret i8 %13
}