#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 iNum, iSum = 0, i;
  printf("\nEnter a number\n");
  scanf("%d", &iNum);
  i = 1;
  while (i < iNum) {
    if (iNum % i == 0)
      iSum += i;
    i++;
  }
  if (iSum == iNum)
    printf("\nGiven number is a Perfect Number\n");
  else
    printf("\nGiven number is not a Perfect Number\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    118c <main+0x6c>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    117e <main+0x5e>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1159 <main+0x39>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11a9 <main+0x89>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
jmp    11b5 <main+0x95>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
lea    0xecc(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%r10d
xor    %esi,%esi
cmp    $0x2,%r10d
jl     1171 <main+0x51>
lea    -0x1(%r10),%r8d
cmp    $0x2,%r10d
jne    118f <main+0x6f>
xor    %esi,%esi
mov    $0x1,%edi
test   $0x1,%r8b
je     1171 <main+0x51>
mov    %r10d,%eax
cltd
idiv   %edi
xor    %eax,%eax
test   %edx,%edx
cmove  %edi,%eax
add    %eax,%esi
cmp    %r10d,%esi
lea    0xebe(%rip),%rax
lea    0xe91(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
xor    %esi,%esi
mov    $0x1,%edi
jmp    11aa <main+0x8a>
nop
add    %eax,%esi
add    $0x2,%edi
cmp    %r9d,%ecx
je     115c <main+0x3c>
mov    %r10d,%eax
cltd
idiv   %edi
mov    %edi,%eax
test   %edx,%edx
je     11b8 <main+0x98>
xor    %eax,%eax
add    %eax,%esi
lea    0x1(%rdi),%ecx
mov    %r10d,%eax
cltd
idiv   %ecx
mov    %ecx,%eax
test   %edx,%edx
je     11a0 <main+0x80>
xor    %eax,%eax
jmp    11a0 <main+0x80>

LLVM IR (-O0):
@.str = [17 x i8] c"\0AEnter a number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"\0AGiven number is a Perfect Number\0A\00"
@.str.3 = [39 x i8] c"\0AGiven number is not a Perfect Number\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 @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)
store i32 1, i32* %4
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %4
%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* %4
%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 %18, %17
store i32 %19, i32* %3
br label %20
20: ; preds = %16, %11
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %7
23: ; preds = %7
%24 = load i32, i32* %3
%25 = load i32, i32* %2
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [16 x i8] c"\0AEnter a number\00"
@str.4 = [38 x i8] c"\0AGiven number is not a Perfect Number\00"
@str.5 = [34 x i8] c"\0AGiven number is a Perfect Number\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 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 [ 1, %11 ], [ %26, %13 ]
%15 = phi i32 [ 0, %11 ], [ %25, %13 ]
%16 = phi i32 [ 0, %11 ], [ %27, %13 ]
%17 = srem i32 %5, %14
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 %14, i32 0
%20 = add nuw nsw i32 %19, %15
%21 = add nuw nsw i32 %14, 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 %14, 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 [ 1, %7 ], [ %26, %13 ]
%32 = phi i32 [ 0, %7 ], [ %25, %13 ]
%33 = icmp eq i32 %9, 0
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = srem i32 %5, %31
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i32 %31, i32 0
%38 = add nuw nsw i32 %37, %32
br label %39
39: ; preds = %34, %29, %0
%40 = phi i32 [ 0, %0 ], [ %30, %29 ], [ %38, %34 ]
%41 = icmp eq i32 %40, %5
%42 = select i1 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @str.4, i64 0, i64 0)
%43 = call i32 @puts(i8* dereferenceable(1) %42)
ret i32 0
}