#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 */
long pow(int, short);
int /*<<< orphan*/ printf(char *, short);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  short int t, i, min_items;
  long price;
  scanf("%d", &t);
  while (t--) {
    scanf("%ld", &price);
    min_items = 0;
    while (price != 0) {
      i = 0;
      while (price >= pow(2, i) && i < 12) {
        i++;
      }
      i -= 1;
      price -= pow(2, i);
      min_items++;
    }
    printf("%d\n", min_items);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x6(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x6(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x6(%rbp)
cmp    $0x0,%ax
je     1239 <main+0x109>
lea    0xe92(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movw   $0x0,-0xa(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1224 <main+0xf4>
movw   $0x0,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x2,%edi
movswl -0x8(%rbp),%esi
call   1050 <pow@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x19(%rbp)
jl     11cb <main+0x9b>
movswl -0x8(%rbp),%eax
cmp    $0xc,%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11db <main+0xab>
jmp    11ec <main+0xbc>
mov    -0x8(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x8(%rbp)
jmp    1193 <main+0x63>
movswl -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %ax,-0x8(%rbp)
mov    $0x2,%edi
movswl -0x8(%rbp),%esi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xa(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xa(%rbp)
jmp    1182 <main+0x52>
lea    0xddc(%rip),%rdi
movswl -0xa(%rbp),%esi
call   1030 <printf@plt>
jmp    1151 <main+0x21>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xebb(%rip),%rdi
lea    0xe(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subw   $0x1,0xe(%rsp)
jae    116a <main+0x3a>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r15
lea    0xe91(%rip),%r12
jmp    1194 <main+0x64>
nopl   0x0(%rax,%rax,1)
movswl %r13w,%esi
mov    %r12,%rdi
call   1030 <printf@plt>
subw   $0x1,0xe(%rsp)
jb     1159 <main+0x29>
xor    %r13d,%r13d
lea    0xe65(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rbp
test   %rbp,%rbp
je     1180 <main+0x50>
xor    %r13d,%r13d
jmp    11e3 <main+0xb3>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
movswl %bx,%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    0x10(%rsp),%rbp
add    $0x1,%r13d
sub    %rax,%rbp
mov    %rbp,0x10(%rsp)
je     1180 <main+0x50>
xor    %ebx,%ebx
mov    $0x2,%edi
xor    %esi,%esi
call   1050 <pow@plt>
cmp    %rax,%rbp
jl     11c0 <main+0x90>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%r14d
lea    0x1(%r14),%ebx
mov    0x10(%rsp),%rbp
movswl %bx,%esi
mov    $0x2,%edi
call   1050 <pow@plt>
cmp    $0xa,%r14w
ja     11c0 <main+0x90>
cmp    %rax,%rbp
jge    1200 <main+0xd0>
jmp    11c0 <main+0x90>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i16
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i16* %2)
br label %7
7: ; preds = %42, %0
%8 = load i16, i16* %2
%9 = add i16 %8, -1
store i16 %9, i16* %2
%10 = icmp ne i16 %8, 0
br i1 %10, label %11, label %45
11: ; preds = %7
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %5)
store i16 0, i16* %4
br label %13
13: ; preds = %31, %11
%14 = load i64, i64* %5
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %42
16: ; preds = %13
store i16 0, i16* %3
br label %17
17: ; preds = %28, %16
%18 = load i64, i64* %5
%19 = load i16, i16* %3
%20 = call i64 @pow(i32 2, i16 signext %19)
%21 = icmp sge i64 %18, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i16, i16* %3
%24 = sext i16 %23 to i32
%25 = icmp slt i32 %24, 12
br label %26
26: ; preds = %22, %17
%27 = phi i1 [ false, %17 ], [ %25, %22 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i16, i16* %3
%30 = add i16 %29, 1
store i16 %30, i16* %3
br label %17
31: ; preds = %26
%32 = load i16, i16* %3
%33 = sext i16 %32 to i32
%34 = sub nsw i32 %33, 1
%35 = trunc i32 %34 to i16
store i16 %35, i16* %3
%36 = load i16, i16* %3
%37 = call i64 @pow(i32 2, i16 signext %36)
%38 = load i64, i64* %5
%39 = sub nsw i64 %38, %37
store i64 %39, i64* %5
%40 = load i16, i16* %4
%41 = add i16 %40, 1
store i16 %41, i16* %4
br label %13
42: ; preds = %13
%43 = load i16, i16* %4
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16 signext %43)
br label %7
45: ; preds = %7
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = alloca i64
%3 = bitcast i16* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i16* %1)
%6 = load i16, i16* %1
%7 = add i16 %6, -1
store i16 %7, i16* %1
%8 = icmp eq i16 %6, 0
br i1 %8, label %40, label %9
9: ; preds = %0, %34
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%11 = load i64, i64* %2
%12 = icmp eq i64 %11, 0
br i1 %12, label %34, label %13
13: ; preds = %9, %26
%14 = phi i64 [ %31, %26 ], [ %11, %9 ]
%15 = phi i16 [ %32, %26 ], [ 0, %9 ]
%16 = call i64 @pow(i32 2, i16 signext 0)
%17 = icmp slt i64 %14, %16
br i1 %17, label %26, label %18
18: ; preds = %13, %18
%19 = phi i16 [ %20, %18 ], [ 0, %13 ]
%20 = add nuw nsw i16 %19, 1
%21 = load i64, i64* %2
%22 = call i64 @pow(i32 2, i16 signext %20)
%23 = icmp sge i64 %21, %22
%24 = icmp ult i16 %19, 11
%25 = and i1 %24, %23
br i1 %25, label %18, label %26
26: ; preds = %18, %13
%27 = phi i16 [ 0, %13 ], [ %20, %18 ]
%28 = add nsw i16 %27, -1
%29 = call i64 @pow(i32 2, i16 signext %28)
%30 = load i64, i64* %2
%31 = sub nsw i64 %30, %29
store i64 %31, i64* %2
%32 = add i16 %15, 1
%33 = icmp eq i64 %31, 0
br i1 %33, label %34, label %13
34: ; preds = %26, %9
%35 = phi i16 [ 0, %9 ], [ %32, %26 ]
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16 signext %35)
%37 = load i16, i16* %1
%38 = add i16 %37, -1
store i16 %38, i16* %1
%39 = icmp eq i16 %37, 0
br i1 %39, label %40, label %9
40: ; preds = %34, %0
ret i32 0
}