#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 power(int, int);
int narcissisticNumbers(int userInput, int digit) {
  int temp = userInput;
  int rem = 0;
  int sum = 0;
  while (temp != 0) {
    rem = temp % 10;
    sum = sum + power(rem, digit);
    temp = temp / 10;
  }
  if (sum == userInput)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<narcissisticNumbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1178 <narcissisticNumbers+0x68>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <power@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    1132 <narcissisticNumbers+0x22>
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1190 <narcissisticNumbers+0x80>
movl   $0x1,-0x4(%rbp)
jmp    1197 <narcissisticNumbers+0x87>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<narcissisticNumbers>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
test   %edi,%edi
je     1167 <narcissisticNumbers+0x57>
mov    %esi,%r15d
xor    %r12d,%r12d
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rbx
imul   $0x66666667,%rbx,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x22,%rbp
add    %eax,%ebp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%edi
sub    %eax,%edi
mov    %r15d,%esi
call   1030 <power@plt>
add    %eax,%r12d
add    $0x9,%ebx
cmp    $0x12,%ebx
ja     1130 <narcissisticNumbers+0x20>
jmp    116a <narcissisticNumbers+0x5a>
xor    %r12d,%r12d
xor    %eax,%eax
cmp    %r14d,%r12d
sete   %al
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @narcissisticNumbers(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %13, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %9, %4 ], [ 0, %2 ]
%6 = phi i32 [ %10, %4 ], [ %0, %2 ]
%7 = srem i32 %6, 10
%8 = tail call i32 @power(i32 %7, i32 %1)
%9 = add nsw i32 %8, %5
%10 = sdiv i32 %6, 10
%11 = add i32 %6, 9
%12 = icmp ult i32 %11, 19
br i1 %12, label %13, label %4
13: ; preds = %4, %2
%14 = phi i32 [ 0, %2 ], [ %9, %4 ]
%15 = icmp eq i32 %14, %0
%16 = zext i1 %15 to i32
ret i32 %16
}