#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 *, long long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int T, i, sum;
  long long N;
  scanf("%d", &T);
  while (T--) {
    sum = 0;
    scanf("%lld", &N);
    for (i = 1; i <= N / 2; i++) {
      if (N % i == 0) {
        sum = sum + i;
      }
    }
    if (sum == N)
      printf("YES, %d is a perfect number!\n", N);
    else
      printf("NO, %d is not a perfect number!\n", N);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1206 <main+0xe6>
movl   $0x0,-0x10(%rbp)
lea    0xea0(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jg     11ce <main+0xae>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11bb <main+0x9b>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11c0 <main+0xa0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <main+0x55>
movslq -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11f1 <main+0xd1>
mov    -0x18(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
jmp    1201 <main+0xe1>
mov    -0x18(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%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    0xecb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    1159 <main+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea3(%rip),%r14
lea    0x10(%rsp),%r13
lea    0xe9c(%rip),%r12
lea    0xeb3(%rip),%r15
jmp    11a4 <main+0x84>
mov    %rsi,%rax
cqto
idiv   %rcx
test   %rdx,%rdx
mov    $0x0,%eax
cmovne %eax,%ecx
add    %ebx,%ecx
mov    %ecx,%ebx
mov    %ebx,%eax
cmp    %rax,%rsi
mov    %r15,%rdi
cmove  %r12,%rdi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     1148 <main+0x28>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rsi
cmp    $0x2,%rsi
jl     118c <main+0x6c>
mov    %rsi,%r8
shr    %r8
cmp    $0x1,%r8
jne    11e0 <main+0xc0>
xor    %ebx,%ebx
mov    $0x1,%ecx
test   $0x2,%sil
je     118c <main+0x6c>
jmp    127e <main+0x15e>
nopl   0x0(%rax)
and    $0xfffffffffffffffe,%r8
xor    %ebx,%ebx
mov    $0x1,%eax
jmp    11fb <main+0xdb>
nopl   (%rax)
add    %eax,%ebx
lea    0x1(%rbp),%rax
cmp    %r8,%rbp
je     1270 <main+0x150>
mov    %rax,%rcx
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1220 <main+0x100>
mov    %rsi,%rax
cqto
idiv   %rcx
jmp    1226 <main+0x106>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
mov    %ecx,%edi
test   %rdx,%rdx
je     122f <main+0x10f>
xor    %edi,%edi
lea    0x1(%rcx),%rbp
mov    %rsi,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     1250 <main+0x130>
mov    %rsi,%rax
cqto
idiv   %rbp
jmp    1256 <main+0x136>
nopl   0x0(%rax)
mov    %esi,%eax
xor    %edx,%edx
div    %ebp
add    %edi,%ebx
mov    %ebp,%eax
test   %rdx,%rdx
je     11f0 <main+0xd0>
xor    %eax,%eax
jmp    11f0 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x2,%rcx
test   $0x2,%sil
je     118c <main+0x6c>
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1175 <main+0x55>
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
jmp    117d <main+0x5d>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [30 x i8] c"YES, %d is a perfect number!\0A\00"
@.str.3 = [33 x i8] c"NO, %d is not a perfect number!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%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), i32* %2)
br label %7
7: ; preds = %44, %0
%8 = load i32, i32* %2
%9 = add nsw i32 %8, -1
store i32 %9, i32* %2
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %45
11: ; preds = %7
store i32 0, i32* %4
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %5)
store i32 1, i32* %3
br label %13
13: ; preds = %30, %11
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = load i64, i64* %5
%17 = sdiv i64 %16, 2
%18 = icmp sle i64 %15, %17
br i1 %18, label %19, label %33
19: ; preds = %13
%20 = load i64, i64* %5
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = srem i64 %20, %22
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = add nsw i32 %26, %27
store i32 %28, i32* %4
br label %29
29: ; preds = %25, %19
br label %30
30: ; preds = %29
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %13
33: ; preds = %13
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = load i64, i64* %5
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i64, i64* %5
%40 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %39)
br label %44
41: ; preds = %33
%42 = load i64, i64* %5
%43 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 %42)
br label %44
44: ; preds = %41, %38
br label %7
45: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [30 x i8] c"YES, %d is a perfect number!\0A\00"
@.str.3 = [33 x i8] c"NO, %d is not a perfect number!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i32* %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), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %57, label %9
9: ; preds = %0, %48
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%11 = load i64, i64* %2
%12 = icmp slt i64 %11, 2
br i1 %12, label %48, label %13
13: ; preds = %9
%14 = lshr i64 %11, 1
%15 = icmp eq i64 %14, 1
br i1 %15, label %36, label %16
16: ; preds = %13
%17 = and i64 %14, 9223372036854775806
br label %18
18: ; preds = %18, %16
%19 = phi i64 [ 1, %16 ], [ %33, %18 ]
%20 = phi i32 [ 0, %16 ], [ %32, %18 ]
%21 = phi i64 [ 0, %16 ], [ %34, %18 ]
%22 = srem i64 %11, %19
%23 = icmp eq i64 %22, 0
%24 = trunc i64 %19 to i32
%25 = select i1 %23, i32 %24, i32 0
%26 = add nuw nsw i32 %25, %20
%27 = add nuw nsw i64 %19, 1
%28 = srem i64 %11, %27
%29 = icmp eq i64 %28, 0
%30 = trunc i64 %27 to i32
%31 = select i1 %29, i32 %30, i32 0
%32 = add nuw nsw i32 %31, %26
%33 = add nuw nsw i64 %19, 2
%34 = add i64 %21, 2
%35 = icmp eq i64 %34, %17
br i1 %35, label %36, label %18
36: ; preds = %18, %13
%37 = phi i32 [ undef, %13 ], [ %32, %18 ]
%38 = phi i64 [ 1, %13 ], [ %33, %18 ]
%39 = phi i32 [ 0, %13 ], [ %32, %18 ]
%40 = and i64 %11, 2
%41 = icmp eq i64 %40, 0
br i1 %41, label %48, label %42
42: ; preds = %36
%43 = srem i64 %11, %38
%44 = icmp eq i64 %43, 0
%45 = trunc i64 %38 to i32
%46 = select i1 %44, i32 %45, i32 0
%47 = add nuw nsw i32 %46, %39
br label %48
48: ; preds = %42, %36, %9
%49 = phi i32 [ 0, %9 ], [ %37, %36 ], [ %47, %42 ]
%50 = zext i32 %49 to i64
%51 = icmp eq i64 %11, %50
%52 = select i1 %51, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0)
%53 = call i32 @printf(i8* %52, i64 %11)
%54 = load i32, i32* %1
%55 = add nsw i32 %54, -1
store i32 %55, i32* %1
%56 = icmp eq i32 %54, 0
br i1 %56, label %57, label %9
57: ; preds = %48, %0
ret i32 0
}