#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 printf(char *, int);
int scanf(char *, int *);
int main() {
  int n, s = 0 * scanf("%d", &n);
  for (; n > 0 || 0 * printf("%d\n", s); n /= 10)
    s += ((n % 10) * (n % 10));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
imul   $0x0,%eax,%eax
mov    %eax,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jg     116f <main+0x4f>
mov    -0xc(%rbp),%esi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
imul   $0x0,%eax,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    117f <main+0x5f>
jmp    11b7 <main+0x97>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%eax
imul   %edx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1145 <main+0x25>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
xor    %esi,%esi
test   %eax,%eax
jle    1174 <main+0x54>
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ecx
mov    %eax,%eax
imul   %r8,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %ecx,%edx
sub    %edi,%edx
imul   %edx,%edx
add    %edx,%esi
cmp    $0xa,%ecx
jae    1150 <main+0x30>
mov    %eax,0x4(%rsp)
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = mul nsw i32 0, %4
store i32 %5, i32* %3
br label %6
6: ; preds = %24, %0
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = mul nsw i32 0, %11
%13 = icmp ne i32 %12, 0
br label %14
14: ; preds = %9, %6
%15 = phi i1 [ true, %6 ], [ %13, %9 ]
br i1 %15, label %16, label %27
16: ; preds = %14
%17 = load i32, i32* %2
%18 = srem i32 %17, 10
%19 = load i32, i32* %2
%20 = srem i32 %19, 10
%21 = mul nsw i32 %18, %20
%22 = load i32, i32* %3
%23 = add nsw i32 %22, %21
store i32 %23, i32* %3
br label %24
24: ; preds = %16
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 10
store i32 %26, i32* %2
br label %6
27: ; preds = %14
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %10, label %7
6: ; preds = %10
store i32 %16, i32* %1
br label %7
7: ; preds = %6, %0
%8 = phi i32 [ %15, %6 ], [ 0, %0 ]
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
ret i32 0
10: ; preds = %0, %10
%11 = phi i32 [ %15, %10 ], [ 0, %0 ]
%12 = phi i32 [ %16, %10 ], [ %4, %0 ]
%13 = urem i32 %12, 10
%14 = mul nuw nsw i32 %13, %13
%15 = add nuw nsw i32 %14, %11
%16 = udiv i32 %12, 10
%17 = icmp ult i32 %12, 10
br i1 %17, label %6, label %10
}