#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 */
scalar_t__ factorial(int);
int processNumber(int num) {
  int n = num, factsum = 0, rem = 0;
  if (num == 0)
    return 0;
  while (n > 0) {
    rem = n % 10;
    factsum += factorial(rem);
    n = n / 10;
  }
  if (factsum == num)
    return 0;
  else
    return -1;
}


x86 assembly (clang, -O0):
<processNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1145 <processNumber+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <processNumber+0x99>
jmp    114a <processNumber+0x3a>
cmpl   $0x0,-0xc(%rbp)
jle    118a <processNumber+0x7a>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <factorial@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    114a <processNumber+0x3a>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11a2 <processNumber+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <processNumber+0x99>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processNumber>:
test   %edi,%edi
je     1156 <processNumber+0x46>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
jle    1159 <processNumber+0x49>
xor    %r12d,%r12d
mov    $0xcccccccd,%r15d
mov    %r14d,%ebx
nopl   (%rax)
mov    %ebx,%ebp
imul   %r15,%rbp
shr    $0x23,%rbp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%edi
sub    %eax,%edi
call   1030 <factorial@plt>
add    %eax,%r12d
cmp    $0x9,%ebx
mov    %ebp,%ebx
ja     1130 <processNumber+0x20>
jmp    115c <processNumber+0x4c>
xor    %eax,%eax
ret
xor    %r12d,%r12d
xor    %eax,%eax
cmp    %r14d,%r12d
setne  %al
neg    %eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @processNumber(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
store i32 %7, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %32
11: ; preds = %1
br label %12
12: ; preds = %15, %11
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i32, i32* %4
%17 = srem i32 %16, 10
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i64 @factorial(i32 %18)
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = sdiv i32 %24, 10
store i32 %25, i32* %4
br label %12
26: ; preds = %12
%27 = load i32, i32* %5
%28 = load i32, i32* %3
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %2
br label %32
31: ; preds = %26
store i32 -1, i32* %2
br label %32
32: ; preds = %31, %30, %10
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @processNumber(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %14
5: ; preds = %3, %5
%6 = phi i32 [ %11, %5 ], [ 0, %3 ]
%7 = phi i32 [ %12, %5 ], [ %0, %3 ]
%8 = urem i32 %7, 10
%9 = tail call i64 @factorial(i32 %8)
%10 = trunc i64 %9 to i32
%11 = add i32 %6, %10
%12 = udiv i32 %7, 10
%13 = icmp ult i32 %7, 10
br i1 %13, label %14, label %5
14: ; preds = %5, %3
%15 = phi i32 [ 0, %3 ], [ %11, %5 ]
%16 = icmp ne i32 %15, %0
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %14, %1
%19 = phi i32 [ 0, %1 ], [ %17, %14 ]
ret i32 %19
}