#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 pow(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n, r, a = 0, t, c = 0, z;
  printf("Enter a number: ");
  scanf("%d", &n);
  t = n;
  z = n;
  while (z > 0) {
    z = z / 10;
    c++;
  }
  while (n > 0) {
    r = n % 10;
    a = a + pow(r, c);
    n = n / 10;
  }
  if (a == t)
    printf("\nThe number is armstrong\n");
  else
    printf("\nThe number is not armstrong\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    119b <main+0x6b>
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1175 <main+0x45>
jmp    11a0 <main+0x70>
cmpl   $0x0,-0x8(%rbp)
jle    11e6 <main+0xb6>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    11a0 <main+0x70>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1203 <main+0xd3>
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
jmp    120f <main+0xdf>
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%r14d
test   %r14d,%r14d
jle    11ef <main+0xaf>
xor    %ebx,%ebx
mov    $0xcccccccd,%eax
mov    %r14d,%ecx
nopl   0x0(%rax)
mov    %ecx,%edx
imul   %rax,%rdx
shr    $0x23,%rdx
add    $0x1,%ebx
cmp    $0x9,%ecx
mov    %edx,%ecx
ja     1180 <main+0x40>
xor    %ebp,%ebp
test   %r14d,%r14d
jle    11f1 <main+0xb1>
mov    $0xcccccccd,%r15d
mov    %r14d,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %edi,%eax
imul   %r15,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
add    %eax,%ebp
movslq 0x4(%rsp),%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rdi
add    %ecx,%edi
mov    %edi,0x4(%rsp)
cmp    $0x9,%rax
jg     11b0 <main+0x70>
jmp    11f1 <main+0xb1>
xor    %ebp,%ebp
cmp    %r14d,%ebp
lea    0xe36(%rip),%rax
lea    0xe12(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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