#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;
  int sum = 0;
  int i;
  printf("Enter an integer number: ");
  scanf("%d", &num);
  if (num < 0) {
    printf("Error: the number must be positive");
    return 0;
  }
  for (i = 1; i < num; i++)
    if (num % i == 0) {
      sum = sum + i;
    }
  if (sum == num)
    printf("%d is a perfect number", num);
  else
    printf("%d is not a perfect number", num);
  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
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1178 <main+0x58>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <main+0xd1>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b7 <main+0x97>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11a4 <main+0x84>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11a9 <main+0x89>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117f <main+0x5f>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11d9 <main+0xb9>
mov    -0x8(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ea <main+0xca>
mov    -0x8(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xede(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
js     1184 <main+0x64>
cmp    $0x2,%esi
jb     1177 <main+0x57>
lea    -0x1(%rsi),%r8d
cmp    $0x2,%esi
jne    11aa <main+0x8a>
xor    %ebx,%ebx
mov    $0x1,%ecx
test   $0x1,%r8b
je     1177 <main+0x57>
mov    %esi,%eax
cltd
idiv   %ecx
xor    %eax,%eax
test   %edx,%edx
cmove  %ecx,%eax
add    %eax,%ebx
cmp    %esi,%ebx
jne    1194 <main+0x74>
lea    0xebe(%rip),%rdi
jmp    119b <main+0x7b>
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a2 <main+0x82>
lea    0xebc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
xor    %ebx,%ebx
mov    $0x1,%ecx
jmp    11ca <main+0xaa>
nopw   0x0(%rax,%rax,1)
add    %eax,%ebx
add    $0x2,%ecx
cmp    %r9d,%edi
je     1163 <main+0x43>
mov    %esi,%eax
cltd
idiv   %ecx
mov    %ecx,%eax
test   %edx,%edx
je     11d7 <main+0xb7>
xor    %eax,%eax
add    %eax,%ebx
lea    0x1(%rcx),%edi
mov    %esi,%eax
cltd
idiv   %edi
mov    %edi,%eax
test   %edx,%edx
je     11c0 <main+0xa0>
xor    %eax,%eax
jmp    11c0 <main+0xa0>

LLVM IR (-O0):
@.str = [26 x i8] c"Enter an integer number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Error: the number must be positive\00"
@.str.3 = [23 x i8] c"%d is a perfect number\00"
@.str.4 = [27 x i8] c"%d is not a 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 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 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)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %40
11: ; preds = %0
store i32 1, i32* %4
br label %12
12: ; preds = %26, %11
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = srem i32 %17, %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = add nsw i32 %22, %23
store i32 %24, i32* %3
br label %25
25: ; preds = %21, %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %12
29: ; preds = %12
%30 = load i32, i32* %3
%31 = load i32, i32* %2
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %39
36: ; preds = %29
%37 = load i32, i32* %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %33
store i32 0, i32* %1
br label %40
40: ; preds = %39, %9
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter an integer number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Error: the number must be positive\00"
@.str.3 = [23 x i8] c"%d is a perfect number\00"
@.str.4 = [27 x i8] c"%d is not a 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 ([26 x i8], [26 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 slt i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = icmp ugt i32 %5, 1
br i1 %8, label %9, label %43
9: ; preds = %7
%10 = add i32 %5, -1
%11 = and i32 %10, 1
%12 = icmp eq i32 %5, 2
br i1 %12, label %33, label %13
13: ; preds = %9
%14 = and i32 %10, -2
br label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %50
17: ; preds = %17, %13
%18 = phi i32 [ 1, %13 ], [ %30, %17 ]
%19 = phi i32 [ 0, %13 ], [ %29, %17 ]
%20 = phi i32 [ 0, %13 ], [ %31, %17 ]
%21 = srem i32 %5, %18
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i32 %18, i32 0
%24 = add nuw nsw i32 %23, %19
%25 = add nuw nsw i32 %18, 1
%26 = srem i32 %5, %25
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i32 %25, i32 0
%29 = add nuw nsw i32 %28, %24
%30 = add nuw nsw i32 %18, 2
%31 = add i32 %20, 2
%32 = icmp eq i32 %31, %14
br i1 %32, label %33, label %17
33: ; preds = %17, %9
%34 = phi i32 [ undef, %9 ], [ %29, %17 ]
%35 = phi i32 [ 1, %9 ], [ %30, %17 ]
%36 = phi i32 [ 0, %9 ], [ %29, %17 ]
%37 = icmp eq i32 %11, 0
br i1 %37, label %43, label %38
38: ; preds = %33
%39 = srem i32 %5, %35
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, i32 %35, i32 0
%42 = add nuw nsw i32 %41, %36
br label %43
43: ; preds = %38, %33, %7
%44 = phi i32 [ 0, %7 ], [ %34, %33 ], [ %42, %38 ]
%45 = icmp eq i32 %44, %5
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %50
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %5)
br label %50
50: ; preds = %46, %48, %15
ret i32 0
}