#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 pow(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int x, result, count = 0;
  scanf("%d", &x);
  for (; x > 0;) {
    for (int n = 0; pow(2, n) <= x; n++)
      result = pow(2, n);
    count++;
    x = x - result;
  }
  printf("%d", count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11b2 <main+0x82>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    $0x2,%edi
call   1050 <pow@plt>
cmp    -0x8(%rbp),%eax
jg     119b <main+0x6b>
mov    -0x14(%rbp),%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1167 <main+0x37>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x26>
mov    -0x10(%rbp),%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11b7 <main+0x87>
xor    %r14d,%r14d
jmp    116c <main+0x3c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14d
sub    %ebp,%ecx
mov    %ecx,0xc(%rsp)
jle    11ba <main+0x8a>
mov    $0x2,%edi
xor    %esi,%esi
call   1050 <pow@plt>
mov    0xc(%rsp),%ecx
cmp    %ecx,%eax
jg     1160 <main+0x30>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2,%edi
mov    %ebx,%esi
call   1050 <pow@plt>
mov    %eax,%ebp
add    $0x1,%ebx
mov    $0x2,%edi
mov    %ebx,%esi
call   1050 <pow@plt>
mov    0xc(%rsp),%ecx
cmp    %ecx,%eax
jle    1190 <main+0x60>
jmp    1160 <main+0x30>
xor    %r14d,%r14d
lea    0xe3f(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %0, %12
%7 = phi i32 [ %15, %12 ], [ 0, %0 ]
%8 = phi i32 [ %13, %12 ], [ undef, %0 ]
%9 = call i32 @pow(i32 2, i32 0)
%10 = load i32, i32* %1
%11 = icmp sgt i32 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %18, %6
%13 = phi i32 [ %8, %6 ], [ %20, %18 ]
%14 = phi i32 [ %10, %6 ], [ %23, %18 ]
%15 = add nuw nsw i32 %7, 1
%16 = sub nsw i32 %14, %13
store i32 %16, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %6, label %25
18: ; preds = %6, %18
%19 = phi i32 [ %21, %18 ], [ 0, %6 ]
%20 = call i32 @pow(i32 2, i32 %19)
%21 = add nuw nsw i32 %19, 1
%22 = call i32 @pow(i32 2, i32 %21)
%23 = load i32, i32* %1
%24 = icmp sgt i32 %22, %23
br i1 %24, label %12, label %18
25: ; preds = %12, %0
%26 = phi i32 [ 0, %0 ], [ %15, %12 ]
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26)
ret i32 0
}