#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 /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ solve(char *, int /*<<< orphan*/, scalar_t__);
scalar_t__ strlen(char *);
int main() {
  long long int i, j, c, len, temp, t, res;
  long long int num;
  char str[30];
  while (1) {
    scanf("%s", str);
    if (str[0] == '0')
      break;
    else {
      printf("%lld", solve(str, 0, strlen(str) - 1));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1060 <scanf@plt>
movsbl -0x70(%rbp),%eax
cmp    $0x30,%eax
jne    1174 <main+0x34>
jmp    11aa <main+0x6a>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    %rax,%rdx
sub    $0x1,%rdx
xor    %esi,%esi
call   1030 <solve@plt>
mov    %eax,%esi
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xeb0(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
cmpb   $0x30,(%rsp)
je     11a1 <main+0x61>
mov    %rsp,%rbx
lea    0xe9b(%rip),%r14
lea    0xe91(%rip),%r15
nop
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <solve@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmpb   $0x30,(%rsp)
jne    1170 <main+0x30>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%lld\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 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
br i1 %5, label %14, label %6
6: ; preds = %0, %6
%7 = call i64 @strlen(i8* %2)
%8 = add nsw i64 %7, -1
%9 = call i32 @solve(i8* %2, i32 0, i64 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%12 = load i8, i8* %2
%13 = icmp eq i8 %12, 48
br i1 %13, label %14, label %6
14: ; preds = %6, %0
ret i32 0
}