#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int main(int argc, char *argv[]) {
  unsigned int integer = atoi(argv[1]);
  int num = 0;
  while (integer != 0) {
    if (integer % 2 == 1) {
      num++;
    }
    integer = integer >> 1;
  }
  printf("%s has %d  1-bit\n", argv[1], num);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117d <main+0x5d>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    116f <main+0x4f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <main+0x2d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%edx
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <atoi@plt>
xor    %edx,%edx
test   %eax,%eax
je     1150 <main+0x30>
mov    %eax,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%esi
and    $0x1,%esi
add    %esi,%edx
shr    %ecx
cmp    $0x1,%eax
mov    %ecx,%eax
ja     1140 <main+0x20>
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"%s has %d 1-bit\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2, %7
%8 = phi i32 [ %11, %7 ], [ 0, %2 ]
%9 = phi i32 [ %12, %7 ], [ %5, %2 ]
%10 = and i32 %9, 1
%11 = add nuw nsw i32 %8, %10
%12 = lshr i32 %9, 1
%13 = icmp ult i32 %9, 2
br i1 %13, label %14, label %7
14: ; preds = %7, %2
%15 = phi i32 [ 0, %2 ], [ %11, %7 ]
%16 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %15)
ret i32 0
}