#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 *);
void main() {
  int num = -1;
  int fac = 1, total = 0;
  int isPer = 0;
  while ((num < 1) || (num >= 10000)) {
    printf("Please enter a positive integer between 0 and 10,000: ");
    scanf("%d", &num);
  }
  while (fac < num) {
    if ((num % fac) == 0) {
      total = total + fac;
    }
    fac += 1;
  }
  if (total == num)
    isPer = 1;
  if (isPer == 0) {
    printf("%d is not a perfect number", num);
  } else {
    printf("%d is a perfect number\n", num);
    printf("1");
    fac = 2;
    while (fac < num) {
      if ((num % fac) == 0) {
        printf("+%d", fac);
      }
      fac += 1;
    }
    printf(" = %d", num);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x11(%rbp)
jl     1160 <main+0x40>
cmpl   $0x2710,-0x4(%rbp)
setge  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1170 <main+0x50>
jmp    1193 <main+0x73>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1144 <main+0x24>
jmp    1198 <main+0x78>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11cb <main+0xab>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    11bd <main+0x9d>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1198 <main+0x78>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11de <main+0xbe>
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11fe <main+0xde>
mov    -0x4(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1270 <main+0x150>
mov    -0x4(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    125f <main+0x13f>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    1251 <main+0x131>
mov    -0x8(%rbp),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1224 <main+0x104>
mov    -0x4(%rbp),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xeb8(%rip),%r14
lea    0xf22(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
lea    -0x2710(%rsi),%eax
cmp    $0xffffd8f1,%eax
jb     1160 <main+0x30>
xor    %ecx,%ecx
cmp    $0x2,%esi
jb     11b5 <main+0x85>
lea    -0x1(%rsi),%r8d
cmp    $0x2,%esi
jne    1233 <main+0x103>
mov    $0x1,%edi
xor    %ecx,%ecx
test   $0x1,%r8b
je     11b5 <main+0x85>
mov    %esi,%eax
cltd
idiv   %edi
xor    %eax,%eax
test   %edx,%edx
cmove  %edi,%eax
add    %eax,%ecx
cmp    %esi,%ecx
jne    1212 <main+0xe2>
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x31,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%esi
cmp    $0x3,%esi
jl     121b <main+0xeb>
mov    $0x2,%ebx
lea    0xe84(%rip),%r14
jmp    11f7 <main+0xc7>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %esi,%ebx
jge    121b <main+0xeb>
mov    %esi,%eax
cltd
idiv   %ebx
test   %edx,%edx
jne    11f0 <main+0xc0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
jmp    11f0 <main+0xc0>
lea    0xe1e(%rip),%rdi
jmp    1222 <main+0xf2>
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
mov    $0x1,%edi
xor    %ecx,%ecx
jmp    125e <main+0x12e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %eax,%ecx
add    $0x2,%edi
cmp    %r9d,%ebx
je     11a1 <main+0x71>
mov    %esi,%eax
cltd
idiv   %edi
mov    %edi,%eax
test   %edx,%edx
je     126b <main+0x13b>
xor    %eax,%eax
add    %eax,%ecx
lea    0x1(%rdi),%ebx
mov    %esi,%eax
cltd
idiv   %ebx
mov    %ebx,%eax
test   %edx,%edx
je     1250 <main+0x120>
xor    %eax,%eax
jmp    1250 <main+0x120>

LLVM IR (-O0):
@.str = [55 x i8] c"Please enter a positive integer between 0 and 10,000: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"%d is not a perfect number\00"
@.str.3 = [24 x i8] c"%d is a perfect number\0A\00"
@.str.4 = [2 x i8] c"1\00"
@.str.5 = [4 x i8] c"+%d\00"
@.str.6 = [6 x i8] c" = %d\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 -1, i32* %1
store i32 1, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %13, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = load i32, i32* %1
%10 = icmp sge i32 %9, 10000
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ true, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %5
16: ; preds = %11
br label %17
17: ; preds = %30, %16
%18 = load i32, i32* %2
%19 = load i32, i32* %1
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = srem i32 %22, %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = add nsw i32 %27, %28
store i32 %29, i32* %3
br label %30
30: ; preds = %26, %21
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %17
33: ; preds = %17
%34 = load i32, i32* %3
%35 = load i32, i32* %1
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 1, i32* %4
br label %38
38: ; preds = %37, %33
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %1
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %66
44: ; preds = %38
%45 = load i32, i32* %1
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %2
br label %48
48: ; preds = %60, %44
%49 = load i32, i32* %2
%50 = load i32, i32* %1
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %63
52: ; preds = %48
%53 = load i32, i32* %1
%54 = load i32, i32* %2
%55 = srem i32 %53, %54
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = load i32, i32* %2
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %57, %52
%61 = load i32, i32* %2
%62 = add nsw i32 %61, 1
store i32 %62, i32* %2
br label %48
63: ; preds = %48
%64 = load i32, i32* %1
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %63, %41
ret void
}

LLVM IR (-O2):
@.str = [55 x i8] c"Please enter a positive integer between 0 and 10,000: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"%d is not a perfect number\00"
@.str.3 = [24 x i8] c"%d is a perfect number\0A\00"
@.str.5 = [4 x i8] c"+%d\00"
@.str.6 = [6 x i8] c" = %d\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
br label %11
3: ; preds = %11
%4 = icmp ugt i32 %14, 1
br i1 %4, label %5, label %43
5: ; preds = %3
%6 = add i32 %14, -1
%7 = and i32 %6, 1
%8 = icmp eq i32 %14, 2
br i1 %8, label %33, label %9
9: ; preds = %5
%10 = and i32 %6, -2
br label %17
11: ; preds = %0, %11
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = add i32 %14, -10000
%16 = icmp ult i32 %15, -9999
br i1 %16, label %11, label %3
17: ; preds = %17, %9
%18 = phi i32 [ 0, %9 ], [ %29, %17 ]
%19 = phi i32 [ 1, %9 ], [ %30, %17 ]
%20 = phi i32 [ 0, %9 ], [ %31, %17 ]
%21 = srem i32 %14, %19
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i32 %19, i32 0
%24 = add nuw nsw i32 %23, %18
%25 = add nuw nsw i32 %19, 1
%26 = srem i32 %14, %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 %19, 2
%31 = add i32 %20, 2
%32 = icmp eq i32 %31, %10
br i1 %32, label %33, label %17
33: ; preds = %17, %5
%34 = phi i32 [ undef, %5 ], [ %29, %17 ]
%35 = phi i32 [ 0, %5 ], [ %29, %17 ]
%36 = phi i32 [ 1, %5 ], [ %30, %17 ]
%37 = icmp eq i32 %7, 0
br i1 %37, label %43, label %38
38: ; preds = %33
%39 = srem i32 %14, %36
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, i32 %36, i32 0
%42 = add nuw nsw i32 %41, %35
br label %43
43: ; preds = %38, %33, %3
%44 = phi i32 [ 0, %3 ], [ %34, %33 ], [ %42, %38 ]
%45 = icmp eq i32 %44, %14
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %68
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%50 = call i32 @putchar(i32 49)
%51 = load i32, i32* %1
%52 = icmp sgt i32 %51, 2
br i1 %52, label %53, label %65
53: ; preds = %48, %61
%54 = phi i32 [ %62, %61 ], [ %51, %48 ]
%55 = phi i32 [ %63, %61 ], [ 2, %48 ]
%56 = srem i32 %54, %55
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %55)
%60 = load i32, i32* %1
br label %61
61: ; preds = %58, %53
%62 = phi i32 [ %60, %58 ], [ %54, %53 ]
%63 = add nuw nsw i32 %55, 1
%64 = icmp slt i32 %63, %62
br i1 %64, label %53, label %65
65: ; preds = %61, %48
%66 = phi i32 [ %51, %48 ], [ %62, %61 ]
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65, %46
ret void
}