#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 *, char *);
int main(void) {
  int x, sum, i;
  char string[1001];
  while (1) {
    scanf("%s", string);
    if (string[0] == '0' && string[1] == '\0')
      break;
    sum = 0, i = 0;
    while (string[i] != '\0') {
      sum += string[i] - '0';
      i++;
    }
    printf("%d\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x400(%rbp),%rsi
lea    0xec0(%rip),%rdi
call   1040 <scanf@plt>
movsbl -0x400(%rbp),%eax
cmp    $0x30,%eax
jne    116a <main+0x4a>
movsbl -0x3ff(%rbp),%eax
cmp    $0x0,%eax
jne    116a <main+0x4a>
jmp    11c4 <main+0xa4>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11b0 <main+0x90>
movslq -0x10(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1178 <main+0x58>
mov    -0xc(%rbp),%esi
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
jmp    1132 <main+0x12>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f8,%rsp
lea    0xecb(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%al
cmp    $0x30,%al
jne    114b <main+0x2b>
cmpb   $0x0,0x1(%rsp)
je     11b4 <main+0x94>
lea    0x1(%rsp),%r12
lea    0xeac(%rip),%r14
lea    0xea2(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %esi,%esi
test   %al,%al
je     1193 <main+0x73>
mov    %r12,%rcx
nopl   0x0(%rax)
movsbl %al,%eax
add    %eax,%esi
add    $0xffffffd0,%esi
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    1180 <main+0x60>
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%al
cmp    $0x30,%al
jne    1170 <main+0x50>
cmpb   $0x0,0x1(%rsp)
jne    1170 <main+0x50>
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1001 x i8]
store i32 0, i32* %1
br label %6
6: ; preds = %0, %38
%7 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 48
br i1 %12, label %13, label %19
13: ; preds = %6
%14 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
br label %41
19: ; preds = %13, %6
store i32 0, i32* %3
store i32 0, i32* %4
br label %20
20: ; preds = %27, %19
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %20
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = sub nsw i32 %32, 48
%34 = load i32, i32* %3
%35 = add nsw i32 %34, %33
store i32 %35, i32* %3
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %20
38: ; preds = %20
%39 = load i32, i32* %3
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
br label %6
41: ; preds = %18
ret i32 0
}

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