#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() {
  int i;
  while (1) {
    char str[1000];
    int s = 0;
    scanf("%s\n", str);
    if (str[0] == '0')
      break;
    for (i = 0; str[i] != '\0'; i++) {
      s += str[i] - '0';
    }
    printf("%d\n", s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3f4(%rbp)
lea    -0x3f0(%rbp),%rsi
lea    0xeb6(%rip),%rdi
call   1040 <scanf@plt>
movsbl -0x3f0(%rbp),%eax
cmp    $0x30,%eax
jne    1164 <main+0x44>
jmp    11c0 <main+0xa0>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11a9 <main+0x89>
movslq -0x8(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
add    -0x3f4(%rbp),%eax
mov    %eax,-0x3f4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116b <main+0x4b>
mov    -0x3f4(%rbp),%esi
lea    0xe4e(%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    $0x3e8,%rsp
lea    0xecb(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%al
cmp    $0x30,%al
jne    1155 <main+0x35>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x1(%rsp),%r12
lea    0xea3(%rip),%r14
lea    0xe98(%rip),%r15
mov    %rsp,%rbx
jmp    118a <main+0x6a>
nopl   (%rax)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%al
cmp    $0x30,%al
je     1144 <main+0x24>
xor    %esi,%esi
test   %al,%al
je     1170 <main+0x50>
mov    %r12,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%eax
add    %eax,%esi
add    $0xffffffd0,%esi
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    11a0 <main+0x80>
jmp    1170 <main+0x50>

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

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