#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__ pow(int, int);
int fifth_power(int canidate) {
  int tmp = canidate;
  int total = 0;
  while (tmp) {
    int current_digit = tmp % 10;
    total += pow(current_digit, 5);
    if (total > canidate)
      return 0;
    tmp /= 10;
  }
  canidate = canidate == total ? canidate : 0;
  return canidate;
}


x86 assembly (clang, -O0):
<fifth_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1185 <fifth_power+0x75>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1030 <pow@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1172 <fifth_power+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <fifth_power+0xa2>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1128 <fifth_power+0x18>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    119c <fifth_power+0x8c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11a6 <fifth_power+0x96>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    11a6 <fifth_power+0x96>
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fifth_power>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
test   %edi,%edi
je     115a <fifth_power+0x4a>
movslq %edi,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    $0x5,%esi
call   1030 <pow@plt>
add    %eax,%ebp
mov    %ebx,%edi
cmp    %r14d,%ebp
jle    1120 <fifth_power+0x10>
xor    %eax,%eax
jmp    1163 <fifth_power+0x53>
xor    %eax,%eax
cmp    %r14d,%ebp
cmove  %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fifth_power(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
br label %8
8: ; preds = %24, %1
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i32, i32* %4
%13 = srem i32 %12, 10
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = call i64 @pow(i32 %14, i32 5)
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = add nsw i64 %17, %15
%19 = trunc i64 %18 to i32
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %11
store i32 0, i32* %2
br label %37
24: ; preds = %11
%25 = load i32, i32* %4
%26 = sdiv i32 %25, 10
store i32 %26, i32* %4
br label %8
27: ; preds = %8
%28 = load i32, i32* %3
%29 = load i32, i32* %5
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i32, i32* %3
br label %34
33: ; preds = %27
br label %34
34: ; preds = %33, %31
%35 = phi i32 [ %32, %31 ], [ 0, %33 ]
store i32 %35, i32* %3
%36 = load i32, i32* %3
store i32 %36, i32* %2
br label %37
37: ; preds = %34, %23
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @fifth_power(i32 %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i32 [ %0, %1 ], [ %12, %6 ]
%4 = phi i32 [ 0, %1 ], [ %10, %6 ]
%5 = icmp eq i32 %3, 0
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = srem i32 %3, 10
%8 = tail call i64 @pow(i32 %7, i32 5)
%9 = trunc i64 %8 to i32
%10 = add i32 %4, %9
%11 = icmp sgt i32 %10, %0
%12 = sdiv i32 %3, 10
br i1 %11, label %16, label %2
13: ; preds = %2
%14 = icmp eq i32 %4, %0
%15 = select i1 %14, i32 %0, i32 0
br label %16
16: ; preds = %6, %13
%17 = phi i32 [ %15, %13 ], [ 0, %6 ]
ret i32 %17
}