#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num, i = 1, sum = 0;
  printf("Enter a number: ");
  scanf("%d", &num);
  while (i < num) {
    if (num % i == 0) {
      sum = sum + i;
    }
    i++;
  }
  if (sum == num)
    printf("%d is a Perfect Number", i);
  else
    printf("%d is Non Perfect Number", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    118e <main+0x6e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1180 <main+0x60>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <main+0x3b>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11b0 <main+0x90>
mov    -0xc(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <main+0xa1>
mov    -0xc(%rbp),%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%ecx
mov    $0x1,%esi
cmp    $0x2,%ecx
jl     117c <main+0x5c>
lea    -0x1(%rcx),%r8d
cmp    $0x2,%ecx
jne    119f <main+0x7f>
mov    $0x1,%edi
xor    %ebx,%ebx
mov    %ecx,%esi
test   $0x1,%r8b
je     117c <main+0x5c>
mov    %ecx,%eax
cltd
idiv   %edi
xor    %eax,%eax
test   %edx,%edx
cmove  %edi,%eax
add    %eax,%ebx
mov    %ecx,%esi
cmp    %ecx,%ebx
lea    0xe8f(%rip),%rax
lea    0xe9f(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
mov    $0x1,%edi
xor    %ebx,%ebx
jmp    11ba <main+0x9a>
nop
add    %eax,%ebx
add    $0x2,%edi
cmp    %r9d,%esi
je     1164 <main+0x44>
mov    %ecx,%eax
cltd
idiv   %edi
mov    %edi,%eax
test   %edx,%edx
je     11c7 <main+0xa7>
xor    %eax,%eax
add    %eax,%ebx
lea    0x1(%rdi),%esi
mov    %ecx,%eax
cltd
idiv   %esi
mov    %esi,%eax
test   %edx,%edx
je     11b0 <main+0x90>
xor    %eax,%eax
jmp    11b0 <main+0x90>

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

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"%d is a Perfect Number\00"
@.str.3 = [25 x i8] c"%d is Non Perfect Number\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 1
br i1 %6, label %7, label %39
7: ; preds = %0
%8 = add i32 %5, -1
%9 = and i32 %8, 1
%10 = icmp eq i32 %5, 2
br i1 %10, label %29, label %11
11: ; preds = %7
%12 = and i32 %8, -2
br label %13
13: ; preds = %13, %11
%14 = phi i32 [ 0, %11 ], [ %25, %13 ]
%15 = phi i32 [ 1, %11 ], [ %26, %13 ]
%16 = phi i32 [ 0, %11 ], [ %27, %13 ]
%17 = srem i32 %5, %15
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 %15, i32 0
%20 = add nuw nsw i32 %19, %14
%21 = add nuw nsw i32 %15, 1
%22 = srem i32 %5, %21
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i32 %21, i32 0
%25 = add nuw nsw i32 %24, %20
%26 = add nuw nsw i32 %15, 2
%27 = add i32 %16, 2
%28 = icmp eq i32 %27, %12
br i1 %28, label %29, label %13
29: ; preds = %13, %7
%30 = phi i32 [ undef, %7 ], [ %25, %13 ]
%31 = phi i32 [ 0, %7 ], [ %25, %13 ]
%32 = phi i32 [ 1, %7 ], [ %26, %13 ]
%33 = icmp eq i32 %9, 0
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = srem i32 %5, %32
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i32 %32, i32 0
%38 = add nuw nsw i32 %37, %31
br label %39
39: ; preds = %34, %29, %0
%40 = phi i32 [ 1, %0 ], [ %5, %29 ], [ %5, %34 ]
%41 = phi i32 [ 0, %0 ], [ %30, %29 ], [ %38, %34 ]
%42 = icmp eq i32 %41, %5
%43 = select i1 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %43, i32 %40)
ret i32 0
}