#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void perfect(int number) {
  int sum = 0;
  int i;
  if (number < 0) {
    exit(0);
  }
  if (number == 0) {
    printf("Zero is not a perfect number\n");
  } else {
    for (i = 1; i < number; i++)
      if (number % i == 0) {
        sum = sum + i;
      }
    if (sum == number)
      printf("%d is a perfect number\n", number);
    else
      printf("%d is not a perfect number\n", number);
  }
}


x86 assembly (clang, -O0):
<perfect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1143 <perfect+0x23>
xor    %edi,%edi
call   1040 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1160 <perfect+0x40>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d7 <perfect+0xb7>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119f <perfect+0x7f>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    118c <perfect+0x6c>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1191 <perfect+0x71>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1167 <perfect+0x47>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11c1 <perfect+0xa1>
mov    -0x4(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d2 <perfect+0xb2>
mov    -0x4(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d7 <perfect+0xb7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perfect>:
test   %edi,%edi
js     11dd <perfect+0xad>
je     1178 <perfect+0x48>
mov    %edi,%r10d
xor    %ecx,%ecx
cmp    $0x1,%edi
je     116a <perfect+0x3a>
lea    -0x1(%r10),%r8d
cmp    $0x2,%r10d
jne    1195 <perfect+0x65>
xor    %ecx,%ecx
mov    $0x1,%edi
test   $0x1,%r8b
je     116a <perfect+0x3a>
mov    %r10d,%eax
cltd
idiv   %edi
xor    %eax,%eax
test   %edx,%edx
cmove  %edi,%eax
add    %eax,%ecx
cmp    %r10d,%ecx
jne    1184 <perfect+0x54>
lea    0xe8a(%rip),%rdi
jmp    118b <perfect+0x5b>
lea    0xeb5(%rip),%rdi
jmp    1030 <puts@plt>
lea    0xe8d(%rip),%rdi
mov    %r10d,%esi
xor    %eax,%eax
jmp    1040 <printf@plt>
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
xor    %ecx,%ecx
mov    $0x1,%edi
jmp    11ba <perfect+0x8a>
cs nopw 0x0(%rax,%rax,1)
nop
add    %eax,%ecx
add    $0x2,%edi
cmp    %r9d,%esi
je     1155 <perfect+0x25>
mov    %r10d,%eax
cltd
idiv   %edi
mov    %edi,%eax
test   %edx,%edx
je     11c8 <perfect+0x98>
xor    %eax,%eax
add    %eax,%ecx
lea    0x1(%rdi),%esi
mov    %r10d,%eax
cltd
idiv   %esi
mov    %esi,%eax
test   %edx,%edx
je     11b0 <perfect+0x80>
xor    %eax,%eax
jmp    11b0 <perfect+0x80>
push   %rax
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Zero is not a perfect number\0A\00"
@.str.1 = [24 x i8] c"%d is a perfect number\0A\00"
@.str.2 = [28 x i8] c"%d is not a perfect number\0A\00"
define void @perfect(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %1
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %43
14: ; preds = %9
store i32 1, i32* %4
br label %15
15: ; preds = %29, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %2
%21 = load i32, i32* %4
%22 = srem i32 %20, %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = add nsw i32 %25, %26
store i32 %27, i32* %3
br label %28
28: ; preds = %24, %19
br label %29
29: ; preds = %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %15
32: ; preds = %15
%33 = load i32, i32* %3
%34 = load i32, i32* %2
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %42
39: ; preds = %32
%40 = load i32, i32* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42, %12
ret void
}

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