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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x9,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jg     116f <main+0x3f>
cmpl   $0xfffffff7,-0x8(%rbp)
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    117f <main+0x4f>
jmp    11b1 <main+0x81>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x26>
mov    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edi
lea    -0xa(%rdi),%eax
xor    %ebx,%ebx
cmp    $0xffffffec,%eax
ja     11b0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %edi,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   1030 <abs@plt>
add    %eax,%ebx
movslq 0xc(%rsp),%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
lea    (%rax,%rcx,1),%edi
mov    %edi,0xc(%rsp)
movslq %ebx,%rbx
add    %ecx,%eax
add    $0xfffffff6,%eax
cmp    $0xffffffed,%eax
jb     1160 <main+0x30>
call   1030 <abs@plt>
add    %eax,%ebx
lea    0xe42(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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 = add i32 %4, -10
%6 = icmp ult i32 %5, -19
br i1 %6, label %7, label %19
7: ; preds = %0, %7
%8 = phi i32 [ %14, %7 ], [ %4, %0 ]
%9 = phi i64 [ %16, %7 ], [ 0, %0 ]
%10 = srem i32 %8, 10
%11 = call i64 @abs(i32 %10)
%12 = add nsw i64 %11, %9
%13 = load i32, i32* %1
%14 = sdiv i32 %13, 10
store i32 %14, i32* %1
%15 = shl i64 %12, 32
%16 = ashr exact i64 %15, 32
%17 = add nsw i32 %14, -10
%18 = icmp ult i32 %17, -19
br i1 %18, label %7, label %19
19: ; preds = %7, %0
%20 = phi i64 [ 0, %0 ], [ %16, %7 ]
%21 = phi i32 [ %4, %0 ], [ %14, %7 ]
%22 = call i64 @abs(i32 %21)
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i32 0
}