#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 *, int);
scalar_t__ scanf(char *, int *);
int sum_digits(int);
int main() {
  int n;
  while (scanf("%d\n", &n) != EOF && n != 0) {
    while ((n = sum_digits(n)) >= 10) {
      ;
    }
    printf("%d\n", n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e8d(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x9(%rbp)
je     1171 <main+0x41>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1181 <main+0x51>
jmp    11b3 <main+0x83>
jmp    1186 <main+0x56>
mov    -0x8(%rbp),%edi
call   1040 <sum_digits@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xa,%eax
jl     119f <main+0x6f>
jmp    1186 <main+0x56>
mov    -0x8(%rbp),%esi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x2e97(%rip),%r15
cmp    (%r15),%rax
je     11a2 <main+0x72>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11a2 <main+0x72>
lea    0xe9b(%rip),%rbx
lea    0xc(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1040 <sum_digits@plt>
mov    %eax,0xc(%rsp)
cmp    $0x9,%eax
jg     1170 <main+0x40>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
cmp    (%r15),%rax
je     11a2 <main+0x72>
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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