#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 find_k(int, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char const *argv[]) {
  int iterations = 0;
  scanf("%d", &iterations);
  int menus[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
  int count = 0;
  int num = 0;
  int k = 0;
  for (int i = 0; i < iterations; ++i) {
    count = 0;
    scanf("%d", &num);
    for (int j = 0; j < 12; ++j) {
      if (menus[j] == num) {
        count = 1;
      }
    }
    if (count != 0) {
      printf("%d\n", count);
      continue;
    }
    while (num != 0) {
      k = find_k(num, menus);
      num -= k;
      count++;
    }
    printf("%d\n", count);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe9c(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x30,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126f <main+0x12f>
movl   $0x0,-0x54(%rbp)
lea    0xe48(%rip),%rdi
lea    -0x58(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xc,-0x64(%rbp)
jge    11fd <main+0xbd>
movslq -0x64(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
cmp    -0x58(%rbp),%eax
jne    11ea <main+0xaa>
movl   $0x1,-0x54(%rbp)
jmp    11ef <main+0xaf>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11c8 <main+0x88>
cmpl   $0x0,-0x54(%rbp)
je     121b <main+0xdb>
mov    -0x54(%rbp),%esi
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
jmp    1261 <main+0x121>
jmp    1220 <main+0xe0>
cmpl   $0x0,-0x58(%rbp)
je     1252 <main+0x112>
mov    -0x58(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1050 <find_k@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%ecx
mov    -0x58(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1220 <main+0xe0>
mov    -0x54(%rbp),%esi
lea    0xda7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    119e <main+0x5e>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x0,0xc(%rsp)
lea    0xeb3(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movdqa 0xe99(%rip),%xmm0
movdqa %xmm0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    125c <main+0x12c>
xor    %ebx,%ebx
lea    0xe67(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r13
lea    0xe59(%rip),%r12
jmp    11c7 <main+0x97>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jge    125c <main+0x12c>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%edi
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0x30(%rsp),%xmm1
pcmpeqd %xmm0,%xmm1
pcmpeqd 0x20(%rsp),%xmm0
pcmpeqd %xmm2,%xmm2
pxor   %xmm2,%xmm1
pxor   %xmm2,%xmm0
packssdw %xmm1,%xmm0
psllw  $0xf,%xmm0
packsswb %xmm0,%xmm0
pmovmskb %xmm0,%eax
mov    $0x1,%ebp
cmp    $0xff,%al
jne    11b0 <main+0x80>
cmp    %edi,0x1c(%rsp)
je     11b0 <main+0x80>
cmp    %edi,0x18(%rsp)
je     11b0 <main+0x80>
cmp    %edi,0x14(%rsp)
je     11b0 <main+0x80>
cmp    %edi,0x10(%rsp)
je     11b0 <main+0x80>
xor    %ebp,%ebp
test   %edi,%edi
je     11b0 <main+0x80>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rsi
call   1040 <find_k@plt>
mov    0x8(%rsp),%edi
add    $0x1,%ebp
sub    %eax,%edi
mov    %edi,0x8(%rsp)
jne    1240 <main+0x110>
jmp    11b0 <main+0x80>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@__const.main.menus = [12 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048]
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [12 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%14 = bitcast [12 x i32]* %7 to i8*
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %15
15: ; preds = %58, %2
%16 = load i32, i32* %11
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %61
19: ; preds = %15
store i32 0, i32* %8
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
store i32 0, i32* %12
br label %21
21: ; preds = %33, %19
%22 = load i32, i32* %12
%23 = icmp slt i32 %22, 12
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load i32, i32* %12
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [12 x i32], [12 x i32]* %7, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %9
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %8
br label %32
32: ; preds = %31, %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
br label %21
36: ; preds = %21
%37 = load i32, i32* %8
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %8
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %58
42: ; preds = %36
br label %43
43: ; preds = %46, %42
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %43
%47 = load i32, i32* %9
%48 = getelementptr inbounds [12 x i32], [12 x i32]* %7, i64 0, i64 0
%49 = call i32 @find_k(i32 %47, i32* %48)
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = load i32, i32* %9
%52 = sub nsw i32 %51, %50
store i32 %52, i32* %9
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %43
55: ; preds = %43
%56 = load i32, i32* %8
%57 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %39
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %15
61: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@__const.main.menus = [12 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048]
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [12 x i32]
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = bitcast [12 x i32]* %4 to i8*
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = getelementptr inbounds [12 x i32], [12 x i32]* %4, i64 0, i64 0
%14 = getelementptr inbounds [12 x i32], [12 x i32]* %4, i64 0, i64 1
%15 = getelementptr inbounds [12 x i32], [12 x i32]* %4, i64 0, i64 2
%16 = getelementptr inbounds [12 x i32], [12 x i32]* %4, i64 0, i64 3
%17 = getelementptr inbounds [12 x i32], [12 x i32]* %4, i64 0, i64 4
%18 = bitcast i32* %17 to <8 x i32>*
br label %20
19: ; preds = %53, %2
ret i32 0
20: ; preds = %12, %53
%21 = phi i32 [ 0, %12 ], [ %56, %53 ]
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%23 = load i32, i32* %5
%24 = load i32, i32* %13
%25 = icmp ne i32 %24, %23
%26 = load i32, i32* %14
%27 = icmp ne i32 %26, %23
%28 = load i32, i32* %15
%29 = icmp ne i32 %28, %23
%30 = load i32, i32* %16
%31 = icmp ne i32 %30, %23
%32 = load <8 x i32>, <8 x i32>* %18
%33 = insertelement <8 x i32> poison, i32 %23, i64 0
%34 = shufflevector <8 x i32> %33, <8 x i32> poison, <8 x i32> zeroinitializer
%35 = icmp ne <8 x i32> %32, %34
%36 = freeze <8 x i1> %35
%37 = bitcast <8 x i1> %36 to i8
%38 = icmp eq i8 %37, -1
%39 = select i1 %38, i1 %31, i1 false
%40 = select i1 %39, i1 %29, i1 false
%41 = select i1 %40, i1 %27, i1 false
%42 = select i1 %41, i1 %25, i1 false
br i1 %42, label %43, label %53
43: ; preds = %20
%44 = icmp eq i32 %23, 0
br i1 %44, label %53, label %45
45: ; preds = %43, %45
%46 = phi i32 [ %51, %45 ], [ 0, %43 ]
%47 = phi i32 [ %50, %45 ], [ %23, %43 ]
%48 = call i32 @find_k(i32 %47, i32* %13)
%49 = load i32, i32* %5
%50 = sub nsw i32 %49, %48
store i32 %50, i32* %5
%51 = add nuw nsw i32 %46, 1
%52 = icmp eq i32 %50, 0
br i1 %52, label %53, label %45
53: ; preds = %45, %43, %20
%54 = phi i32 [ 1, %20 ], [ 0, %43 ], [ %51, %45 ]
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = add nuw nsw i32 %21, 1
%57 = load i32, i32* %3
%58 = icmp slt i32 %56, %57
br i1 %58, label %20, label %19
}