#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 /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void main(void) {
  int N, n, sum = 0, digits = 0;
  int q, r;
  printf("Enter number to check: ");
  scanf("%d", &n);
  N = n;
  while (n != 0) {
    n /= 10;
    digits++;
  }
  n = N;
  while (n != 0) {
    r = n % 10;
    n = n / 10;
    sum += pow(r, digits);
  }
  if (sum == N)
    printf("Armstrong number\n");
  else
    printf("Not Armstrong number\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118e <main+0x5e>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1168 <main+0x38>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d7 <main+0xa7>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <pow@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    1194 <main+0x64>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11f4 <main+0xc4>
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
jmp    1200 <main+0xd0>
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%r14d
test   %r14d,%r14d
je     11e6 <main+0xa6>
xor    %ebx,%ebx
mov    %r14d,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x1,%ebx
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1180 <main+0x40>
xor    %ebp,%ebp
test   %r14d,%r14d
je     11e8 <main+0xa8>
mov    %r14d,%eax
nopl   0x0(%rax)
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%edi
mov    %eax,0xc(%rsp)
mov    %ebx,%esi
call   1060 <pow@plt>
add    %eax,%ebp
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    11b0 <main+0x70>
jmp    11e8 <main+0xa8>
xor    %ebp,%ebp
cmp    %r14d,%ebp
lea    0xe2d(%rip),%rax
lea    0xe22(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter number to check: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"Armstrong number\0A\00"
@.str.3 = [22 x i8] c"Not Armstrong number\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
store i32 %9, i32* %1
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 10
store i32 %15, i32* %2
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %10
18: ; preds = %10
%19 = load i32, i32* %1
store i32 %19, i32* %2
br label %20
20: ; preds = %23, %18
%21 = load i32, i32* %2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = load i32, i32* %2
%25 = srem i32 %24, 10
store i32 %25, i32* %6
%26 = load i32, i32* %2
%27 = sdiv i32 %26, 10
store i32 %27, i32* %2
%28 = load i32, i32* %6
%29 = load i32, i32* %4
%30 = call i64 @pow(i32 %28, i32 %29)
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = add nsw i64 %32, %30
%34 = trunc i64 %33 to i32
store i32 %34, i32* %3
br label %20
35: ; preds = %20
%36 = load i32, i32* %3
%37 = load i32, i32* %1
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %43
41: ; preds = %35
%42 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter number to check: \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [21 x i8] c"Not Armstrong number\00"
@str.4 = [17 x i8] c"Armstrong number\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 eq i32 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %11, %7 ], [ 0, %0 ]
%9 = phi i32 [ %10, %7 ], [ %5, %0 ]
%10 = sdiv i32 %9, 10
%11 = add nuw nsw i32 %8, 1
%12 = add i32 %9, 9
%13 = icmp ult i32 %12, 19
br i1 %13, label %14, label %7
14: ; preds = %7
br i1 %6, label %25, label %15
15: ; preds = %14, %15
%16 = phi i32 [ %22, %15 ], [ 0, %14 ]
%17 = phi i32 [ %23, %15 ], [ %5, %14 ]
%18 = srem i32 %17, 10
%19 = sdiv i32 %17, 10
store i32 %19, i32* %1
%20 = call i64 @pow(i32 %18, i32 %11)
%21 = trunc i64 %20 to i32
%22 = add i32 %16, %21
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %15, %0, %14
%26 = phi i32 [ 0, %14 ], [ 0, %0 ], [ %22, %15 ]
%27 = icmp eq i32 %26, %5
%28 = select i1 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0)
%29 = call i32 @puts(i8* dereferenceable(1) %28)
ret void
}