#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 /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num;
  int root = 0;
  int sum = 0;
  scanf("%d", &num);
  sum = num;
  while (sum > 9) {
    num = sum;
    sum = 0;
    while (num > 0) {
      sum = sum + num % 10;
      num = num / 10;
    }
  }
  printf("%d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x9,-0x10(%rbp)
jle    11a5 <main+0x85>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11a0 <main+0x80>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    116a <main+0x4a>
jmp    1153 <main+0x33>
mov    -0x10(%rbp),%esi
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%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),%ecx
cmp    $0xa,%ecx
jl     1183 <main+0x63>
xor    %edx,%edx
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,%edi
imul   %r8,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %ecx,%eax
sub    %esi,%eax
mov    %edx,%esi
add    %eax,%esi
mov    %esi,%edx
cmp    $0xa,%ecx
mov    %edi,%ecx
jae    1150 <main+0x30>
mov    $0x0,%edx
mov    %esi,%ecx
cmp    $0xa,%esi
jae    1150 <main+0x30>
mov    %edi,0x4(%rsp)
jmp    1185 <main+0x65>
mov    %ecx,%esi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\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, 9
br i1 %5, label %8, label %19
6: ; preds = %8
%7 = icmp ugt i32 %12, 9
br i1 %7, label %15, label %18
8: ; preds = %0, %15
%9 = phi i32 [ %16, %15 ], [ 0, %0 ]
%10 = phi i32 [ %17, %15 ], [ %4, %0 ]
%11 = urem i32 %10, 10
%12 = add nuw nsw i32 %9, %11
%13 = udiv i32 %10, 10
%14 = icmp ult i32 %10, 10
br i1 %14, label %6, label %15
15: ; preds = %8, %6
%16 = phi i32 [ %12, %8 ], [ 0, %6 ]
%17 = phi i32 [ %13, %8 ], [ %12, %6 ]
br label %8
18: ; preds = %6
store i32 %13, i32* %1
br label %19
19: ; preds = %18, %0
%20 = phi i32 [ %12, %18 ], [ %4, %0 ]
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
ret i32 0
}