#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__ EOF;
int /*<<< orphan*/ printf(char *, unsigned int);
scalar_t__ scanf(char *, unsigned int *);
int main(int argc, const char *argv[]) {
  unsigned int n, sum, odd;
  while (scanf("%d\n", &n) != EOF) {
    sum = 0;
    while (n != 0) {
      odd = n % 10;
      n = (n - odd) / 10;
      sum += odd;
    }
    printf("%d\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%rax
je     11aa <main+0x8a>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1196 <main+0x76>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    115d <main+0x3d>
mov    -0x18(%rbp),%esi
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x2ea8(%rip),%r15
cmp    (%r15),%rax
jne    1153 <main+0x33>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xea6(%rip),%r12
lea    0x4(%rsp),%r14
mov    $0xcccccccd,%ebx
jmp    1188 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
cmp    (%r15),%rax
je     1145 <main+0x25>
mov    0x4(%rsp),%eax
xor    %esi,%esi
test   %eax,%eax
je     1170 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ecx
mov    %eax,%eax
imul   %rbx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%edi
sub    %edx,%edi
add    %edi,%esi
cmp    $0x9,%ecx
ja     11a0 <main+0x80>
mov    %eax,0x4(%rsp)
jmp    1170 <main+0x50>

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

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